Closed Radnen closed 8 years ago
Very Python-esque. I like it, but I am having a difficult time imagining the actual implementation.
I'm sure the implementation would be something like:
var modules = [];
function AddModule(name, module) {
modules[name] = module;
}
Then when you implement creating a stage:
function CreateStage(name, stageparams) {
var stage = stageparams[stageparams.length-1];
var dependencies = [];
for (var i = 0; i < stageparams.length - 1; ++i) {
dependencies[i] = modules[stageparams[i]];
}
stage.load = stage.load.bind.apply(stage, dependencies);
stage.enter = stage.enter.bind.apply(stage, dependencies);
stage.leave = stage.leave.bind.apply(stage, dependencies); // etc.
modules[name] = stage;
return stage;
}
Of course we can get more elegant than that, but at least it shows you we have to utilize a hash map of modules to module names, and then when a stage is created, resolve the modules from it's dependency list. The API doesn't have to be like the above, I'm just doing it in the angular way, that's all.
Also notice I made a stage a module, because technically they would be no different. I just think that a stage is more of an interface. A stage is a module but it must have load/enter/leave functions whereas a standard module can have really anything.
For some reason, I have NO clue what this is about.
One this i am sure of, we can't name them modules because code encapsulation will use a 'module' system (like angular.js, like node.js, etc).
Maybe you mean something alike... But I am not a real fan of how angular does it...
Dependency Injection is used to automatically find and resolve dependencies. This is useful for making sure your code uses the libraries it only should use rather than just have access to all code files. http://en.wikipedia.org/wiki/Dependency_injection
Anyways, I think it's easy enough to add in pure js code, so it's not necessarily an engine-level thing unless we intend to add it to #9 somehow.
I am currently trying to implement #9, after that I can see about adding dependency injections.
AFAIK, Angular uses this module system because it is Async: it loads the dependencies and then itself and then executes that code. I don't think we need async loading of libs. I don't see how dependency injection in such form will help us in the current module/require() system.
I think sphere stages should have the ability to load in a dependency module without extra boiler-plate code.