-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 933 Bytes
/
index.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
module.exports = function() {
var args = Array.prototype.slice.call(arguments);
var _initializers = [];
var _mounters = [];
var _updaters = [];
var contextOverrides = {
onInitialize: cb => {
_initializers.push(cb);
},
onMount: cb => {
_mounters.push(cb);
},
onUpdate: cb => {
_updaters.push(cb);
}
}
return function(context) {
var virtualContext = Object.assign({}, context, contextOverrides);
args.forEach(function(arg) {
arg(virtualContext);
})
context.onInitialize && context.onInitialize(function() {
_initializers.forEach(_initialize => _initialize.apply(this, arguments));
})
context.onMount && context.onMount(function() {
_mounters.forEach(_mount => _mount.apply(this, arguments));
})
context.onUpdate && context.onUpdate(function() {
_updaters.forEach(_update => _update.apply(this, arguments));
})
}
}