-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscope.js
46 lines (39 loc) · 1.18 KB
/
scope.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
"use strict";
module.exports = Scope;
function Scope() {
this.root = this;
this.components = Object.create(null);
this.componentsFor = Object.create(null);
}
Scope.prototype.nest = function () {
var child = Object.create(this);
child.parent = this;
child.caller = this.caller && this.caller.nest();
return child;
};
Scope.prototype.nestComponents = function () {
var child = this.nest();
child.components = Object.create(this.components);
child.componentsFor = Object.create(this.componentsFor);
return child;
};
// TODO deprecated
Scope.prototype.set = function (id, component) {
console.log(new Error().stack);
this.hookup(id, component);
};
Scope.prototype.hookup = function (id, component) {
var scope = this;
scope.components[id] = component;
if (scope.this.hookup) {
scope.this.hookup(id, component, scope);
} else if (scope.this.add) {
// TODO deprecated
scope.this.add(component, id, scope);
}
var exportId = scope.this.exports && scope.this.exports[id];
if (exportId) {
var callerId = scope.caller.id;
scope.caller.hookup(callerId + ":" + exportId, component);
}
};