1 | var Pipeline = module.exports = function (controller) {
|
2 | this.steps = [];
|
3 | this.controller = controller;
|
4 | }
|
5 |
|
6 | Pipeline.prototype.addStep = function (step) {
|
7 | this.steps.push(step);
|
8 | }
|
9 |
|
10 | Pipeline.prototype.run = function (frame) {
|
11 | var stepsLength = this.steps.length;
|
12 | for (var i = 0; i != stepsLength; i++) {
|
13 | if (!frame) break;
|
14 | frame = this.steps[i](frame);
|
15 | }
|
16 | return frame;
|
17 | }
|
18 |
|
19 | Pipeline.prototype.removeStep = function(step){
|
20 | var index = this.steps.indexOf(step);
|
21 | if (index === -1) throw "Step not found in pipeline";
|
22 | this.steps.splice(index, 1);
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | Pipeline.prototype.addWrappedStep = function (type, callback) {
|
39 | var controller = this.controller,
|
40 | step = function (frame) {
|
41 | var dependencies, i, len;
|
42 | dependencies = (type == 'frame') ? [frame] : (frame[type + 's'] || []);
|
43 |
|
44 | for (i = 0, len = dependencies.length; i < len; i++) {
|
45 | callback.call(controller, dependencies[i]);
|
46 | }
|
47 |
|
48 | return frame;
|
49 | };
|
50 |
|
51 | this.addStep(step);
|
52 | return step;
|
53 | }; |
\ | No newline at end of file |