Archetype provide a very powerful file loader. It handles lots of problematics:
You can use the file loader threw the public method Archetype.requre. It uses two parameters:
By using components and there dependency management, user has not to use the require method himself. Futur features on IoC (Inversion of Control) will give to user even more solutions to handle file loading without using directly the require method.
If you're using components, you already configured your dependencies in the component description. Archetype provide a special method to load all files needed to use a component: Archetype.requireComponent. You can use it with one or two parameters:
Here we can find some use cases of this methods. There directly belongs to Archetype's core sources.
This first example is the call to require which loads configured default modules and launch the Archetype._prepareBoot method as callback.
Archetype.require(Archetype.defaultModules, {
callback: Archetype._prepareBoot
});
This is the require used to load all libraries configured in dependencies of a component:
Archetype.require(componentDefinition.setup.dependencies.lib, {
evaluation: "js",
asynchronous: true,
callback: this.librariesDependenciesLoaded.bind(this, componentDefinition, setupJoiner)
});
The most common use of Archetype.requireComponent is to load the first component of an application from the {Page}.main function which is yout entry point. This is the case in the Slidy page (Pages/Slidy.js):
main: function() {
Archetype.requireComponent("Slidy.components.container");
}
We can imagin a new version with a parameter passed to the component constructor:
main: function() {
var myParameter = "foo";
Archetype.requireComponent("Slidy.components.container", function(containerConstructor) {
new containerConstructor(myParameter);
});
}