Module-like system with two step initialization
Module-like system with two step initialization.
Units provides an ability to add number of component instances to a set and then call init function on each of them with guarantee that all other components are instantiated.
Can also be used on client side using browserify or similar tool.
var units = ;var;// all units are instantiated at this point// getting components we're depended onthisdb = unitsrequire'db';thislogicB = unitsrequire'logic.b';;unitsadd'db' someDbArgs;unitsadd'settings' '/path/to/project/root/or/something';unitsadd'logic.a' ;unitsadd'logic.b' ;unitsadd'facade' ;unitsinit; // calls unitInit() function of every unit internally
UnitSet can be added to other UnitSet which will be it's parent. On getting keys, lookup will be performed locally first, then on parent UnitSet. All child units will be added directly to parent and inited by parent as well.
var units = ;unitsadd'db' ;var childUnits = ;childUnitsadd'logic.a' ;childUnitsadd'logic.b' ;unitsaddSetchildUnits;childUnitsget'db'; // will try to find 'db' in childUnits, then in units
Unit class is actually an interface. You can inherit it to make obvious that your subclass is Unit. But you can also just implement unitInit() without inheriting Unit.