react 0.5.2 → 0.6.3

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