react 0.6.3 → 0.7.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.
Files changed (55) hide show
  1. package/.travis.yml +5 -3
  2. package/README.md +10 -1
  3. package/dist/react.js +179 -145
  4. package/dist/react.min.js +1 -1
  5. package/doc/advanced.md +1 -1
  6. package/lib/base-task.js +16 -19
  7. package/lib/cb-task.js +5 -5
  8. package/lib/core.js +5 -5
  9. package/lib/dsl.js +29 -29
  10. package/lib/error.js +4 -4
  11. package/lib/event-collector.js +6 -6
  12. package/lib/event-manager.js +1 -1
  13. package/lib/eventemitter.js +3 -3
  14. package/lib/finalcb-first-task.js +4 -4
  15. package/lib/finalcb-task.js +4 -4
  16. package/lib/id.js +3 -3
  17. package/lib/input-parser.js +10 -10
  18. package/lib/log-events.js +1 -1
  19. package/lib/parse.js +3 -3
  20. package/lib/promise-resolve.js +4 -4
  21. package/lib/promise-task.js +4 -4
  22. package/lib/react.js +1 -1
  23. package/lib/ret-task.js +4 -4
  24. package/lib/sprintf.js +4 -4
  25. package/lib/status.js +3 -3
  26. package/lib/task.js +12 -12
  27. package/lib/track-tasks.js +4 -4
  28. package/lib/validate.js +8 -8
  29. package/lib/vcon.js +28 -5
  30. package/lib/when-task.js +7 -8
  31. package/package.json +7 -7
  32. package/test/ast.mocha.js +4 -4
  33. package/test/cb-task.mocha.js +17 -17
  34. package/test/core-deferred.mocha.js +8 -8
  35. package/test/core-when.mocha.js +7 -7
  36. package/test/core.mocha.js +52 -52
  37. package/test/dsl.mocha.js +14 -12
  38. package/test/event-manager.mocha.js +2 -2
  39. package/test/exec-options.mocha.js +4 -4
  40. package/test/finalcb-task.mocha.js +1 -1
  41. package/test/input-parser.mocha.js +1 -1
  42. package/test/log-events.mocha.js +1 -1
  43. package/test/module-use.mocha.js +24 -7
  44. package/test/promise-auto-resolve.mocha.js +4 -4
  45. package/test/ret-task.mocha.js +18 -18
  46. package/test/task.mocha.js +3 -3
  47. package/test/validate-cb-task.mocha.js +11 -11
  48. package/test/validate-ret-task.mocha.js +14 -14
  49. package/test/validate.mocha.js +57 -57
  50. package/test/vcon.mocha.js +13 -13
  51. package/vendor/chai/chai.js +3371 -1158
  52. package/vendor/requirejs/require.js +1447 -1455
  53. package/vendor/requirejs/require.min.js +31 -28
  54. package/vendor/mocha/mocha.css +0 -135
  55. package/vendor/mocha/mocha.js +0 -3589
package/test/dsl.mocha.js CHANGED
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true sprintf:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(sprintf) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -307,17 +307,19 @@ if (typeof(sprintf) === 'undefined') {
307
307
  function loadEmailTemplate(cb) { setTimeout(cb, 50, null, 'emailmd'); }
308
308
  function customizeEmail(user, emailHtml) { return 'cust-'+user+emailHtml; }
309
309
  function deliverEmail(custEmailHtml, cb) { setTimeout(cb, 100, null, 'delivered-'+custEmailHtml); }
310
- var loadAndSave = react('loadAndSave', 'filename, uid, outDirname, cb -> err, html, user, bytesWritten', // name, in/out params
311
- loadUser, 'uid, cb -> err, user', // calling async fn loadUser with uid, callback is called with err and user
312
- loadFile, 'filename, cb -> err, filedata',
313
- markdown, 'filedata -> html', // using a sync function
314
- prepareDirectory, 'outDirname, cb -> err, dircreated',
315
- writeOutput, 'html, user, cb -> err, bytesWritten', { after: prepareDirectory }, // only after prepareDirectory done
316
- loadEmailTemplate, 'cb -> err, emailmd',
317
- markdown, 'emailmd -> emailHtml', // using a sync function
318
- customizeEmail, 'user, emailHtml -> custEmailHtml',
319
- deliverEmail, 'custEmailHtml, cb -> err, deliveredEmail', { after: writeOutput } // only after writeOutput is done
320
- );
310
+ var loadAndSave = react(
311
+ 'loadAndSave', 'filename, uid, outDirname, cb -> err, html, user, bytesWritten', // name, in/out params
312
+ loadUser, 'uid, cb -> err, user', // calling async fn loadUser with uid, cb is called w/ err & user
313
+ loadFile, 'filename, cb -> err, filedata',
314
+ markdown, 'filedata -> html', // using a sync function
315
+ prepareDirectory, 'outDirname, cb -> err, dircreated',
316
+ writeOutput, 'html, user, cb -> err, bytesWritten', { after: prepareDirectory }, // after prepareDirectory done
317
+ loadEmailTemplate, 'cb -> err, emailmd',
318
+ markdown, 'emailmd -> emailHtml', // using a sync function
319
+ customizeEmail, 'user, emailHtml -> custEmailHtml',
320
+ deliverEmail, 'custEmailHtml, cb -> err, deliveredEmail', { after: writeOutput } // only after writeOutput is done
321
+ );
322
+
321
323
  loadAndSave('file.md', 100, '/tmp/foo', function (err, html, user, bytesWritten) { // executing the flow
322
324
  t.equal(err, null);
323
325
  t.equal(html, 'htmlFiledatafile.md');
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true EventManager:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(EventManager) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -116,4 +116,4 @@ if (typeof(EventManager) === 'undefined') {
116
116
  em.emit('bar', 'hello');
117
117
  });
118
118
 
119
- }());
119
+ }());
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -10,6 +9,7 @@ if (typeof(react) === 'undefined') {
10
9
  }
11
10
 
12
11
  (function () {
12
+ 'use strict';
13
13
 
14
14
  var t = chai.assert;
15
15
 
@@ -25,7 +25,7 @@ if (typeof(react) === 'undefined') {
25
25
  var fn = react();
26
26
  var errors = fn.setAndValidateAST({
27
27
  inParams: ['a', 'b'],
28
- tasks: [
28
+ tasks: [
29
29
  { f: multiply, a: ['a', 'b'], out: ['c'] }
30
30
  ],
31
31
  outTask: { a: ['c'] }
@@ -36,13 +36,13 @@ if (typeof(react) === 'undefined') {
36
36
  reactExecOptions: true,
37
37
  outputStyle: 'cb'
38
38
  };
39
-
39
+
40
40
  fn(execOptions, 2, 3, function (err, c) {
41
41
  t.equal(err, null);
42
42
  t.equal(c, 6);
43
43
  done();
44
44
  });
45
- });
45
+ });
46
46
 
47
47
 
48
48
  }());
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true taskUtil:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(taskUtil) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true inputParser:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(inputParser) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true BaseTask:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -10,6 +9,7 @@ if (typeof(react) === 'undefined') {
10
9
  }
11
10
 
12
11
  (function () {
12
+ 'use strict';
13
13
 
14
14
  var t = chai.assert;
15
15
 
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true BaseTask:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(BaseTask) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -36,7 +36,7 @@ if (typeof(BaseTask) === 'undefined') {
36
36
  bum, 'dog, cb -> err, result2');
37
37
 
38
38
  // OR using AST
39
-
39
+
40
40
  var loadAndSave = react();
41
41
  loadAndSave.setAndValidateAST({
42
42
  inParams: ['one', 'two'],
@@ -88,7 +88,7 @@ if (typeof(BaseTask) === 'undefined') {
88
88
  { f: foo, a: ['a'], out: ['c'], type: 'cb', name: 'foo' },
89
89
  { f: bar, a: ['b'], out: ['d'], type: 'cb', name: 'bar' }
90
90
  ]);
91
- t.deepEqual(r.ast.outTask, { a: ['c', 'd'], type: 'finalcb' }, 'should return obj just set');
91
+ t.deepEqual(r.ast.outTask, { a: ['c', 'd'], type: 'finalcb' }, 'should return obj just set');
92
92
  done();
93
93
  });
94
94
 
@@ -100,7 +100,7 @@ if (typeof(BaseTask) === 'undefined') {
100
100
  add, 'm, a, cb -> err, s'
101
101
  );
102
102
 
103
-
103
+
104
104
  fn(2, 3, function (err, m, s) {
105
105
  t.deepEqual(err, null, 'should not be any error');
106
106
  t.equal(m, 6);
@@ -116,17 +116,17 @@ if (typeof(BaseTask) === 'undefined') {
116
116
  function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
117
117
  function add(a, b, cb) { cb(null, a + b); }
118
118
 
119
-
119
+
120
120
  var fn = react.selectFirst('mySelectFirst', 'a, b, cb -> err, c',
121
121
  noSuccess, 'a, b, cb -> err, c',
122
122
  noSuccessNull, 'a, b, cb -> err, c',
123
123
  add, 'a, b, cb -> err, c',
124
- noSuccess, 'a, b, cb -> err, c'
124
+ noSuccess, 'a, b, cb -> err, c'
125
125
  );
126
126
 
127
127
  var collector = react.createEventCollector();
128
128
  collector.capture(fn, 'task.complete');
129
-
129
+
130
130
  fn(2, 3, function (err, c) {
131
131
  t.deepEqual(err, null, 'should not be any error');
132
132
  t.equal(c, 5);
@@ -140,6 +140,23 @@ if (typeof(BaseTask) === 'undefined') {
140
140
  });
141
141
  });
142
142
 
143
+ test('reference local/global vars', function (done) {
144
+ function foo(cb) {
145
+ cb(null, 100);
146
+ }
147
+
148
+ var fn = react('refGlobal', 'cb -> err, result',
149
+ 'console.log', '"using global/local ref to console" ->',
150
+ foo, 'cb -> err, result', { after: 'console.log' }
151
+ );
152
+
153
+ fn(function (err, result) {
154
+ if (err) return done(err);
155
+ t.equal(result, 100);
156
+ done();
157
+ });
158
+ });
159
+
143
160
  }());
144
161
 
145
162
 
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true Deferred:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(Deferred) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -34,7 +34,7 @@ if (typeof(Deferred) === 'undefined') {
34
34
  var fn = react();
35
35
  var errors = fn.setAndValidateAST({
36
36
  inParams: ['a', 'b'],
37
- tasks: [
37
+ tasks: [
38
38
  { f: multiply, a: ['a', 'b'], out: ['c'] },
39
39
  { f: add, a: ['c', 'b'], out: ['d'] }
40
40
  ],
@@ -51,7 +51,7 @@ if (typeof(Deferred) === 'undefined') {
51
51
  function retBP() {
52
52
  var deferred = new Deferred();
53
53
  setTimeout(function () { deferred.resolve(3); }, 10);
54
- return deferred.promise();
54
+ return deferred.promise();
55
55
  }
56
56
 
57
57
  var ap = retAP();
@@ -65,4 +65,4 @@ if (typeof(Deferred) === 'undefined') {
65
65
  });
66
66
  });
67
67
 
68
- }());
68
+ }());
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true RetTask:true VContext:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -18,6 +17,7 @@ if (typeof(VContext) === 'undefined') {
18
17
  }
19
18
 
20
19
  (function () {
20
+ 'use strict';
21
21
 
22
22
  var t = chai.assert;
23
23
 
@@ -66,7 +66,7 @@ if (typeof(VContext) === 'undefined') {
66
66
  t.equal(task.isReady(vCon, tasksByName), false);
67
67
  task.status = null;
68
68
  t.equal(task.isReady(vCon, tasksByName), true);
69
- done();
69
+ done();
70
70
  });
71
71
 
72
72
  test('no args defined, no after -> not ready', function (done) {
@@ -82,39 +82,39 @@ if (typeof(VContext) === 'undefined') {
82
82
  var vCon = VContext.create([1, {}], ['b', 'c']);
83
83
  var tasksByName = { foo: task };
84
84
  t.equal(task.isReady(vCon, tasksByName), false);
85
- done();
85
+ done();
86
86
  });
87
87
 
88
88
  test('all args defined, no after, out no obj parent -> NOT ready', function (done) {
89
89
  var task = new RetTask({ type: 'ret', f: foo, a: ['b', 'c'], out: ['d.e'] });
90
90
  var vCon = VContext.create([1, null], ['b', 'c']);
91
91
  var tasksByName = { foo: task };
92
- t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent undef');
93
- done();
92
+ t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent undef');
93
+ done();
94
94
  });
95
95
 
96
96
  test('all args defined, no after, out no obj.par.par -> NOT ready', function (done) {
97
97
  var task = new RetTask({ type: 'ret', f: foo, a: ['b', 'c'], out: ['c.e.f'] });
98
98
  var vCon = VContext.create([1, { }], ['b', 'c']);
99
99
  var tasksByName = { foo: task };
100
- t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent undef');
101
- done();
100
+ t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent undef');
101
+ done();
102
102
  });
103
103
 
104
104
  test('all args defined, no after, out null obj parent -> NOT ready', function (done) {
105
105
  var task = new RetTask({ type: 'ret', f: foo, a: ['b', 'c'], out: ['c.e'] });
106
106
  var vCon = VContext.create([1, null], ['b', 'c']);
107
107
  var tasksByName = { foo: task };
108
- t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent null');
109
- done();
108
+ t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent null');
109
+ done();
110
110
  });
111
111
 
112
112
  test('all args defined, no after, out null obj.par.par -> NOT ready', function (done) {
113
113
  var task = new RetTask({ type: 'ret', f: foo, a: ['b', 'c'], out: ['c.e.f'] });
114
114
  var vCon = VContext.create([1, { e: null }], ['b', 'c']);
115
115
  var tasksByName = { foo: task };
116
- t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent null');
117
- done();
116
+ t.equal(task.isReady(vCon, tasksByName), false, 'false if out objparent null');
117
+ done();
118
118
  });
119
119
 
120
120
  test('all args defined, no after -> ready', function (done) {
@@ -122,7 +122,7 @@ if (typeof(VContext) === 'undefined') {
122
122
  var vCon = VContext.create([1, null], ['b', 'c']);
123
123
  var tasksByName = { foo: task };
124
124
  t.equal(task.isReady(vCon, tasksByName), true);
125
- done();
125
+ done();
126
126
  });
127
127
 
128
128
  test('all args defined, obj prop null, no after -> ready', function (done) {
@@ -130,7 +130,7 @@ if (typeof(VContext) === 'undefined') {
130
130
  var vCon = VContext.create([1, { prop: null }], ['b', 'c']);
131
131
  var tasksByName = { foo: task };
132
132
  t.equal(task.isReady(vCon, tasksByName), true);
133
- done();
133
+ done();
134
134
  });
135
135
 
136
136
  test('all args defined, after not complete -> NOT ready', function (done) {
@@ -140,8 +140,8 @@ if (typeof(VContext) === 'undefined') {
140
140
  { type: 'ret', f: foo, a: ['b', 'c'], out: [], after: ['cat', 'bar']});
141
141
  var vCon = VContext.create([1, 2], ['b', 'c']);
142
142
  var tasksByName = { foo: task, bar: tbar, cat: tcat };
143
- t.equal(task.isReady(vCon, tasksByName), false);
144
- done();
143
+ t.equal(task.isReady(vCon, tasksByName), false);
144
+ done();
145
145
  });
146
146
 
147
147
  test('all args defined, after all complete -> ready', function (done) {
@@ -151,8 +151,8 @@ if (typeof(VContext) === 'undefined') {
151
151
  { type: 'ret', f: foo, a: ['b', 'c'], out: [], after: ['cat', 'bar']});
152
152
  var vCon = VContext.create([1, 2], ['b', 'c']);
153
153
  var tasksByName = { foo: task, bar: tbar, cat: tcat };
154
- t.equal(task.isReady(vCon, tasksByName), true);
155
- done();
154
+ t.equal(task.isReady(vCon, tasksByName), true);
155
+ done();
156
156
  });
157
157
 
158
158
  test('string without . is not method call', function (done) {
@@ -217,4 +217,4 @@ if (typeof(VContext) === 'undefined') {
217
217
  done();
218
218
  });
219
219
 
220
- }());
220
+ }());
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true taskUtil:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -14,6 +13,7 @@ if (typeof(taskUtil) === 'undefined') {
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -28,7 +28,7 @@ if (typeof(taskUtil) === 'undefined') {
28
28
 
29
29
  test('missing types are guessed from params', function (done) {
30
30
  var ast = {
31
- inParams: ['a'],
31
+ inParams: ['a'],
32
32
  tasks: [
33
33
  { f: foo, a: ['a'], out: ['baz'] },
34
34
  ],
@@ -39,4 +39,4 @@ if (typeof(taskUtil) === 'undefined') {
39
39
  done();
40
40
  });
41
41
 
42
- }());
42
+ }());
@@ -1,4 +1,3 @@
1
- 'use strict';
2
1
  /*global react:true util:true sprintf:true validate:true */
3
2
 
4
3
  if (typeof(chai) === 'undefined') {
@@ -22,6 +21,7 @@ if (typeof(validate) === 'undefined') {
22
21
  }
23
22
 
24
23
  (function () {
24
+ 'use strict';
25
25
 
26
26
  var t = chai.assert;
27
27
 
@@ -36,19 +36,19 @@ if (typeof(validate) === 'undefined') {
36
36
 
37
37
  test('cbTask requires f, a, out', function (done) {
38
38
  var ast = {
39
- inParams: ['a'],
39
+ inParams: ['a'],
40
40
  tasks: [{ type: 'cb' }],
41
41
  outTask: { a: ['bar'] }
42
42
  };
43
43
  var msg = sprintf('cbTask requires f, a, out - %s',
44
44
  util.inspect(ast.tasks[0]));
45
- t.deepEqual(validate(ast), [msg]);
45
+ t.deepEqual(validate(ast), [msg]);
46
46
  done();
47
47
  });
48
-
48
+
49
49
  test('cbTask verifies f type', function (done) {
50
50
  var ast = {
51
- inParams: ['a'],
51
+ inParams: ['a'],
52
52
  tasks: [{ type: 'cb', f: foo, a: [], out: [] }],
53
53
  outTask: { a: ['bar'] }
54
54
  };
@@ -61,39 +61,39 @@ if (typeof(validate) === 'undefined') {
61
61
 
62
62
  test('cbTask verifies a type', function (done) {
63
63
  var ast = {
64
- inParams: ['a'],
64
+ inParams: ['a'],
65
65
  tasks: [{ type: 'cb', f: foo, a: [], out: [] }],
66
66
  outTask: { a: ['bar'] }
67
67
  };
68
68
  ast.tasks[0].a = 'foo'; //err should be arr of strings
69
69
  var msg = sprintf('cbTask requires a to be an array of string param names - %s',
70
70
  util.inspect(ast.tasks[0]));
71
- t.deepEqual(validate(ast), [msg]);
71
+ t.deepEqual(validate(ast), [msg]);
72
72
 
73
73
  ast = Object.create(ast);
74
74
  ast.tasks[0].a = ['foo', 1]; //err should be arr of strings
75
75
  msg = sprintf('cbTask requires a to be an array of string param names - %s',
76
76
  util.inspect(ast.tasks[0]));
77
- t.deepEqual(validate(ast), [msg]);
77
+ t.deepEqual(validate(ast), [msg]);
78
78
  done();
79
79
  });
80
80
 
81
81
  test('cbTask verifies out type', function (done) {
82
82
  var ast = {
83
- inParams: ['a'],
83
+ inParams: ['a'],
84
84
  tasks: [{ type: 'cb', f: foo, a: [], out: [] }],
85
85
  outTask: { a: ['bar'] }
86
86
  };
87
87
  ast.tasks[0].out = 'foo'; //err should be arr of strings
88
88
  var msg = sprintf('cbTask requires out to be an array of string param names - %s',
89
89
  util.inspect(ast.tasks[0]));
90
- t.deepEqual(validate(ast), [msg]);
90
+ t.deepEqual(validate(ast), [msg]);
91
91
 
92
92
  ast = Object.create(ast);
93
93
  ast.tasks[0].out = ['foo', 1]; //err should be arr of strings
94
94
  msg = sprintf('cbTask requires out to be an array of string param names - %s',
95
95
  util.inspect(ast.tasks[0]));
96
- t.deepEqual(validate(ast), [msg]);
96
+ t.deepEqual(validate(ast), [msg]);
97
97
  done();
98
98
  });
99
99