react 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +4 -0
- package/Jakefile.js +39 -0
- package/README.md +9 -22
- package/browser-test/dist.html +90 -0
- package/browser-test/index.html +86 -0
- package/browser-test/min.html +90 -0
- package/dist/react.js +3291 -0
- package/dist/react.min.js +1 -0
- package/doc/advanced.md +2 -2
- package/examples/using-events1.js +1 -1
- package/lib/base-task.js +116 -110
- package/lib/cb-task.js +71 -67
- package/lib/core.js +118 -119
- package/lib/dsl.js +120 -115
- package/lib/error.js +44 -36
- package/lib/event-collector.js +69 -56
- package/lib/event-manager.js +65 -58
- package/lib/eventemitter.js +20 -0
- package/lib/finalcb-first-task.js +56 -53
- package/lib/finalcb-task.js +55 -51
- package/lib/id.js +18 -7
- package/lib/input-parser.js +49 -41
- package/lib/log-events.js +79 -73
- package/lib/parse.js +34 -25
- package/lib/promise-resolve.js +42 -27
- package/lib/promise-task.js +78 -74
- package/lib/react.js +59 -0
- package/lib/ret-task.js +59 -55
- package/lib/sprintf.js +18 -0
- package/lib/status.js +11 -2
- package/lib/task.js +218 -217
- package/lib/track-tasks.js +72 -58
- package/lib/validate.js +136 -136
- package/lib/vcon.js +78 -69
- package/lib/when-task.js +69 -65
- package/package.json +11 -9
- package/src/dist.build.requirejs +20 -0
- package/test/ast.mocha.js +136 -0
- package/test/cb-task.mocha.js +220 -0
- package/test/core-deferred.mocha.js +143 -0
- package/test/core-when.mocha.js +96 -0
- package/test/core.mocha.js +589 -0
- package/test/dsl.mocha.js +350 -0
- package/test/event-manager.mocha.js +119 -0
- package/test/exec-options.mocha.js +48 -0
- package/test/finalcb-task.mocha.js +58 -0
- package/test/input-parser.mocha.js +86 -0
- package/test/mocha.opts +2 -0
- package/test/module-use.mocha.js +147 -0
- package/test/promise-auto-resolve.mocha.js +68 -0
- package/test/ret-task.mocha.js +220 -0
- package/test/task.mocha.js +42 -0
- package/test/validate-cb-task.mocha.js +100 -0
- package/test/validate-ret-task.mocha.js +110 -0
- package/test/validate.mocha.js +324 -0
- package/test/vcon.mocha.js +193 -0
- package/vendor/chai/chai.js +2038 -0
- package/vendor/jquery/jquery-1.7.1.js +9266 -0
- package/vendor/jquery/jquery-1.7.1.min.js +4 -0
- package/vendor/mocha/mocha.css +135 -0
- package/vendor/mocha/mocha.js +3589 -0
- package/vendor/node/util.js +531 -0
- package/vendor/requirejs/require.js +2053 -0
- package/vendor/requirejs/require.min.js +33 -0
- package/react.js +0 -40
- package/test/ast.test.js +0 -118
- package/test/cb-task.test.js +0 -197
- package/test/core-deferred.test.js +0 -134
- package/test/core-promised.test.js +0 -132
- package/test/core-when.test.js +0 -84
- package/test/core.test.js +0 -593
- package/test/dsl.test.js +0 -330
- package/test/event-manager.test.js +0 -102
- package/test/exec-options.test.js +0 -33
- package/test/finalcb-task.test.js +0 -38
- package/test/input-parser.test.js +0 -66
- package/test/module-use.test.js +0 -134
- package/test/promise-auto-resolve.test.js +0 -52
- package/test/ret-task.test.js +0 -199
- package/test/task.test.js +0 -21
- package/test/validate-cb-task.test.js +0 -74
- package/test/validate-ret-task.test.js +0 -83
- package/test/validate.test.js +0 -295
- package/test/vcon.test.js +0 -173
package/lib/event-manager.js
CHANGED
|
@@ -1,75 +1,82 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/*global define:true process:false*/
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
if (typeof define !== 'function') {
|
|
5
|
+
var define = require('amdefine')(module);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
define(['./eventemitter'], function (EventEmitter) {
|
|
4
9
|
|
|
5
|
-
var EVENT_EMITTER2_CONFIG = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
+
var EVENT_EMITTER2_CONFIG = {
|
|
11
|
+
wildcard: true, // should the event emitter use wildcards.
|
|
12
|
+
delimiter: '.', // the delimiter used to segment namespaces, defaults to `.`.
|
|
13
|
+
maxListeners: 30 // the max number of listeners that can be assigned to an event, defaults to 10.
|
|
14
|
+
};
|
|
10
15
|
|
|
11
|
-
var PASS_EVENTS_PROCESS_RE = /^ast.defined$/; // events to pass up to global process
|
|
16
|
+
var PASS_EVENTS_PROCESS_RE = /^ast.defined$/; // events to pass up to global process
|
|
12
17
|
|
|
13
|
-
var TYPES = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
var TYPES = {
|
|
19
|
+
// Flow monitoring events and their params
|
|
20
|
+
AST_DEFINED: 'ast.defined', // ast
|
|
21
|
+
FLOW_BEGIN: 'flow.begin', // env
|
|
22
|
+
TASK_BEGIN: 'task.begin', // task
|
|
23
|
+
TASK_COMPLETE: 'task.complete', // task
|
|
24
|
+
TASK_ERRORED: 'task.errored', // task
|
|
25
|
+
FLOW_COMPLETE: 'flow.complete', // env
|
|
26
|
+
FLOW_ERRORED: 'flow.errored', // env
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
};
|
|
28
|
+
// Internal Hooks
|
|
29
|
+
EXEC_FLOW_START: 'exec.flow.start', // env
|
|
30
|
+
EXEC_INPUT_PREPROCESS: 'exec.input.preprocess', // parsedInput
|
|
31
|
+
EXEC_TASKS_PRECREATE: 'exec.tasks.precreate', // env
|
|
32
|
+
EXEC_OUTTASK_CREATE: 'exec.outTask.create', // outTaskOptions
|
|
33
|
+
EXEC_TASK_START: 'exec.task.start', // task
|
|
34
|
+
EXEC_TASK_COMPLETE: 'exec.task.complete', // task
|
|
35
|
+
EXEC_TASK_ERRORED: 'exec.task.errored', // task
|
|
36
|
+
EXEC_FLOW_COMPLETE: 'exec.flow.complete', // env
|
|
37
|
+
EXEC_FLOW_ERRORED: 'exec.flow.errored' // env
|
|
38
|
+
};
|
|
34
39
|
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
/**
|
|
41
|
+
Event manager which emits events up to its parent if exists.
|
|
42
|
+
Allows a hierarchy of emitters, which communicate up the
|
|
43
|
+
chain.
|
|
39
44
|
*/
|
|
40
|
-
function EventManager() {
|
|
41
|
-
}
|
|
45
|
+
function EventManager() {
|
|
46
|
+
}
|
|
42
47
|
|
|
43
|
-
EventManager.create = function () { return new EventManager(); };
|
|
48
|
+
EventManager.create = function () { return new EventManager(); };
|
|
44
49
|
|
|
45
|
-
EventManager.TYPES = TYPES;
|
|
46
|
-
EventManager.prototype.TYPES = TYPES;
|
|
50
|
+
EventManager.TYPES = TYPES;
|
|
51
|
+
EventManager.prototype.TYPES = TYPES;
|
|
47
52
|
|
|
48
|
-
EventManager.prototype.isEnabled = function () { // if has listener or an ancestor has listener
|
|
49
|
-
|
|
50
|
-
};
|
|
53
|
+
EventManager.prototype.isEnabled = function () { // if has listener or an ancestor has listener
|
|
54
|
+
return !!(this.emitter || (this.parent && this.parent.isEnabled()));
|
|
55
|
+
};
|
|
51
56
|
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
/**
|
|
58
|
+
Add listener. Wildcard events are allowed like 'foo.*'
|
|
59
|
+
Use '*' to listen to any event
|
|
55
60
|
*/
|
|
56
|
-
EventManager.prototype.on = function (event, listener) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
+
EventManager.prototype.on = function (event, listener) {
|
|
62
|
+
if (!this.emitter) this.emitter = new EventEmitter(EVENT_EMITTER2_CONFIG);
|
|
63
|
+
if (event === '*') this.emitter.onAny(listener);
|
|
64
|
+
else this.emitter.on(event, listener);
|
|
65
|
+
};
|
|
61
66
|
|
|
62
|
-
EventManager.prototype.emit = function (event, arg1, arg2, argN) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
67
|
+
EventManager.prototype.emit = function (event, arg1, arg2, argN) {
|
|
68
|
+
if (event === undefined) throw new Error('event is undefined');
|
|
69
|
+
if (this.emitter) this.emitter.emit.apply(this.emitter, arguments);
|
|
70
|
+
if (this.parent && this.parent.isEnabled()) this.parent.emit.apply(this.parent, arguments);
|
|
71
|
+
if (PASS_EVENTS_PROCESS_RE.test(event) && process && process.emit) process.emit.apply(process, arguments); // pass some to process
|
|
72
|
+
};
|
|
68
73
|
|
|
69
|
-
EventManager.prototype.removeListener = function (event, listener) {
|
|
70
|
-
|
|
71
|
-
};
|
|
74
|
+
EventManager.prototype.removeListener = function (event, listener) {
|
|
75
|
+
if (this.emitter) this.emitter.removeListener.apply(this.emitter, arguments);
|
|
76
|
+
};
|
|
72
77
|
|
|
73
78
|
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
EventManager.global = EventManager.create(); // create one top level emitter
|
|
80
|
+
return EventManager;
|
|
81
|
+
|
|
82
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/*global define:true EventEmitter2:true */
|
|
3
|
+
|
|
4
|
+
if (typeof define !== 'function') {
|
|
5
|
+
var define = require('amdefine')(module);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
define(['eventemitter2'], function (EventEmitterMod) {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
Abstract the details of getting an EventEmitter
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// EventEmitter doesn't return itself in browser so need to get the global
|
|
15
|
+
// EventEmitter api changed, so accomodate which ever version is available
|
|
16
|
+
var EventEmitter = (EventEmitterMod) ?
|
|
17
|
+
((EventEmitterMod.EventEmitter2) ? EventEmitterMod.EventEmitter2 : EventEmitterMod) : EventEmitter2;
|
|
18
|
+
return EventEmitter;
|
|
19
|
+
|
|
20
|
+
});
|
|
@@ -1,65 +1,68 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/*global define:true */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
var
|
|
4
|
+
if (typeof define !== 'function') {
|
|
5
|
+
var define = require('amdefine')(module);
|
|
6
|
+
}
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var EventManager = require('./event-manager.js');
|
|
8
|
+
define(['./sprintf', 'util', './status', './vcon', './event-manager'],
|
|
9
|
+
function (sprintf, util, STATUS, VContext, EventManager) {
|
|
9
10
|
|
|
10
|
-
var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
|
|
11
|
+
var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
|
|
11
12
|
|
|
12
|
-
function FinalCbFirstSuccTask(outTaskOptions) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
function FinalCbFirstSuccTask(outTaskOptions) {
|
|
14
|
+
var taskDef = outTaskOptions.taskDef;
|
|
15
|
+
if (typeof(outTaskOptions.cbFunc) !== 'function') throw new Error('callback is not a function');
|
|
16
|
+
var self = this;
|
|
17
|
+
for (var k in taskDef) {
|
|
18
|
+
if (true) self[k] = taskDef[k]; // if to make jshint happy
|
|
19
|
+
}
|
|
20
|
+
this.f = outTaskOptions.cbFunc;
|
|
21
|
+
this.tasks = outTaskOptions.tasks;
|
|
22
|
+
this.vCon = outTaskOptions.vCon;
|
|
23
|
+
this.retValue = outTaskOptions.retValue;
|
|
24
|
+
this.env = outTaskOptions.env;
|
|
18
25
|
}
|
|
19
|
-
this.f = outTaskOptions.cbFunc;
|
|
20
|
-
this.tasks = outTaskOptions.tasks;
|
|
21
|
-
this.vCon = outTaskOptions.vCon;
|
|
22
|
-
this.retValue = outTaskOptions.retValue;
|
|
23
|
-
this.env = outTaskOptions.env;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function format_error(errmsg, obj) {
|
|
27
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
28
|
-
}
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (! (Array.isArray(taskDef.a) &&
|
|
33
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
34
|
-
errors.push(format_error(OUTTASK_A_REQ, taskDef));
|
|
27
|
+
function format_error(errmsg, obj) {
|
|
28
|
+
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
35
29
|
}
|
|
36
|
-
return errors;
|
|
37
|
-
};
|
|
38
30
|
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
FinalCbFirstSuccTask.validate = function (taskDef) {
|
|
32
|
+
var errors = [];
|
|
33
|
+
if (! (Array.isArray(taskDef.a) &&
|
|
34
|
+
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
35
|
+
errors.push(format_error(OUTTASK_A_REQ, taskDef));
|
|
36
|
+
}
|
|
37
|
+
return errors;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
is ready to exit when any task comes back with non-null defined value
|
|
41
42
|
*/
|
|
42
|
-
FinalCbFirstSuccTask.prototype.isReady = function () {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
43
|
+
FinalCbFirstSuccTask.prototype.isReady = function () {
|
|
44
|
+
var lastres = this.vCon.getLastResults();
|
|
45
|
+
if (!lastres) return false; // no results yet
|
|
46
|
+
return (lastres.some(function (v) { return (v !== undefined && v !== null); }));
|
|
47
|
+
};
|
|
47
48
|
|
|
48
|
-
FinalCbFirstSuccTask.prototype.exec = function (err) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
49
|
+
FinalCbFirstSuccTask.prototype.exec = function (err) {
|
|
50
|
+
if (!this.f) return; //must have already been called
|
|
51
|
+
if (err) {
|
|
52
|
+
this.env.error = err;
|
|
53
|
+
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_ERRORED, this.env);
|
|
54
|
+
this.f.call(null, err); //call the final callback with the first error hit
|
|
55
|
+
} else { // no error, call with args
|
|
56
|
+
var vCon = this.vCon;
|
|
57
|
+
var finalArgs = this.a.map(function (k) { return vCon.getVar(k); });
|
|
58
|
+
finalArgs.unshift(null); //unshift err=null to front
|
|
59
|
+
this.env.results = finalArgs;
|
|
60
|
+
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_COMPLETE, this.env);
|
|
61
|
+
this.f.apply(null, finalArgs);
|
|
62
|
+
}
|
|
63
|
+
this.f = null; // prevent multiple calls
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return FinalCbFirstSuccTask;
|
|
64
67
|
|
|
65
|
-
|
|
68
|
+
});
|
package/lib/finalcb-task.js
CHANGED
|
@@ -1,61 +1,65 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/*global define:true */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
var
|
|
4
|
+
if (typeof define !== 'function') {
|
|
5
|
+
var define = require('amdefine')(module);
|
|
6
|
+
}
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
define(['./sprintf', 'util', './status', './event-manager'],
|
|
9
|
+
function (sprintf, util, STATUS, EventManager) {
|
|
8
10
|
|
|
9
|
-
var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
|
|
11
|
+
var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
|
|
10
12
|
|
|
11
|
-
function FinalCbTask(outTaskOptions) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
function FinalCbTask(outTaskOptions) {
|
|
14
|
+
var taskDef = outTaskOptions.taskDef;
|
|
15
|
+
if (typeof(outTaskOptions.cbFunc) !== 'function') throw new Error('callback is not a function');
|
|
16
|
+
var self = this;
|
|
17
|
+
for (var k in taskDef) {
|
|
18
|
+
if (true) self[k] = taskDef[k]; // if to make jshint happy
|
|
19
|
+
}
|
|
20
|
+
this.f = outTaskOptions.cbFunc;
|
|
21
|
+
this.tasks = outTaskOptions.tasks;
|
|
22
|
+
this.vCon = outTaskOptions.vCon;
|
|
23
|
+
this.retValue = outTaskOptions.retValue;
|
|
24
|
+
this.execOptions = outTaskOptions.execOptions;
|
|
25
|
+
this.env = outTaskOptions.env;
|
|
17
26
|
}
|
|
18
|
-
this.f = outTaskOptions.cbFunc;
|
|
19
|
-
this.tasks = outTaskOptions.tasks;
|
|
20
|
-
this.vCon = outTaskOptions.vCon;
|
|
21
|
-
this.retValue = outTaskOptions.retValue;
|
|
22
|
-
this.execOptions = outTaskOptions.execOptions;
|
|
23
|
-
this.env = outTaskOptions.env;
|
|
24
|
-
}
|
|
25
27
|
|
|
26
|
-
function format_error(errmsg, obj) {
|
|
27
|
-
|
|
28
|
-
}
|
|
28
|
+
function format_error(errmsg, obj) {
|
|
29
|
+
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
30
|
+
}
|
|
29
31
|
|
|
30
32
|
|
|
31
|
-
FinalCbTask.validate = function (taskDef) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
FinalCbTask.prototype.isReady = function () {
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
FinalCbTask.prototype.exec = function (err) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
33
|
+
FinalCbTask.validate = function (taskDef) {
|
|
34
|
+
var errors = [];
|
|
35
|
+
if (! (Array.isArray(taskDef.a) &&
|
|
36
|
+
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
37
|
+
errors.push(format_error(OUTTASK_A_REQ, taskDef));
|
|
38
|
+
}
|
|
39
|
+
return errors;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
FinalCbTask.prototype.isReady = function () {
|
|
43
|
+
return (this.tasks.every(function (t) { return (t.status === STATUS.COMPLETE); }));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
FinalCbTask.prototype.exec = function (err) {
|
|
47
|
+
if (!this.f) return; //must have already been called
|
|
48
|
+
if (err) {
|
|
49
|
+
this.env.error = err;
|
|
50
|
+
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_ERRORED, this.env);
|
|
51
|
+
this.f.call(null, err); //call the final callback with the first error hit
|
|
52
|
+
} else { // no error, call with args
|
|
53
|
+
var vCon = this.vCon;
|
|
54
|
+
var finalArgs = this.a.map(function (k) { return vCon.getVar(k); });
|
|
55
|
+
finalArgs.unshift(null); //unshift err=null to front
|
|
56
|
+
this.env.results = finalArgs;
|
|
57
|
+
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_COMPLETE, this.env);
|
|
58
|
+
this.f.apply(null, finalArgs);
|
|
59
|
+
}
|
|
60
|
+
this.f = null; // prevent multiple calls
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return FinalCbTask;
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
});
|
package/lib/id.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/*global define:true */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function createUniqueId() {
|
|
6
|
-
startingId += 1;
|
|
7
|
-
if (startingId === Number.MAX_VALUE) startingId = 0; // if hits this start over //TODO need something better?
|
|
8
|
-
return startingId;
|
|
4
|
+
if (typeof define !== 'function') {
|
|
5
|
+
var define = require('amdefine')(module);
|
|
9
6
|
}
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
define([], function () {
|
|
9
|
+
|
|
10
|
+
var startingId = 0;
|
|
11
|
+
|
|
12
|
+
function createUniqueId() {
|
|
13
|
+
startingId += 1;
|
|
14
|
+
if (startingId === Number.MAX_VALUE) startingId = 0; // if hits this start over //TODO need something better?
|
|
15
|
+
return startingId;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
createUniqueId: createUniqueId
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
});
|
package/lib/input-parser.js
CHANGED
|
@@ -1,48 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
+
/*global define:true */
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
if (typeof define !== 'function') {
|
|
5
|
+
var define = require('amdefine')(module);
|
|
6
|
+
}
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
reactExecOptions: true,
|
|
7
|
-
outputStyle: 'cb',
|
|
8
|
-
};
|
|
8
|
+
define(['./event-manager'], function (EventManager) {
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
10
|
+
var defaultExecOptions = {
|
|
11
|
+
reactExecOptions: true,
|
|
12
|
+
outputStyle: 'cb',
|
|
13
|
+
};
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.keys(options).forEach(function (k) { accum[k] = options[k]; });
|
|
20
|
-
return accum;
|
|
21
|
-
}
|
|
15
|
+
var OUTPUT_STYLES = {
|
|
16
|
+
CALLBACK: 'cb',
|
|
17
|
+
NONE: 'none'
|
|
18
|
+
};
|
|
22
19
|
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
20
|
+
function isExecOptions(x) { return (x && x.reactExecOptions); }
|
|
21
|
+
function execOptionsFilter(x) { return isExecOptions(x); }
|
|
22
|
+
function nonExecOptionsFilter(x) { return !isExecOptions(x); }
|
|
23
|
+
function mergeExecOptions(accum, options) {
|
|
24
|
+
Object.keys(options).forEach(function (k) { accum[k] = options[k]; });
|
|
25
|
+
return accum;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function splitArgs(args, inParams, style) {
|
|
29
|
+
var result = { };
|
|
30
|
+
result.args = inParams.map(function (p) { return args.shift(); }); // take args for input params first
|
|
31
|
+
if (style === OUTPUT_STYLES.CALLBACK && args.length) result.cb = args.shift(); // next take the cb
|
|
32
|
+
result.extra = args; // these remaining were after the callback
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function inputParser(inputArgs, ast) {
|
|
37
|
+
var parsedInput = { };
|
|
38
|
+
var execOptionsArr = inputArgs.filter(execOptionsFilter);
|
|
39
|
+
execOptionsArr.unshift(defaultExecOptions);
|
|
40
|
+
parsedInput.options = execOptionsArr.reduce(mergeExecOptions, {});
|
|
41
|
+
|
|
42
|
+
var args = inputArgs.filter(nonExecOptionsFilter);
|
|
43
|
+
var splitResult = splitArgs(args, ast.inParams, parsedInput.options.outputStyle);
|
|
44
|
+
parsedInput.args = splitResult.args;
|
|
45
|
+
parsedInput.cb = splitResult.cb;
|
|
46
|
+
if (splitResult.outputStyle) parsedInput.options.outputStyle = splitResult.outputStyle;
|
|
47
|
+
if (splitResult.extra) parsedInput.extraArgs = splitResult.extra;
|
|
48
|
+
EventManager.global.emit(EventManager.TYPES.EXEC_INPUT_PREPROCESS, parsedInput); // hook
|
|
49
|
+
return parsedInput;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
inputParser.defaultExecOptions = defaultExecOptions;
|
|
54
|
+
return inputParser;
|
|
46
55
|
|
|
47
|
-
|
|
48
|
-
module.exports.defaultExecOptions = defaultExecOptions;
|
|
56
|
+
});
|