-
Notifications
You must be signed in to change notification settings - Fork 0
/
scope.js
35 lines (27 loc) · 1 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
// Help.: https://github.com/diogolmenezes/scope/
class Scope {
// add on scope
addScope(value) {
this.scope = this.scope || { _chain: [] };
if (value) {
Object.assign(this.scope, value);
}
// put the objsct in the chain if its not
const object = this.__proto__.constructor.name;
const itsInTheChain = this.scope._chain.includes(object);
if (!itsInTheChain) {
// scans all properties that inherit from Scope and passes the scope
const scopableProperties = Object.keys(this).filter(x => this[x] instanceof Scope);
scopableProperties.map(property => {
this[property].scope = this.scope;
this[property].addScope();
});
this.scope._chain.push(object);
}
}
// remove from scope
removeScope(name) {
delete this.scope[name];
}
}
module.exports = Scope;