This repository has been archived by the owner on Dec 7, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
plugin.react.js
95 lines (78 loc) · 2.01 KB
/
plugin.react.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
// "react" (reactive sequences)
(function IIFE(){
var extensions = {};
ASQ.react = function $$react(reactor) {
function next() {
if (!paused) {
if (template) {
var sq = template.duplicate();
sq.unpause.apply(ø,arguments);
return sq;
}
return ASQ(function $$asq(){ throw "Disabled Sequence"; });
}
}
function registerTeardown(fn) {
if (template && typeof fn === "function") {
teardowns.push(fn);
}
}
var template = ASQ().duplicate(),
teardowns = [], paused = false
;
// add reactive sequence kill switch
template.stop = function $$stop() {
if (template) {
template = null;
teardowns.forEach(Function.call,Function.call);
teardowns.length = 0;
}
};
template.pause = function $$pause() {
if (!paused && template) {
paused = true;
teardowns.forEach(Function.call,Function.call);
teardowns.length = 0;
}
};
template.resume = function $$resume() {
if (paused && template) {
paused = false;
reactor.call(template,next,registerTeardown);
}
};
template.push = next;
next.onStream = function $$onStream() {
ARRAY_SLICE.call(arguments)
.forEach(function $$each(stream){
stream.on("data",next);
stream.on("error",next);
});
};
next.unStream = function $$unStream() {
ARRAY_SLICE.call(arguments)
.forEach(function $$each(stream){
stream.removeListener("data",next);
stream.removeListener("error",next);
});
};
Object.keys(extensions)
.forEach(function $$each(name){
template[name] = template[name] || extensions[name](template);
});
// blacklist (remove from reactive sequences)
["pipe","fork","errfcb","pThen","pCatch","toPromise"]
.forEach(function $$each(name){
delete template[name];
});
// make sure `reactor(..)` is called async
ASQ.__schedule(function $$schedule(){
reactor.call(template,next,registerTeardown);
});
return template;
};
ASQ.react.extend = function $$extend(name,build) {
extensions[name] = build;
return ASQ.react;
};
})();