-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmicroObservables.js
More file actions
40 lines (35 loc) · 792 Bytes
/
microObservables.js
File metadata and controls
40 lines (35 loc) · 792 Bytes
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
var observable = function (o) {
var h = {};
o.on = function (e, fn) {
if(typeof fn !== "function") return;
if(!h[e]) h[e] = [];
h[e].push(fn);
return o;
};
o.off = function (es) {
es = es.split(/\s+/);
for (var i = 0; i < es.length; i++) {
delete h[es[i]];
}
return o;
};
o.trigger = function (e) {
var args = Array.prototype.slice.call(arguments, 1);
fns = h[e] || [];
for (var i = 0; i < fns.length; i++) {
fns[i].apply(fns[i], args);
}
return o;
};
return o;
};
if (typeof exports === 'undefined') {
window.observable = observable;
if (typeof window.define === "function" && window.define.amd) {
window.define("microObservables", [], function() {
return window.observable;
});
}
} else {
module.exports = observable;
}