react 0.6.0 → 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 (58) hide show
  1. package/.travis.yml +5 -2
  2. package/README.md +16 -2
  3. package/browser-test/dist.html +1 -1
  4. package/browser-test/index.html +3 -3
  5. package/browser-test/min.html +1 -1
  6. package/dist/react.js +407 -557
  7. package/dist/react.min.js +22 -1
  8. package/doc/advanced.md +9 -1
  9. package/lib/base-task.js +16 -19
  10. package/lib/cb-task.js +5 -5
  11. package/lib/core.js +7 -7
  12. package/lib/dsl.js +29 -29
  13. package/lib/error.js +4 -4
  14. package/lib/event-collector.js +6 -6
  15. package/lib/event-manager.js +13 -6
  16. package/lib/eventemitter.js +3 -3
  17. package/lib/finalcb-first-task.js +4 -4
  18. package/lib/finalcb-task.js +4 -4
  19. package/lib/id.js +3 -3
  20. package/lib/input-parser.js +10 -10
  21. package/lib/log-events.js +23 -14
  22. package/lib/parse.js +3 -3
  23. package/lib/promise-resolve.js +4 -4
  24. package/lib/promise-task.js +4 -4
  25. package/lib/react.js +7 -7
  26. package/lib/ret-task.js +4 -4
  27. package/lib/sprintf.js +8 -8
  28. package/lib/status.js +3 -3
  29. package/lib/task.js +44 -47
  30. package/lib/track-tasks.js +4 -4
  31. package/lib/validate.js +8 -8
  32. package/lib/vcon.js +31 -8
  33. package/lib/when-task.js +7 -8
  34. package/package.json +7 -8
  35. package/test/ast.mocha.js +4 -4
  36. package/test/cb-task.mocha.js +17 -17
  37. package/test/core-deferred.mocha.js +8 -8
  38. package/test/core-when.mocha.js +7 -7
  39. package/test/core.mocha.js +52 -52
  40. package/test/dsl.mocha.js +45 -43
  41. package/test/event-manager.mocha.js +2 -2
  42. package/test/exec-options.mocha.js +4 -4
  43. package/test/finalcb-task.mocha.js +6 -6
  44. package/test/input-parser.mocha.js +1 -1
  45. package/test/log-events.mocha.js +88 -0
  46. package/test/module-use.mocha.js +24 -7
  47. package/test/promise-auto-resolve.mocha.js +4 -4
  48. package/test/ret-task.mocha.js +18 -18
  49. package/test/task.mocha.js +3 -3
  50. package/test/validate-cb-task.mocha.js +11 -11
  51. package/test/validate-ret-task.mocha.js +14 -14
  52. package/test/validate.mocha.js +57 -57
  53. package/test/vcon.mocha.js +13 -13
  54. package/vendor/chai/chai.js +3371 -1158
  55. package/vendor/requirejs/require.js +1447 -1455
  56. package/vendor/requirejs/require.min.js +31 -28
  57. package/vendor/mocha/mocha.css +0 -135
  58. 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
 
@@ -80,7 +80,7 @@ if (typeof(sprintf) === 'undefined') {
80
80
  { f: falpha, a: [], out: ['c'], type: 'cb', name: 'falpha'}
81
81
  ]);
82
82
  t.deepEqual(r.ast.outTask, { a: ['c'], type: 'finalcb' });
83
- done();
83
+ done();
84
84
  });
85
85
 
86
86
  test('single task, err and out params', function (done) {
@@ -92,7 +92,7 @@ if (typeof(sprintf) === 'undefined') {
92
92
  { f: falpha, a: [], out: ['c'], type: 'cb', name: 'falpha'}
93
93
  ]);
94
94
  t.deepEqual(r.ast.outTask, { a: ['c'], type: 'finalcb' });
95
- done();
95
+ done();
96
96
  });
97
97
 
98
98
  test('using - with literal string', function (done) {
@@ -104,11 +104,11 @@ if (typeof(sprintf) === 'undefined') {
104
104
  { f: falpha, a: ['"another-string"'], out: ['c'], type: 'cb', name: 'falpha'}
105
105
  ]);
106
106
  t.deepEqual(r.ast.outTask, { a: ['c'], type: 'finalcb' });
107
- done();
107
+ done();
108
108
  });
109
109
 
110
110
  test('single task, ERR and out params', function (done) {
111
- var r = react('myName', 'cb -> ERR, c',
111
+ var r = react('myName', 'cb -> ERR, c',
112
112
  falpha, 'cb -> ERR, c'
113
113
  );
114
114
  t.deepEqual(r.ast.inParams, []);
@@ -116,11 +116,11 @@ if (typeof(sprintf) === 'undefined') {
116
116
  { f: falpha, a: [], out: ['c'], type: 'cb', name: 'falpha'}
117
117
  ]);
118
118
  t.deepEqual(r.ast.outTask, { a: ['c'], type: 'finalcb' });
119
- done();
119
+ done();
120
120
  });
121
121
 
122
122
  test('cb used in defs is simply ignored', function (done) {
123
- var r = react('myName', 'a, b, cb -> err, c',
123
+ var r = react('myName', 'a, b, cb -> err, c',
124
124
  falpha, 'a, b, cb -> err, c'
125
125
  );
126
126
  t.deepEqual(r.ast.inParams, ['a', 'b']);
@@ -128,7 +128,7 @@ if (typeof(sprintf) === 'undefined') {
128
128
  { f: falpha, a: ['a', 'b'], out: ['c'], type: 'cb', name: 'falpha'}
129
129
  ]);
130
130
  t.deepEqual(r.ast.outTask, { a: ['c'], type: 'finalcb' });
131
- done();
131
+ done();
132
132
  });
133
133
 
134
134
  test('callback used in defs is simply ignored', function (done) {
@@ -140,7 +140,7 @@ if (typeof(sprintf) === 'undefined') {
140
140
  { f: falpha, a: ['a', 'b'], out: ['c'], type: 'cb', name: 'falpha'}
141
141
  ]);
142
142
  t.deepEqual(r.ast.outTask, { a: ['c'], type: 'finalcb' });
143
- done();
143
+ done();
144
144
  });
145
145
 
146
146
  test('two inputs, two tasks, two out params', function (done) {
@@ -154,7 +154,7 @@ if (typeof(sprintf) === 'undefined') {
154
154
  { f: fbeta, a: ['a', 'b'], out: ['d', 'e'], type: 'cb', name: 'fbeta'}
155
155
  ]);
156
156
  t.deepEqual(r.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
157
- done();
157
+ done();
158
158
  });
159
159
 
160
160
  test('two inputs, two tasks, two out params, options', function (done) {
@@ -171,7 +171,7 @@ if (typeof(sprintf) === 'undefined') {
171
171
  t.deepEqual(r.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
172
172
  t.equal(r.ast.name, 'myName', 'name should match');
173
173
  t.equal(r.ast.otherOptFoo, 'foo', 'other options should pass through');
174
- done();
174
+ done();
175
175
  });
176
176
 
177
177
  test('two inputs, two mixed tasks, two out params', function (done) {
@@ -185,12 +185,12 @@ if (typeof(sprintf) === 'undefined') {
185
185
  { f: fbeta, a: ['a', 'b'], out: ['d'], type: 'ret', name: 'fbeta'}
186
186
  ]);
187
187
  t.deepEqual(r.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
188
- done();
188
+ done();
189
189
  });
190
190
 
191
191
 
192
192
  test('two inputs, two mixed tasks, two out params, opts', function (done) {
193
- var r = react('myName', 'a, b, cb -> err, c, d',
193
+ var r = react('myName', 'a, b, cb -> err, c, d',
194
194
  falpha, 'a, cb -> err, c', { after: fbeta },
195
195
  fbeta, 'a, b -> d'
196
196
  );
@@ -200,13 +200,13 @@ if (typeof(sprintf) === 'undefined') {
200
200
  { f: fbeta, a: ['a', 'b'], out: ['d'], type: 'ret', name: 'fbeta'}
201
201
  ]);
202
202
  t.deepEqual(r.ast.outTask, { a: ['c', 'd'], type: 'finalcb' });
203
- done();
203
+ done();
204
204
  });
205
205
 
206
206
 
207
207
  // Object use
208
208
  test('object prop task params', function (done) {
209
- var r = react('myName', 'a, b, cb -> err, c, e',
209
+ var r = react('myName', 'a, b, cb -> err, c, e',
210
210
  falpha, 'a, b.cat, cb -> err, c',
211
211
  fbeta, 'c.dog, b -> d',
212
212
  'd.egg', 'c, cb -> err, e'
@@ -218,7 +218,7 @@ if (typeof(sprintf) === 'undefined') {
218
218
  { f: 'd.egg', a: ['c'], out: ['e'], type: 'cb', name: 'd.egg'}
219
219
  ]);
220
220
  t.deepEqual(r.ast.outTask, { a: ['c', 'e'], type: 'finalcb' });
221
- done();
221
+ done();
222
222
  });
223
223
 
224
224
  // Errors
@@ -229,7 +229,7 @@ if (typeof(sprintf) === 'undefined') {
229
229
  falpha, 'cb -> err, c'
230
230
  );
231
231
  };
232
- t.throws(fn, new Error('first flow parameter should be the flow name, but found in/out def: cb -> err, c'));
232
+ t.throws(fn, 'first flow parameter should be the flow name, but found in/out def: cb -> err, c');
233
233
  done();
234
234
  });
235
235
 
@@ -239,7 +239,7 @@ if (typeof(sprintf) === 'undefined') {
239
239
  falpha, 'cb -> err, c'
240
240
  );
241
241
  };
242
- t.throws(fn, new Error('callback specified, but first out param was not "err", use for clarity. Found in/out def: cb -> c'));
242
+ t.throws(fn, 'callback specified, but first out param was not "err", use for clarity. Found in/out def: cb -> c');
243
243
  done();
244
244
  });
245
245
 
@@ -249,7 +249,7 @@ if (typeof(sprintf) === 'undefined') {
249
249
  falpha, 'cb -> c' // missing err
250
250
  );
251
251
  };
252
- t.throws(fn, new Error('callback specified, but first out param was not "err", use for clarity. Found in/out def: cb -> c'));
252
+ t.throws(fn, 'callback specified, but first out param was not "err", use for clarity. Found in/out def: cb -> c');
253
253
  done();
254
254
  });
255
255
 
@@ -259,7 +259,7 @@ if (typeof(sprintf) === 'undefined') {
259
259
  falpha, 'cb -> err, c'
260
260
  );
261
261
  };
262
- t.throws(fn, new Error('found err param, but cb/callback is not specified, is this cb-style async or sync function? Found in/out def: a -> err, c'));
262
+ t.throws(fn, 'found err param, but cb/callback is not specified, is this cb-style async or sync function? Found in/out def: a -> err, c');
263
263
  done();
264
264
  });
265
265
 
@@ -269,36 +269,36 @@ if (typeof(sprintf) === 'undefined') {
269
269
  falpha, 'a -> err, c' // missing cb
270
270
  );
271
271
  };
272
- t.throws(fn, new Error('found err param, but cb/callback is not specified, is this cb-style async or sync function? Found in/out def: a -> err, c'));
272
+ t.throws(fn, 'found err param, but cb/callback is not specified, is this cb-style async or sync function? Found in/out def: a -> err, c');
273
273
  done();
274
274
  });
275
275
 
276
276
  test('extra arg throws error', function (done) {
277
277
  var fn = function () {
278
- var r = react('myName', 'a, b, cb -> err, c, d',
278
+ var r = react('myName', 'a, b, cb -> err, c, d',
279
279
  falpha, 'a, cb -> err, c', { after: fbeta },
280
280
  fbeta, 'a, b -> returns d',
281
281
  'extraBadArg'
282
282
  );
283
283
  };
284
- t.throws(fn, new Error('extra unmatched task arg: extraBadArg'));
285
- done();
284
+ t.throws(fn, 'extra unmatched task arg: extraBadArg');
285
+ done();
286
286
  });
287
287
 
288
288
  test('not enough args throws error', function (done) {
289
289
  var fn = function () {
290
- var r = react('myName', 'a, b, cb -> err, c, d',
290
+ var r = react('myName', 'a, b, cb -> err, c, d',
291
291
  falpha, 'a, cb -> err, c', { after: fbeta },
292
292
  fbeta
293
293
  );
294
294
  };
295
- t.throws(fn, new Error(sprintf('extra unmatched task arg: %s', fbeta)));
296
- done();
295
+ t.throws(fn, sprintf('extra unmatched task arg: %s', fbeta));
296
+ done();
297
297
  });
298
298
 
299
299
  test('long example', function (done) {
300
300
  /*jshint white: false */
301
-
301
+
302
302
  function loadUser(uid, cb){ setTimeout(cb, 100, null, "User"+uid); }
303
303
  function loadFile(filename, cb){ setTimeout(cb, 100, null, 'Filedata'+filename); }
304
304
  function markdown(filedata) { return 'html'+filedata; }
@@ -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');
@@ -327,11 +329,11 @@ if (typeof(sprintf) === 'undefined') {
327
329
  });
328
330
  });
329
331
 
330
- // selectFirst
332
+ // selectFirst
331
333
 
332
334
  test('selectFirst', function (done) {
333
335
  var r = react.selectFirst('myName', 'a, b, cb -> err, c',
334
- { otherOptFoo: 'foo'}, // main options
336
+ { otherOptFoo: 'foo'}, // main options
335
337
  falpha, 'a, b, cb -> err, c',
336
338
  fbeta, 'a, b -> c'
337
339
  );
@@ -344,7 +346,7 @@ if (typeof(sprintf) === 'undefined') {
344
346
  t.deepEqual(r.ast.outTask, { type: 'finalcbFirst', a: ['c'] });
345
347
  t.equal(r.ast.name, 'myName', 'name should match if supplied');
346
348
  t.equal(r.ast.otherOptFoo, 'foo', 'other options should pass through');
347
- done();
349
+ done();
348
350
  });
349
351
 
350
- }());
352
+ }());
@@ -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') {
@@ -10,10 +9,11 @@ if (typeof(react) === 'undefined') {
10
9
  }
11
10
 
12
11
  if (typeof(taskUtil) === 'undefined') {
13
- var taskUtil = require('../lib/task.js');
12
+ var taskUtil = require('../lib/task.js');
14
13
  }
15
14
 
16
15
  (function () {
16
+ 'use strict';
17
17
 
18
18
  var t = chai.assert;
19
19
 
@@ -27,7 +27,7 @@ if (typeof(taskUtil) === 'undefined') {
27
27
  var fn = function () {
28
28
  var finalTask = taskUtil.createOutTask({}, undefined);
29
29
  };
30
- t.throws(fn, new Error('callback is not a function'));
30
+ t.throws(fn, 'callback is not a function');
31
31
  done();
32
32
  });
33
33
 
@@ -35,7 +35,7 @@ if (typeof(taskUtil) === 'undefined') {
35
35
  var fn = function () {
36
36
  var finalTask = taskUtil.createOutTask({}, null);
37
37
  };
38
- t.throws(fn, new Error('callback is not a function'));
38
+ t.throws(fn, 'callback is not a function');
39
39
  done();
40
40
  });
41
41
 
@@ -43,7 +43,7 @@ if (typeof(taskUtil) === 'undefined') {
43
43
  var fn = function () {
44
44
  var finalTask = taskUtil.createOutTask({}, 'foo');
45
45
  };
46
- t.throws(fn, new Error('callback is not a function'));
46
+ t.throws(fn, 'callback is not a function');
47
47
  done();
48
48
  });
49
49
 
@@ -55,4 +55,4 @@ if (typeof(taskUtil) === 'undefined') {
55
55
  done();
56
56
  });
57
57
 
58
- }());
58
+ }());
@@ -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
 
@@ -0,0 +1,88 @@
1
+ /*global react:true BaseTask:true */
2
+
3
+ if (typeof(chai) === 'undefined') {
4
+ var chai = require('chai');
5
+ }
6
+
7
+ if (typeof(react) === 'undefined') {
8
+ var react = require('../'); //require('react');
9
+ }
10
+
11
+ (function () {
12
+ 'use strict';
13
+
14
+ var t = chai.assert;
15
+
16
+ /**
17
+ Testing turning on logging of events
18
+ */
19
+
20
+ suite('log-events');
21
+
22
+ /**
23
+ @example
24
+ var react = require('react');
25
+ react.logEvents(); // log to console
26
+ */
27
+
28
+ before(function () {
29
+ react.logEvents();
30
+ });
31
+
32
+ after(function () {
33
+ react.logEvents(false);
34
+ });
35
+
36
+ test('use react() default DSL from module', function (done) {
37
+ function multiply(a, b, cb) { cb(null, a * b); }
38
+ function add(a, b, cb) { cb(null, a + b); }
39
+ var fn = react('multiplyAdd', 'a, b, cb -> err, m, s',
40
+ multiply, 'a, b, cb -> err, m',
41
+ add, 'm, a, cb -> err, s'
42
+ );
43
+
44
+
45
+ fn(2, 3, function (err, m, s) {
46
+ t.deepEqual(err, null, 'should not be any error');
47
+ t.equal(m, 6);
48
+ t.equal(s, 8);
49
+ done();
50
+ });
51
+ });
52
+
53
+ test('use react.selectFirst() default DSL with events', function (done) {
54
+ function noSuccess(a, b, cb) {
55
+ setTimeout(function () { cb(null); }, 100); // returns undefined result
56
+ }
57
+ function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
58
+ function add(a, b, cb) { cb(null, a + b); }
59
+
60
+
61
+ var fn = react.selectFirst('mySelectFirst', 'a, b, cb -> err, c',
62
+ noSuccess, 'a, b, cb -> err, c',
63
+ noSuccessNull, 'a, b, cb -> err, c',
64
+ add, 'a, b, cb -> err, c',
65
+ noSuccess, 'a, b, cb -> err, c'
66
+ );
67
+
68
+ var collector = react.createEventCollector();
69
+ collector.capture(fn, 'task.complete');
70
+
71
+ fn(2, 3, function (err, c) {
72
+ t.deepEqual(err, null, 'should not be any error');
73
+ t.equal(c, 5);
74
+ var events = collector.list();
75
+ t.equal(events.length, 3, 'should have seen two task compl events');
76
+ t.equal(events[0].task.name, 'noSuccess', 'name matches');
77
+ t.equal(events[1].task.name, 'noSuccessNull', 'name matches');
78
+ t.equal(events[2].task.name, 'add', 'name matches');
79
+ t.deepEqual(events[2].task.results, [5], 'results match');
80
+ done();
81
+ });
82
+ });
83
+
84
+ }());
85
+
86
+
87
+
88
+