-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.js
131 lines (131 loc) · 5.26 KB
/
Application.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
define(["require", "exports", './has', 'dojo/_base/lang', './LogLevel', './ObservableEvented', './Promise', './util'], function (require, exports, has, lang, LogLevel, ObservableEvented, Promise, util) {
var resolve = require.toAbsMid || require.resolve;
var defaultBindings = [
resolve('./binding/bindings/CompositeBinding'),
resolve('./binding/bindings/ObjectMethodBinding'),
resolve('./binding/bindings/NestedBinding'),
resolve('./binding/bindings/ObservableBinding'),
resolve('./binding/bindings/StatefulBinding'),
resolve('./binding/bindings/CollectionLengthBinding'),
resolve('./binding/bindings/CollectionBinding'),
resolve('./binding/bindings/ArrayBinding'),
resolve('./binding/bindings/DomInputBinding')
];
if (has('es7-object-observe')) {
defaultBindings.push(resolve('./binding/bindings/Es7Binding'));
}
else {
defaultBindings.push(resolve('./binding/bindings/Es5Binding'), resolve('./binding/bindings/ObjectTargetBinding'));
}
var Application = (function (_super) {
__extends(Application, _super);
function Application(kwArgs) {
kwArgs = util.deepCreate(this.constructor._defaultConfig, kwArgs);
_super.call(this, kwArgs);
}
Application.prototype.destroy = function () {
for (var key in this) {
var component = this[key];
component.destroy && component.destroy();
}
_super.prototype.destroy.call(this);
};
Application.prototype.handleError = function (error) {
var errorHandler = this.get('errorHandler');
if (errorHandler) {
errorHandler.handleError(error);
}
else {
this.log(error.stack || error.message, 0 /* ERROR */, 'error/' + error.name);
}
};
Application.prototype.log = function (message, level, category) {
if (level === void 0) { level = 2 /* LOG */; }
if (category === void 0) { category = null; }
var logger = this.get('logger');
if (logger) {
logger.log(message, level, category);
}
else {
console[LogLevel[level].toLowerCase()]((category ? category + ': ' : '') + message);
}
};
Application.prototype.run = function () {
var self = this;
var components = this._components;
function getConstructors() {
var ctors = {};
for (var key in components) {
if (!components[key]) {
continue;
}
ctors[key] = new Promise(function (resolve, reject) {
var ctor = components[key].constructor;
if (typeof ctor === 'string') {
util.getModule(ctor).then(resolve, reject);
}
else if (typeof ctor === 'function') {
resolve(ctor);
}
else {
reject(new Error('Constructor for ' + key + ' must be a string or function'));
}
});
}
return Promise.all(ctors);
}
function instantiateComponents(ctors) {
var instance;
var instances = [];
var startups = [];
for (var key in ctors) {
instance = new ctors[key](lang.mixin({ app: self }, components[key], { constructor: undefined }));
self.set(key, instance);
instances.push(instance);
}
while ((instance = instances.shift())) {
instance.run && startups.push(instance.run());
}
return Promise.all(startups);
}
if (has('debug')) {
this.on('error', function (event) {
console.error(event.message);
});
}
var promise = getConstructors().then(instantiateComponents).then(function () {
return self;
});
this.run = function () {
return promise;
};
return promise;
};
Application._defaultConfig = {
components: {
binder: {
constructor: resolve('./binding/Binder'),
constructors: defaultBindings
},
errorHandler: {
constructor: resolve('./ErrorHandler')
},
i18n: {
constructor: resolve('./I18n')
},
scheduler: {
constructor: resolve('./Scheduler')
}
}
};
return Application;
})(ObservableEvented);
return Application;
});
//# sourceMappingURL=_debug/Application.js.map