react 0.5.1 → 0.6.2

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 (88) hide show
  1. package/.travis.yml +5 -0
  2. package/Jakefile.js +39 -0
  3. package/README.md +17 -24
  4. package/browser-test/dist.html +89 -0
  5. package/browser-test/index.html +85 -0
  6. package/browser-test/min.html +89 -0
  7. package/dist/react.js +3094 -0
  8. package/dist/react.min.js +22 -0
  9. package/doc/advanced.md +2 -2
  10. package/doc/simple.dot +25 -0
  11. package/doc/simple.png +0 -0
  12. package/examples/using-events1.js +1 -1
  13. package/lib/base-task.js +116 -110
  14. package/lib/cb-task.js +71 -67
  15. package/lib/core.js +116 -117
  16. package/lib/dsl.js +120 -115
  17. package/lib/error.js +44 -36
  18. package/lib/event-collector.js +69 -56
  19. package/lib/event-manager.js +69 -56
  20. package/lib/eventemitter.js +20 -0
  21. package/lib/finalcb-first-task.js +56 -53
  22. package/lib/finalcb-task.js +55 -51
  23. package/lib/id.js +18 -7
  24. package/lib/input-parser.js +49 -41
  25. package/lib/log-events.js +79 -73
  26. package/lib/parse.js +34 -25
  27. package/lib/promise-resolve.js +42 -27
  28. package/lib/promise-task.js +78 -74
  29. package/lib/react.js +59 -0
  30. package/lib/ret-task.js +59 -55
  31. package/lib/sprintf.js +18 -0
  32. package/lib/status.js +11 -2
  33. package/lib/task.js +215 -217
  34. package/lib/track-tasks.js +72 -58
  35. package/lib/validate.js +136 -136
  36. package/lib/vcon.js +78 -69
  37. package/lib/when-task.js +69 -65
  38. package/package.json +10 -9
  39. package/src/dist.build.requirejs +20 -0
  40. package/test/ast.mocha.js +136 -0
  41. package/test/cb-task.mocha.js +220 -0
  42. package/test/core-deferred.mocha.js +143 -0
  43. package/test/core-when.mocha.js +96 -0
  44. package/test/core.mocha.js +589 -0
  45. package/test/dsl.mocha.js +350 -0
  46. package/test/event-manager.mocha.js +119 -0
  47. package/test/exec-options.mocha.js +48 -0
  48. package/test/finalcb-task.mocha.js +58 -0
  49. package/test/input-parser.mocha.js +86 -0
  50. package/test/mocha.opts +2 -0
  51. package/test/module-use.mocha.js +147 -0
  52. package/test/promise-auto-resolve.mocha.js +68 -0
  53. package/test/ret-task.mocha.js +220 -0
  54. package/test/task.mocha.js +42 -0
  55. package/test/validate-cb-task.mocha.js +100 -0
  56. package/test/validate-ret-task.mocha.js +110 -0
  57. package/test/validate.mocha.js +324 -0
  58. package/test/vcon.mocha.js +193 -0
  59. package/vendor/chai/chai.js +2038 -0
  60. package/vendor/jquery/jquery-1.7.1.js +9266 -0
  61. package/vendor/jquery/jquery-1.7.1.min.js +4 -0
  62. package/vendor/mocha/mocha.css +135 -0
  63. package/vendor/mocha/mocha.js +3589 -0
  64. package/vendor/node/util.js +531 -0
  65. package/vendor/requirejs/require.js +2053 -0
  66. package/vendor/requirejs/require.min.js +33 -0
  67. package/doc/default-simple.dot +0 -19
  68. package/doc/default-simple.dot.png +0 -0
  69. package/react.js +0 -40
  70. package/test/ast.test.js +0 -95
  71. package/test/cb-task.test.js +0 -197
  72. package/test/core-deferred.test.js +0 -134
  73. package/test/core-promised.test.js +0 -132
  74. package/test/core-when.test.js +0 -84
  75. package/test/core.test.js +0 -593
  76. package/test/dsl.test.js +0 -330
  77. package/test/event-manager.test.js +0 -102
  78. package/test/exec-options.test.js +0 -33
  79. package/test/finalcb-task.test.js +0 -38
  80. package/test/input-parser.test.js +0 -66
  81. package/test/module-use.test.js +0 -134
  82. package/test/promise-auto-resolve.test.js +0 -52
  83. package/test/ret-task.test.js +0 -199
  84. package/test/task.test.js +0 -21
  85. package/test/validate-cb-task.test.js +0 -74
  86. package/test/validate-ret-task.test.js +0 -83
  87. package/test/validate.test.js +0 -295
  88. package/test/vcon.test.js +0 -173
@@ -1,35 +1,50 @@
1
1
  'use strict';
2
+ /*global define:true */
2
3
 
3
- /**
4
- Auto resolve promises passed in as arguments to the flow
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
5
7
 
6
- - Detects promises by checking for .then()
7
- - Create promise name for param (param__promise)
8
- - moves existing vCon promise into the param__promise
9
- - creates WhenTask which resolves param__promise into param
8
+ define([], function () {
9
+
10
+ /**
11
+ Auto resolve promises passed in as arguments to the flow
12
+
13
+ - Detects promises by checking for .then()
14
+ - Create promise name for param (param__promise)
15
+ - moves existing vCon promise into the param__promise
16
+ - creates WhenTask which resolves param__promise into param
10
17
  */
11
18
 
12
19
 
13
- var react = require('../'); // require('react');
14
-
15
- var PROMISE_SUFFIX = '__promise'; // added to param names that are promises
16
-
17
- react.events.on(react.events.TYPES.EXEC_TASKS_PRECREATE, function (env) {
18
- var vConValues = env.vCon.values;
19
- var promiseParams = env.ast.inParams.filter(function (p) {
20
- var value = vConValues[p];
21
- return (value && typeof(value.then) === 'function');
22
- });
23
- promiseParams.forEach(function (p) {
24
- var promiseName = p + PROMISE_SUFFIX;
25
- vConValues[promiseName] = vConValues[p];
26
- vConValues[p] = undefined;
27
- env.taskDefs.push({
28
- type: 'when',
29
- a: [promiseName],
30
- out: [p]
20
+ var PROMISE_SUFFIX = '__promise'; // added to param names that are promises
21
+
22
+ var resolvingPromises = false;
23
+
24
+ function resolvePromises(react) {
25
+ if (resolvingPromises) return; // already resolving
26
+ resolvingPromises = true;
27
+
28
+ react.events.on(react.events.TYPES.EXEC_TASKS_PRECREATE, function (env) {
29
+ var vConValues = env.vCon.values;
30
+ var promiseParams = env.ast.inParams.filter(function (p) {
31
+ var value = vConValues[p];
32
+ return (value && typeof(value.then) === 'function');
33
+ });
34
+ promiseParams.forEach(function (p) {
35
+ var promiseName = p + PROMISE_SUFFIX;
36
+ vConValues[promiseName] = vConValues[p];
37
+ vConValues[p] = undefined;
38
+ env.taskDefs.push({
39
+ type: 'when',
40
+ a: [promiseName],
41
+ out: [p]
42
+ });
43
+ });
31
44
  });
32
- });
33
- });
34
45
 
35
- module.exports = react; // return react
46
+ }
47
+
48
+ return resolvePromises;
49
+
50
+ });
@@ -1,89 +1,93 @@
1
1
  'use strict';
2
+ /*global define:true */
2
3
 
3
- /**
4
- PromiseTask is a task which executes a fn that returns a promise
5
- and when it completes it sets the values in vCon
6
- */
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
7
7
 
8
- var util = require('util');
9
- var sprintf = require('sprintf').sprintf;
8
+ define(['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
10
9
 
11
- var BaseTask = require('./base-task.js');
10
+ /**
11
+ PromiseTask is a task which executes a fn that returns a promise
12
+ and when it completes it sets the values in vCon
13
+ */
12
14
 
13
- function format_error(errmsg, obj) {
14
- return sprintf('%s - %s', errmsg, util.inspect(obj));
15
- }
15
+ function format_error(errmsg, obj) {
16
+ return sprintf('%s - %s', errmsg, util.inspect(obj));
17
+ }
16
18
 
17
- var REQ = 'promiseTask requires f, a, out';
18
- var FN_REQ = 'promiseTask requires f to be a function or string';
19
- var A_REQ = 'promiseTask requires a to be an array of string param names';
20
- var OUT_REQ = 'promiseTask requires out to be an array[1] of string param names';
19
+ var REQ = 'promiseTask requires f, a, out';
20
+ var FN_REQ = 'promiseTask requires f to be a function or string';
21
+ var A_REQ = 'promiseTask requires a to be an array of string param names';
22
+ var OUT_REQ = 'promiseTask requires out to be an array[1] of string param names';
21
23
 
22
- function PromiseTask(taskDef) {
23
- var self = this;
24
- Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
25
- }
24
+ function PromiseTask(taskDef) {
25
+ var self = this;
26
+ Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
27
+ }
26
28
 
27
- PromiseTask.prototype = new BaseTask();
28
- PromiseTask.prototype.constructor = PromiseTask;
29
+ PromiseTask.prototype = new BaseTask();
30
+ PromiseTask.prototype.constructor = PromiseTask;
29
31
 
30
- PromiseTask.validate = function (taskDef) {
31
- var errors = [];
32
- if (!taskDef.f || !taskDef.a || !taskDef.out) {
33
- errors.push(format_error(REQ, taskDef));
34
- } else {
35
- var ftype = typeof(taskDef.f);
36
- if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
37
- errors.push(format_error(FN_REQ, taskDef));
32
+ PromiseTask.validate = function (taskDef) {
33
+ var errors = [];
34
+ if (!taskDef.f || !taskDef.a || !taskDef.out) {
35
+ errors.push(format_error(REQ, taskDef));
36
+ } else {
37
+ var ftype = typeof(taskDef.f);
38
+ if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
39
+ errors.push(format_error(FN_REQ, taskDef));
40
+ }
41
+ if (! (Array.isArray(taskDef.a) &&
42
+ taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
43
+ errors.push(format_error(A_REQ, taskDef));
44
+ }
45
+ if (! (Array.isArray(taskDef.out) && taskDef.out.length <= 1 &&
46
+ taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
47
+ errors.push(format_error(OUT_REQ, taskDef));
48
+ }
38
49
  }
39
- if (! (Array.isArray(taskDef.a) &&
40
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
41
- errors.push(format_error(A_REQ, taskDef));
42
- }
43
- if (! (Array.isArray(taskDef.out) && taskDef.out.length <= 1 &&
44
- taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
45
- errors.push(format_error(OUT_REQ, taskDef));
46
- }
47
- }
48
- return errors;
49
- };
50
+ return errors;
51
+ };
50
52
 
51
- PromiseTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
52
- var self = this;
53
- this.nextFn = function (arg) {
54
- var args = Array.prototype.slice.call(arguments);
55
- vCon.saveResults(self.out, args);
56
- self.complete(args);
57
- contExec();
53
+ PromiseTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
54
+ var self = this;
55
+ this.nextFn = function (arg) {
56
+ var args = Array.prototype.slice.call(arguments);
57
+ vCon.saveResults(self.out, args);
58
+ self.complete(args);
59
+ contExec();
60
+ };
61
+ this.failFn = function (err) {
62
+ handleTaskError(self, err);
63
+ };
58
64
  };
59
- this.failFn = function (err) {
60
- handleTaskError(self, err);
65
+
66
+ PromiseTask.prototype.exec = function exec(vCon, handleError, contExec) {
67
+ try {
68
+ var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
69
+ //console.error('PromiseTask.exec.args=', args);
70
+ //console.error('PromiseTask.exec.vCon=', vCon);
71
+ this.start(args); //note the start time, args
72
+ var func = this.f;
73
+ var bindObj = vCon.getVar('this'); //global space or the original this
74
+ if (this.isMethodCall()) { //if method call then reset func and bindObj
75
+ func = vCon.getVar(this.f);
76
+ bindObj = this.getMethodObj(vCon);
77
+ } else if (typeof(func) === 'string') {
78
+ func = vCon.getVar(func); // we want the actual fn from this string
79
+ }
80
+ var retValue = func.apply(bindObj, args);
81
+ if (retValue && typeof(retValue.then) === 'function') { // is a promise
82
+ retValue.then(this.nextFn, this.failFn);
83
+ } else { // just a value, proceed now
84
+ this.nextFn(retValue);
85
+ }
86
+ } catch (err) { //catch and handle the task error, calling final cb
87
+ handleError(this, err);
88
+ }
61
89
  };
62
- };
63
90
 
64
- PromiseTask.prototype.exec = function exec(vCon, handleError, contExec) {
65
- try {
66
- var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
67
- //console.error('PromiseTask.exec.args=', args);
68
- //console.error('PromiseTask.exec.vCon=', vCon);
69
- this.start(args); //note the start time, args
70
- var func = this.f;
71
- var bindObj = vCon.getVar('this'); //global space or the original this
72
- if (this.isMethodCall()) { //if method call then reset func and bindObj
73
- func = vCon.getVar(this.f);
74
- bindObj = this.getMethodObj(vCon);
75
- } else if (typeof(func) === 'string') {
76
- func = vCon.getVar(func); // we want the actual fn from this string
77
- }
78
- var retValue = func.apply(bindObj, args);
79
- if (retValue && typeof(retValue.then) === 'function') { // is a promise
80
- retValue.then(this.nextFn, this.failFn);
81
- } else { // just a value, proceed now
82
- this.nextFn(retValue);
83
- }
84
- } catch (err) { //catch and handle the task error, calling final cb
85
- handleError(this, err);
86
- }
87
- };
91
+ return PromiseTask;
88
92
 
89
- module.exports = PromiseTask;
93
+ });
package/lib/react.js ADDED
@@ -0,0 +1,59 @@
1
+ 'use strict';
2
+ /*global define:true */
3
+
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
7
+
8
+ define(['./core', './dsl', './track-tasks', './log-events', './promise-resolve', './event-collector'],
9
+ function (core, dsl, trackTasksFn, logEventsMod, resolvePromisesFn, eventCollectorFactory) {
10
+
11
+ var react = dsl; // core + default dsl
12
+
13
+ /**
14
+ Enable detection of promises and resolution
15
+ */
16
+ function resolvePromises() {
17
+ resolvePromisesFn(react);
18
+ }
19
+
20
+ /**
21
+ Enable tracking of tasks and flow execution, emitting events and
22
+ tracking start, end, elapsed time
23
+ */
24
+ function trackTasks() {
25
+ trackTasksFn(react);
26
+ }
27
+
28
+ /**
29
+ If called, load the built-in plugin for log events and invoke
30
+
31
+ @param flowFn [function] if not provided uses global react
32
+ @param eventWildcard [string] pattern to log events for
33
+ */
34
+ function logEvents(flowFn, eventWildcard) {
35
+ if (!eventWildcard && typeof(flowFn) === 'string') { // only wildcard provided
36
+ eventWildcard = flowFn;
37
+ flowFn = undefined;
38
+ }
39
+ if (!flowFn) flowFn = react; // use global
40
+ trackTasks();
41
+ return logEventsMod.logEvents(flowFn, eventWildcard);
42
+ }
43
+
44
+ /**
45
+ Instantiate an event collector
46
+ */
47
+ function createEventCollector() {
48
+ return eventCollectorFactory(react);
49
+ }
50
+
51
+ react.options = core.options; // global react options
52
+ react.events = core.events; // global react event emitter
53
+ react.logEvents = logEvents; // enable event logging
54
+ react.resolvePromises = resolvePromises; // enable promise resolution
55
+ react.trackTasks = trackTasks; // enable tracking of tasks
56
+ react.createEventCollector = createEventCollector; // create instance of EventCollector
57
+ return react;
58
+
59
+ });
package/lib/ret-task.js CHANGED
@@ -1,67 +1,71 @@
1
1
  'use strict';
2
+ /*global define:true */
2
3
 
3
- var util = require('util');
4
- var sprintf = require('sprintf').sprintf;
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
5
7
 
6
- var BaseTask = require('./base-task.js');
8
+ define(['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
9
+
10
+ function format_error(errmsg, obj) {
11
+ return sprintf('%s - %s', errmsg, util.inspect(obj));
12
+ }
7
13
 
8
- function format_error(errmsg, obj) {
9
- return sprintf('%s - %s', errmsg, util.inspect(obj));
10
- }
14
+ var REQ = 'retTask requires f, a, out';
15
+ var FN_REQ = 'retTask requires f to be a function or string';
16
+ var A_REQ = 'retTask requires a to be an array of string param names';
17
+ var RET_REQ = 'retTask requires out to be an array with single string param name or []';
11
18
 
12
- var REQ = 'retTask requires f, a, out';
13
- var FN_REQ = 'retTask requires f to be a function or string';
14
- var A_REQ = 'retTask requires a to be an array of string param names';
15
- var RET_REQ = 'retTask requires out to be an array with single string param name or []';
19
+ function RetTask(taskDef) {
20
+ var self = this;
21
+ Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
22
+ }
16
23
 
17
- function RetTask(taskDef) {
18
- var self = this;
19
- Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
20
- }
24
+ RetTask.prototype = new BaseTask();
25
+ RetTask.prototype.constructor = RetTask;
21
26
 
22
- RetTask.prototype = new BaseTask();
23
- RetTask.prototype.constructor = RetTask;
27
+ RetTask.validate = function (taskDef) {
28
+ var errors = [];
29
+ if (!taskDef.f || !taskDef.a || !taskDef.out) {
30
+ errors.push(format_error(REQ, taskDef));
31
+ } else {
32
+ var ftype = typeof(taskDef.f);
33
+ if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
34
+ errors.push(format_error(FN_REQ, taskDef));
35
+ }
36
+ if (! (Array.isArray(taskDef.a) &&
37
+ taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
38
+ errors.push(format_error(A_REQ, taskDef));
39
+ }
24
40
 
25
- RetTask.validate = function (taskDef) {
26
- var errors = [];
27
- if (!taskDef.f || !taskDef.a || !taskDef.out) {
28
- errors.push(format_error(REQ, taskDef));
29
- } else {
30
- var ftype = typeof(taskDef.f);
31
- if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
32
- errors.push(format_error(FN_REQ, taskDef));
33
- }
34
- if (! (Array.isArray(taskDef.a) &&
35
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
36
- errors.push(format_error(A_REQ, taskDef));
41
+ if (! (Array.isArray(taskDef.out) &&
42
+ (taskDef.out.length === 0 ||
43
+ (taskDef.out.length === 1 && typeof(taskDef.out[0] === 'string'))))) {
44
+ errors.push(format_error(RET_REQ, taskDef));
45
+ }
37
46
  }
47
+ return errors;
48
+ };
38
49
 
39
- if (! (Array.isArray(taskDef.out) &&
40
- (taskDef.out.length === 0 ||
41
- (taskDef.out.length === 1 && typeof(taskDef.out[0] === 'string'))))) {
42
- errors.push(format_error(RET_REQ, taskDef));
43
- }
44
- }
45
- return errors;
46
- };
50
+ RetTask.prototype.exec = function exec(vCon, handleError, contExec) {
51
+ try {
52
+ var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
53
+ this.start(args); //note the start time, args
54
+ var func = this.f;
55
+ var bindObj = vCon.getVar('this'); //global space or the original this
56
+ if (this.isMethodCall()) { //if method call then reset func and bindObj
57
+ func = vCon.getVar(this.f);
58
+ bindObj = this.getMethodObj(vCon);
59
+ } else if (typeof(func) === 'string') {
60
+ func = vCon.getVar(func); // we want the actual fn from this string
61
+ }
62
+ var results = [func.apply(bindObj, args)];
63
+ vCon.saveResults(this.out, results); // save retval, takes arrays
64
+ this.complete(results);
65
+ contExec(); // continue since no callback to run this
66
+ } catch (err) { handleError(this, err); } // catch and handle the task error, calling final cb
67
+ };
47
68
 
48
- RetTask.prototype.exec = function exec(vCon, handleError, contExec) {
49
- try {
50
- var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
51
- this.start(args); //note the start time, args
52
- var func = this.f;
53
- var bindObj = vCon.getVar('this'); //global space or the original this
54
- if (this.isMethodCall()) { //if method call then reset func and bindObj
55
- func = vCon.getVar(this.f);
56
- bindObj = this.getMethodObj(vCon);
57
- } else if (typeof(func) === 'string') {
58
- func = vCon.getVar(func); // we want the actual fn from this string
59
- }
60
- var results = [func.apply(bindObj, args)];
61
- vCon.saveResults(this.out, results); // save retval, takes arrays
62
- this.complete(results);
63
- contExec(); // continue since no callback to run this
64
- } catch (err) { handleError(this, err); } // catch and handle the task error, calling final cb
65
- };
69
+ return RetTask;
66
70
 
67
- module.exports = RetTask;
71
+ });
package/lib/sprintf.js ADDED
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+ /*global define:true sprint:true */
3
+
4
+ if (typeof define !== 'function') {
5
+ var define = require('amdefine')(module);
6
+ }
7
+
8
+ define(['util'], function (util) {
9
+
10
+ /**
11
+ Abstract the details of getting a sprintf function.
12
+ Currently using the simple format capabilities of node's util.format
13
+ */
14
+
15
+ var sprintf = util.format;
16
+ return sprintf;
17
+
18
+ });