arcs_module.js
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* definition of the main module function:
* it takes an anonymous function as a parameter
* the anonymous function has one parameter: the object encompassing
* ARCS definitions (in order to able to use ARCS.Component.create, ...)
* @param moduleDefinition {function} main function of the module.
* It should return a list of components
* @param deps {mixed[]} dependencies
*/
// TODO remove dependency handling
// reimplementation using native promises
arcs_module = function(moduleDefinition) {
var storeComponents, i;
// TODO verify if this is still needed
if (typeof module !== 'undefined') {
if (module.parent.exports) {
ARCS = module.exports;
}
}
storeComponents = function () {
var mdef, p;
// we should insert ARCS at the beginning of deps !
mdef = (typeof moduleDefinition === 'function') ?
moduleDefinition.apply(this) : moduleDefinition;
if (mdef === undefined) {
throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition);
}
for (p in mdef) {
if (mdef.hasOwnProperty(p) && ARCS.Context.currentContext != null) {
ARCS.Context.currentContext.setFactory(p,mdef[p]); //.setFactory(ARCS.Application.currentApplication, p, mdef[p]);
}
}
return Promise.resolve();
};
// until now, it is the very same code.
ARCS.Context.currentContext.addLibraryPromise(
storeComponents,
function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); })
);
}