-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflow.js
61 lines (50 loc) · 1.48 KB
/
flow.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
var Flow;
(function (exports) {
if (typeof module !== "undefined" && module.exports) {
module.exports = exports; // CommonJS
} else if (typeof define === "function") {
define(exports); // AMD
} else {
Flow = exports; // <script>
}
}((function () {
function Flow() {
this.name = "flow.js";
this.version = "1.0.0";
this.stack = [];
this.count = 0;
}
Flow.prototype.par = function (callback, n) {
var current = this.stack.length - 1;
if (current < 1 || typeof this.stack[current] === 'function') {
this.stack.push([callback]);
} else {
this.stack[current].push(callback);
}
};
Flow.prototype.seq = function (callback) {
this.stack.push(callback);
};
Flow.prototype.call = function (flow, callback) {
callback(function () {
flow.next();
});
};
Flow.prototype.next = function () {
this.count--;
if (this.count < 1) {
var callbacks = this.stack.shift();
if (callbacks) {
if (typeof callbacks === 'function') {
this.call(this, callbacks);
} else {
this.count = callbacks.length;
for (var i = 0; i < callbacks.length; i++) {
this.call(this, callbacks[i]);
}
}
}
}
};
return Flow;
}())));