react 0.6.3 → 0.9.0-rc1

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 (218) hide show
  1. package/README.md +10 -222
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +30 -0
  4. package/lib/CSSCore.js +115 -0
  5. package/lib/CSSProperty.js +121 -0
  6. package/lib/CSSPropertyOperations.js +97 -0
  7. package/lib/ChangeEventPlugin.js +387 -0
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +260 -0
  10. package/lib/DOMChildrenOperations.js +165 -0
  11. package/lib/DOMProperty.js +268 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +197 -0
  15. package/lib/DefaultEventPluginOrder.js +44 -0
  16. package/lib/EnterLeaveEventPlugin.js +145 -0
  17. package/lib/EventConstants.js +76 -0
  18. package/lib/EventListener.js +69 -0
  19. package/lib/EventPluginHub.js +291 -0
  20. package/lib/EventPluginRegistry.js +260 -0
  21. package/lib/EventPluginUtils.js +214 -0
  22. package/lib/EventPropagators.js +143 -0
  23. package/lib/ExecutionEnvironment.js +44 -0
  24. package/lib/LinkedStateMixin.js +46 -0
  25. package/lib/LinkedValueUtils.js +161 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +95 -0
  29. package/lib/ReactCSSTransitionGroup.js +65 -0
  30. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  31. package/lib/ReactChildren.js +132 -0
  32. package/lib/ReactComponent.js +550 -0
  33. package/lib/ReactComponentBrowserEnvironment.js +158 -0
  34. package/lib/ReactComponentEnvironment.js +26 -0
  35. package/lib/ReactCompositeComponent.js +1455 -0
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +39 -0
  38. package/lib/ReactDOM.js +207 -0
  39. package/lib/ReactDOMButton.js +68 -0
  40. package/lib/ReactDOMComponent.js +399 -0
  41. package/lib/ReactDOMForm.js +59 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +58 -0
  44. package/lib/ReactDOMInput.js +181 -0
  45. package/lib/ReactDOMOption.js +51 -0
  46. package/lib/ReactDOMSelect.js +179 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +140 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +115 -0
  51. package/lib/ReactDefaultPerf.js +244 -0
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +37 -0
  54. package/lib/ReactEventEmitter.js +337 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +109 -0
  57. package/lib/ReactInjection.js +39 -0
  58. package/lib/ReactInputSelection.js +140 -0
  59. package/lib/ReactInstanceHandles.js +338 -0
  60. package/lib/ReactLink.js +54 -0
  61. package/lib/ReactMarkupChecksum.js +53 -0
  62. package/lib/ReactMount.js +641 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +425 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +154 -0
  67. package/lib/ReactPerf.js +85 -0
  68. package/lib/ReactPropTransferer.js +147 -0
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/ReactPropTypeLocations.js +29 -0
  71. package/lib/ReactPropTypes.js +359 -0
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +181 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +59 -0
  76. package/lib/ReactStateSetters.js +111 -0
  77. package/lib/ReactTextComponent.js +99 -0
  78. package/lib/ReactTransitionChildMapping.js +106 -0
  79. package/lib/ReactTransitionEvents.js +97 -0
  80. package/lib/ReactTransitionGroup.js +187 -0
  81. package/lib/ReactUpdates.js +148 -0
  82. package/lib/ReactWithAddons.js +46 -0
  83. package/lib/SelectEventPlugin.js +200 -0
  84. package/lib/ServerReactRootIndex.js +36 -0
  85. package/lib/SimpleEventPlugin.js +413 -0
  86. package/lib/SyntheticClipboardEvent.js +51 -0
  87. package/lib/SyntheticCompositionEvent.js +51 -0
  88. package/lib/SyntheticDragEvent.js +44 -0
  89. package/lib/SyntheticEvent.js +164 -0
  90. package/lib/SyntheticFocusEvent.js +44 -0
  91. package/lib/SyntheticKeyboardEvent.js +58 -0
  92. package/lib/SyntheticMouseEvent.js +85 -0
  93. package/lib/SyntheticTouchEvent.js +50 -0
  94. package/lib/SyntheticUIEvent.js +45 -0
  95. package/lib/SyntheticWheelEvent.js +66 -0
  96. package/lib/Transaction.js +276 -0
  97. package/lib/ViewportMetrics.js +37 -0
  98. package/lib/accumulate.js +54 -0
  99. package/lib/adler32.js +39 -0
  100. package/lib/cloneWithProps.js +59 -0
  101. package/lib/containsNode.js +49 -0
  102. package/lib/copyProperties.js +54 -0
  103. package/lib/createArrayFrom.js +91 -0
  104. package/lib/createFullPageComponent.js +63 -0
  105. package/lib/createNodesFromMarkup.js +93 -0
  106. package/lib/createObjectFrom.js +61 -0
  107. package/lib/cx.js +44 -0
  108. package/lib/dangerousStyleValue.js +57 -0
  109. package/lib/emptyFunction.js +43 -0
  110. package/lib/escapeTextForBrowser.js +47 -0
  111. package/lib/flattenChildren.js +57 -0
  112. package/lib/forEachAccumulated.js +36 -0
  113. package/lib/getActiveElement.js +34 -0
  114. package/lib/getEventKey.js +85 -0
  115. package/lib/getEventTarget.js +36 -0
  116. package/lib/getMarkupWrap.js +118 -0
  117. package/lib/getNodeForCharacterOffset.js +80 -0
  118. package/lib/getReactRootElementInContainer.js +40 -0
  119. package/lib/getTextContentAccessor.js +42 -0
  120. package/lib/getUnboundedScrollPosition.js +45 -0
  121. package/lib/hyphenate.js +35 -0
  122. package/lib/invariant.js +62 -0
  123. package/lib/isEventSupported.js +70 -0
  124. package/lib/isNode.js +33 -0
  125. package/lib/isTextInputElement.js +49 -0
  126. package/lib/isTextNode.js +30 -0
  127. package/lib/joinClasses.js +44 -0
  128. package/lib/keyMirror.js +58 -0
  129. package/lib/keyOf.js +41 -0
  130. package/lib/memoizeStringOnly.js +39 -0
  131. package/lib/merge.js +37 -0
  132. package/lib/mergeHelpers.js +136 -0
  133. package/lib/mergeInto.js +45 -0
  134. package/lib/mixInto.js +34 -0
  135. package/lib/objMap.js +47 -0
  136. package/lib/objMapKeyVal.js +47 -0
  137. package/lib/onlyChild.js +43 -0
  138. package/lib/performanceNow.js +42 -0
  139. package/lib/shallowEqual.js +49 -0
  140. package/lib/shouldUpdateReactComponent.js +58 -0
  141. package/lib/toArray.js +75 -0
  142. package/lib/traverseAllChildren.js +189 -0
  143. package/lib/warning.js +40 -0
  144. package/package.json +32 -21
  145. package/react.js +1 -0
  146. package/.npmignore +0 -7
  147. package/.travis.yml +0 -5
  148. package/Jakefile.js +0 -39
  149. package/LICENSE +0 -19
  150. package/browser-test/dist.html +0 -90
  151. package/browser-test/index.html +0 -86
  152. package/browser-test/min.html +0 -90
  153. package/dist/react.js +0 -3107
  154. package/dist/react.min.js +0 -22
  155. package/doc/advanced.md +0 -174
  156. package/doc/color-def.graffle +0 -938
  157. package/doc/color-def.png +0 -0
  158. package/doc/simple.dot +0 -25
  159. package/doc/simple.png +0 -0
  160. package/examples/longer-example.js +0 -41
  161. package/examples/simple.js +0 -45
  162. package/examples/using-ast-directly.js +0 -30
  163. package/examples/using-events1.js +0 -79
  164. package/examples/using-log-events.js +0 -43
  165. package/lib/base-task.js +0 -123
  166. package/lib/cb-task.js +0 -84
  167. package/lib/core.js +0 -138
  168. package/lib/dsl.js +0 -138
  169. package/lib/error.js +0 -55
  170. package/lib/event-collector.js +0 -81
  171. package/lib/event-manager.js +0 -89
  172. package/lib/eventemitter.js +0 -20
  173. package/lib/finalcb-first-task.js +0 -68
  174. package/lib/finalcb-task.js +0 -65
  175. package/lib/id.js +0 -22
  176. package/lib/input-parser.js +0 -56
  177. package/lib/log-events.js +0 -101
  178. package/lib/parse.js +0 -41
  179. package/lib/promise-resolve.js +0 -50
  180. package/lib/promise-task.js +0 -93
  181. package/lib/react.js +0 -59
  182. package/lib/ret-task.js +0 -71
  183. package/lib/sprintf.js +0 -18
  184. package/lib/status.js +0 -14
  185. package/lib/task.js +0 -251
  186. package/lib/track-tasks.js +0 -74
  187. package/lib/validate.js +0 -159
  188. package/lib/vcon.js +0 -90
  189. package/lib/when-task.js +0 -85
  190. package/src/dist.build.requirejs +0 -20
  191. package/test/ast.mocha.js +0 -136
  192. package/test/cb-task.mocha.js +0 -220
  193. package/test/core-deferred.mocha.js +0 -143
  194. package/test/core-when.mocha.js +0 -96
  195. package/test/core.mocha.js +0 -589
  196. package/test/dsl.mocha.js +0 -350
  197. package/test/event-manager.mocha.js +0 -119
  198. package/test/exec-options.mocha.js +0 -48
  199. package/test/finalcb-task.mocha.js +0 -58
  200. package/test/input-parser.mocha.js +0 -86
  201. package/test/log-events.mocha.js +0 -88
  202. package/test/mocha.opts +0 -2
  203. package/test/module-use.mocha.js +0 -147
  204. package/test/promise-auto-resolve.mocha.js +0 -68
  205. package/test/ret-task.mocha.js +0 -220
  206. package/test/task.mocha.js +0 -42
  207. package/test/validate-cb-task.mocha.js +0 -100
  208. package/test/validate-ret-task.mocha.js +0 -110
  209. package/test/validate.mocha.js +0 -324
  210. package/test/vcon.mocha.js +0 -193
  211. package/vendor/chai/chai.js +0 -2038
  212. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  213. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  214. package/vendor/mocha/mocha.css +0 -135
  215. package/vendor/mocha/mocha.js +0 -3589
  216. package/vendor/node/util.js +0 -531
  217. package/vendor/requirejs/require.js +0 -2053
  218. package/vendor/requirejs/require.min.js +0 -33
@@ -1,589 +0,0 @@
1
- 'use strict';
2
- /*global react:true */
3
-
4
- if (typeof(chai) === 'undefined') {
5
- var chai = require('chai');
6
- }
7
-
8
- if (typeof(react) === 'undefined') {
9
- var react = require('../'); //require('react');
10
- }
11
-
12
- (function () {
13
-
14
- var t = chai.assert;
15
-
16
- /**
17
- Testing core functionality
18
- */
19
-
20
- suite('core');
21
-
22
- function multiply(x, y, cb) { cb(null, x * y); }
23
- function add(x, y, cb) { cb(null, x + y); }
24
- function badFunc(a, b, cb) { throw new Error('badFuncThrow'); }
25
- function badF2(a, b, cb) { cb('my-error'); }
26
- function fnRetsSum(a, b) { return a + b; }
27
- var anonFn = function (a, b) { return a + b; };
28
-
29
- test('set and validate AST', function (done) {
30
- var fn = react();
31
- var errors = fn.setAndValidateAST({
32
- name: 'myflow',
33
- inParams: ['a', 'b'],
34
- tasks: [
35
- { f: multiply, a: ['a', 'b'], out: ['c'] }
36
- ],
37
- outTask: { a: ['c'] },
38
- otherOpt: 'foo',
39
- otherOpt2: 'bar'
40
- });
41
- t.deepEqual(errors, [], 'should set and validate as true');
42
- t.deepEqual(fn.ast.inParams, ['a', 'b']);
43
- t.deepEqual(fn.ast.tasks, [
44
- { f: multiply, a: ['a', 'b'], out: ['c'], type: 'cb', name: 'multiply' }
45
- ]);
46
- t.deepEqual(fn.ast.outTask, { a: ['c'], type: 'finalcb' });
47
- t.equal(fn.ast.name, 'myflow', 'name should match if set');
48
- t.equal(fn.ast.otherOpt, 'foo', 'any additional options should pass through');
49
- done();
50
- });
51
-
52
- test('unnamed tasks will be assigned unique names', function (done) {
53
- var fn = react();
54
- var errors = fn.setAndValidateAST({
55
- inParams: ['a', 'b'],
56
- tasks: [
57
- { f: multiply, a: ['a', 'b'], out: ['c'] },
58
- { f: multiply, a: ['a', 'b'], out: ['d'], name: 'multiply' },
59
- { f: multiply, a: ['a', 'b'], out: ['e'], name: 'times' },
60
- { f: anonFn, a: ['a', 'b'], out: ['g'], type: 'ret' },
61
- { f: multiply, a: ['a', 'b'], out: ['f'] }
62
- ],
63
- outTask: { a: ['c'] }
64
- });
65
- t.deepEqual(errors, [], 'should set and validate as true');
66
- t.equal(fn.ast.name.slice(0, 'flow_'.length), 'flow_', 'generated flow name should start with flow_');
67
- t.deepEqual(fn.ast.tasks, [
68
- { f: multiply, a: ['a', 'b'], out: ['c'], type: 'cb', name: 'multiply_0' },
69
- { f: multiply, a: ['a', 'b'], out: ['d'], name: 'multiply', type: 'cb' },
70
- { f: multiply, a: ['a', 'b'], out: ['e'], name: 'times', type: 'cb' },
71
- { f: anonFn, a: ['a', 'b'], out: ['g'], type: 'ret', name: 'task_3' },
72
- { f: multiply, a: ['a', 'b'], out: ['f'], type: 'cb', name: 'multiply_4' }
73
- ]);
74
- done();
75
- });
76
-
77
-
78
- test('execution with no errors should call callback with result', function (done) {
79
- var fn = react();
80
- var errors = fn.setAndValidateAST({
81
- inParams: ['a', 'b'],
82
- tasks: [
83
- { f: multiply, a: ['a', 'b'], out: ['c'] }
84
- ],
85
- outTask: { a: ['c'] }
86
- });
87
- t.deepEqual(errors, [], 'no validation errors');
88
- fn(2, 3, function (err, c) {
89
- t.equal(err, null);
90
- t.equal(c, 6);
91
- done();
92
- });
93
- });
94
-
95
- test('multi-step', function (done) {
96
- var fn = react();
97
- var errors = fn.setAndValidateAST({
98
- inParams: ['a', 'b'],
99
- tasks: [
100
- { f: multiply, a: ['a', 'b'], out: ['c'] },
101
- { f: add, a: ['c', 'b'], out: ['d'] }
102
- ],
103
- outTask: { a: ['c', 'd'] }
104
- });
105
- t.deepEqual(errors, [], 'no validation errors');
106
-
107
- fn(2, 3, function (err, c, d) {
108
- t.equal(err, null);
109
- t.equal(c, 6);
110
- t.equal(d, 9);
111
- done();
112
- });
113
- });
114
-
115
- test('multi-step with after as nonarr fn', function (done) {
116
- var fn = react();
117
- var errors = fn.setAndValidateAST({
118
- inParams: ['a', 'b'],
119
- tasks: [
120
- { f: multiply, a: ['a', 'b'], out: ['c'], after: add },
121
- { f: add, a: ['a', 'b'], out: ['d'] }
122
- ],
123
- outTask: { a: ['c', 'd'] }
124
- });
125
- t.deepEqual(errors, [], 'no validation errors');
126
-
127
- var collector = react.createEventCollector();
128
- collector.capture(fn, 'task.complete');
129
-
130
- fn(2, 3, function (err, c, d) {
131
- t.equal(err, null);
132
- t.equal(c, 6);
133
- t.equal(d, 5);
134
- var events = collector.list();
135
- t.equal(events.length, 2, 'should have seen one task compl events');
136
- t.equal(events[0].task.name, 'add', 'name matches');
137
- t.equal(events[1].task.name, 'multiply', 'name matches');
138
- done();
139
- });
140
- });
141
-
142
- test('mixed multi-step with after as nonarr fn w/events', function (done) {
143
- var fn = react();
144
- var errors = fn.setAndValidateAST({
145
- inParams: ['a', 'b'],
146
- tasks: [
147
- { f: multiply, a: ['a', 'b'], out: ['c'], after: fnRetsSum },
148
- { f: fnRetsSum, a: ['a', 'b'], out: ['d'], type: 'ret' }
149
- ],
150
- outTask: { a: ['c', 'd'] }
151
- });
152
- t.deepEqual(errors, [], 'no validation errors');
153
-
154
- var collector = react.createEventCollector();
155
- collector.capture(fn, 'task.complete');
156
-
157
- fn(2, 3, function (err, c, d) {
158
- t.equal(err, null);
159
- t.equal(c, 6);
160
- t.equal(d, 5);
161
- var events = collector.list();
162
- t.equal(events.length, 2, 'should have seen one task compl events');
163
- t.equal(events[0].task.name, 'fnRetsSum', 'name matches');
164
- t.isNotNull(events[0].task.id, 'has unique id');
165
- t.isNotNull(events[0].task.startTime, 'has startTime');
166
- t.isNotNull(events[0].task.endTime, 'has endTime');
167
- t.isNotNull(events[0].task.elapsedTime !== undefined, 'has elapsedTime');
168
- t.isNotNull(events[0].task.args, 'has args');
169
- t.isNotNull(events[0].task.results, 'has results');
170
- t.equal(events[1].task.name, 'multiply', 'name matches');
171
- t.isNotNull(events[1].task.id, 'has unique id');
172
- t.isNotNull(events[1].task.startTime, 'has startTime');
173
- t.isNotNull(events[1].task.endTime, 'has endTime');
174
- t.isNotNull(events[1].task.elapsedTime !== undefined, 'has elapsedTime');
175
- t.isNotNull(events[1].task.args, 'has args');
176
- t.isNotNull(events[1].task.results, 'has results');
177
- done();
178
- });
179
- });
180
-
181
-
182
-
183
-
184
- test('sets obj values', function (done) {
185
- var fn = react();
186
- var errors = fn.setAndValidateAST({
187
- inParams: ['a', 'b', 'c'],
188
- tasks: [
189
- { f: multiply, a: ['a', 'b'], out: ['c.mult'] },
190
- { f: fnRetsSum, a: ['c.mult', 'b'], out: ['c.sum'], type: 'ret' }
191
- ],
192
- outTask: { a: ['c.mult', 'c.sum', 'c'] }
193
- });
194
- t.deepEqual(errors, [], 'no validation errors');
195
-
196
- fn(2, 3, { foo: 1 }, function (err, cmult, csum, c) {
197
- t.deepEqual(err, null, 'should be no err');
198
- t.equal(cmult, 6);
199
- t.equal(csum, 9);
200
- t.deepEqual(c, { foo: 1, mult: 6, sum: 9});
201
- done();
202
- });
203
- });
204
-
205
- test('error when cant complete', function (done) {
206
- var fn = react();
207
- var errors = fn.setAndValidateAST({
208
- inParams: ['a', 'b', 'c'],
209
- tasks: [
210
- { f: multiply, a: ['a', 'b'], out: ['c.mult'] },
211
- { f: fnRetsSum, a: ['c.bad', 'b'], out: ['c.sum'], type: 'ret' },
212
- { f: add, a: ['c.sum', 'a'], out: ['d']}
213
- ],
214
- outTask: { a: ['c.mult', 'c.sum', 'd'] }
215
- });
216
- t.deepEqual(errors, [], 'no validation errors');
217
-
218
- fn(2, 3, { foo: 1 }, function (err, cmult, csum, d) {
219
- t.equal(err.message, 'no tasks running, flow will not complete, remaining tasks: fnRetsSum, add');
220
- done();
221
- });
222
- });
223
-
224
-
225
- test('objects', function (done) {
226
- function retObj(a, b, cb) { cb(null, { bar: a + b }); }
227
- function concat(a, b, cb) { cb(null, { result: a + b }); }
228
-
229
- var fn = react();
230
- var errors = fn.setAndValidateAST({
231
- inParams: ['a', 'b'],
232
- tasks: [
233
- { f: retObj, a: ['a.foo', 'b'], out: ['c'] },
234
- { f: concat, a: ['c.bar', 'b'], out: ['d'] }
235
- ],
236
- outTask: { a: ['c', 'd.result'] }
237
- });
238
- t.deepEqual(errors, [], 'no validation errors');
239
-
240
- fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
241
- t.equal(err, null);
242
- t.deepEqual(c, { bar: 'FOOB' });
243
- t.equal(dresult, 'FOOBB');
244
- done();
245
- });
246
- });
247
-
248
- test('objects from container', function (done) {
249
- var C = {
250
- retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
251
- concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
252
- };
253
-
254
- var fn = react();
255
- var errors = fn.setAndValidateAST({
256
- inParams: ['a', 'b'],
257
- tasks: [
258
- { f: C.retObj, a: ['a.foo', 'b'], out: ['c'] },
259
- { f: C.concat, a: ['c.bar', 'b'], out: ['d'] }
260
- ],
261
- outTask: { a: ['c', 'd.result'] }
262
- });
263
- t.deepEqual(errors, [], 'no validation errors');
264
-
265
- fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
266
- t.equal(err, null);
267
- t.deepEqual(c, { bar: 'FOOB' });
268
- t.equal(dresult, 'FOOBB');
269
- done();
270
- });
271
- });
272
-
273
- test('objects from container input arg', function (done) {
274
- var CONT = {
275
- retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
276
- concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
277
- };
278
-
279
- var fn = react();
280
- var errors = fn.setAndValidateAST({
281
- inParams: ['a', 'b', 'CONT'],
282
- tasks: [
283
- { f: 'CONT.retObj', a: ['a.foo', 'b'], out: ['c'] },
284
- { f: 'CONT.concat', a: ['c.bar', 'b'], out: ['d'] }
285
- ],
286
- outTask: { a: ['c', 'd.result'] }
287
- });
288
- t.deepEqual(errors, [], 'no validation errors');
289
-
290
- fn({ foo: 'FOO' }, 'B', CONT, function (err, c, dresult) {
291
- t.equal(err, null);
292
- t.deepEqual(c, { bar: 'FOOB' });
293
- t.equal(dresult, 'FOOBB');
294
- done();
295
- });
296
- });
297
-
298
- test('use locals for functions', function (done) {
299
- var locals = {
300
- retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
301
- concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
302
- };
303
-
304
- var fn = react();
305
- var errors = fn.setAndValidateAST({
306
- inParams: ['a', 'b'],
307
- tasks: [
308
- { f: 'retObj', a: ['a.foo', 'b'], out: ['c'] },
309
- { f: 'concat', a: ['c.bar', 'b'], out: ['d'] }
310
- ],
311
- outTask: { a: ['c', 'd.result'] },
312
- locals: locals
313
- });
314
- t.deepEqual(errors, [], 'no validation errors');
315
-
316
- fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
317
- t.equal(err, null);
318
- t.deepEqual(c, { bar: 'FOOB' });
319
- t.equal(dresult, 'FOOBB');
320
- done();
321
- });
322
- });
323
-
324
- test('objects from locals', function (done) {
325
- var CONT = {
326
- retObj: function retObj(a, b, cb) { cb(null, { bar: a + b }); },
327
- concat: function concat(a, b, cb) { cb(null, { result: a + b }); }
328
- };
329
-
330
- var fn = react();
331
- var errors = fn.setAndValidateAST({
332
- inParams: ['a', 'b'],
333
- tasks: [
334
- { f: 'CONT.retObj', a: ['a.foo', 'b'], out: ['c'] },
335
- { f: 'CONT.concat', a: ['c.bar', 'b'], out: ['d'] }
336
- ],
337
- outTask: { a: ['c', 'd.result'] },
338
- locals: { CONT: CONT }
339
- });
340
- t.deepEqual(errors, [], 'no validation errors');
341
-
342
- fn({ foo: 'FOO' }, 'B', function (err, c, dresult) {
343
- t.equal(err, null);
344
- t.deepEqual(c, { bar: 'FOOB' });
345
- t.equal(dresult, 'FOOBB');
346
- done();
347
- });
348
- });
349
-
350
- test('multi-step func throws, cb with error', function (done) {
351
- var fn = react();
352
- var errors = fn.setAndValidateAST({
353
- inParams: ['a', 'b'],
354
- tasks: [
355
- { f: multiply, a: ['a', 'b'], out: ['c'] },
356
- { f: badFunc, a: ['c', 'b'], out: ['d'] }
357
- ],
358
- outTask: { a: ['c', 'd'] }
359
- });
360
- t.deepEqual(errors, [], 'no validation errors');
361
-
362
- fn(2, 3, function (err, c, d) {
363
- t.equal(err.message, 'badFuncThrow');
364
- done();
365
- });
366
- });
367
-
368
- test('multi-step func cb err, cb with error', function (done) {
369
-
370
- var fn = react();
371
- var errors = fn.setAndValidateAST({
372
- inParams: ['a', 'b'],
373
- tasks: [
374
- { f: multiply, a: ['a', 'b'], out: ['c'] },
375
- { f: badF2, a: ['c', 'b'], out: ['d'] },
376
- { f: add, a: ['d', 'b'], out: ['e'] }
377
- ],
378
- outTask: { a: ['c', 'e'] }
379
- });
380
- t.deepEqual(errors, [], 'no validation errors');
381
-
382
- fn(2, 3, function (err, c, d) {
383
- t.equal(err.message, 'my-error');
384
- done();
385
- });
386
- });
387
-
388
- test('using "this" in a cb function', function (done) {
389
-
390
- function getA(cb) {
391
- /*jshint validthis: true */
392
- cb(null, this.a);
393
- }
394
-
395
- var fn = react();
396
- var errors = fn.setAndValidateAST({
397
- inParams: [],
398
- tasks: [
399
- { f: getA, a: [], out: ['a'] }
400
- ],
401
- outTask: { a: ['a'] }
402
- });
403
- t.deepEqual(errors, [], 'no validation errors');
404
-
405
- var obj = {
406
- a: 100
407
- };
408
-
409
- fn.apply(obj, [function (err, a) {
410
- t.equal(err, null);
411
- t.equal(a, 100);
412
- done();
413
- }]);
414
- });
415
-
416
- test('using "this" in a sync function', function (done) {
417
- function getA(cb) {
418
- /*jshint validthis: true */
419
- return this.a;
420
- }
421
-
422
- var fn = react();
423
- var errors = fn.setAndValidateAST({
424
- inParams: [],
425
- tasks: [
426
- { f: getA, a: [], out: ['a'], type: 'ret' }
427
- ],
428
- outTask: { a: ['a'] }
429
- });
430
- t.deepEqual(errors, [], 'no validation errors');
431
-
432
- var obj = {
433
- a: 100
434
- };
435
-
436
- fn.apply(obj, [function (err, a) {
437
- t.equal(err, null);
438
- t.equal(a, 100);
439
- done();
440
- }]);
441
- });
442
-
443
- test('undefined input arguments will be upgraded from undefined to null', function (done) {
444
- var fn = react();
445
- function concat(a, b) {
446
- return '' + a + b;
447
- }
448
- var errors = fn.setAndValidateAST({
449
- inParams: ['a', 'b'],
450
- tasks: [
451
- { f: concat, a: ['a', 'b'], out: ['c'], type: 'ret' }
452
- ],
453
- outTask: { a: ['c'] }
454
- });
455
- t.deepEqual(errors, [], 'no validation errors');
456
- fn('first', undefined, function (err, c) { // undefined second param, upgrade to null
457
- t.equal(err, null);
458
- t.equal(c, 'firstnull');
459
- done();
460
- });
461
- });
462
-
463
-
464
-
465
- // Select first tests
466
-
467
-
468
- test('selectFirst with first succeeding', function (done) {
469
- var fn = react();
470
- var errors = fn.setAndValidateAST({
471
- inParams: ['a', 'b'],
472
- tasks: [
473
- { f: multiply, a: ['a', 'b'], out: ['c'] },
474
- { f: add, a: ['a', 'b'], out: ['c'], after: ['multiply'] }
475
- ],
476
- outTask: { type: 'finalcbFirst', a: ['c'] }
477
- });
478
- t.deepEqual(errors, [], 'no validation errors');
479
-
480
- var collector = react.createEventCollector();
481
- collector.capture(fn, 'task.complete');
482
-
483
- fn(2, 3, function (err, c) {
484
- t.equal(err, null);
485
- t.equal(c, 6);
486
- var events = collector.list();
487
- t.equal(events.length, 1, 'should have seen one task compl events');
488
- t.equal(events[0].task.name, 'multiply', 'name matches');
489
- t.deepEqual(events[0].task.results, [6], 'results match');
490
- done();
491
- });
492
- });
493
-
494
- test('selectFirst with third succeeding', function (done) {
495
- function noSuccess(a, b, cb) { cb(null); } // returns undefined result
496
- function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
497
- var fn = react();
498
- var errors = fn.setAndValidateAST({
499
- inParams: ['a', 'b'],
500
- tasks: [
501
- { f: noSuccess, a: ['a', 'b'], out: ['c'] },
502
- { f: noSuccessNull, a: ['a', 'b'], out: ['c'], after: ['noSuccess'] },
503
- { f: add, a: ['a', 'b'], out: ['c'], after: ['noSuccessNull'] }
504
- ],
505
- outTask: { type: 'finalcbFirst', a: ['c'] }
506
- });
507
- t.deepEqual(errors, [], 'no validation errors');
508
-
509
- var collector = react.createEventCollector();
510
- collector.capture(fn, 'task.complete');
511
-
512
- fn(2, 3, function (err, c) {
513
- t.equal(err, null);
514
- t.equal(c, 5);
515
- var events = collector.list();
516
- t.equal(events.length, 3, 'should have seen three task compl events');
517
- t.equal(events[2].task.name, 'add', 'name matches');
518
- t.deepEqual(events[2].task.results, [5], 'results match');
519
- done();
520
- });
521
- });
522
-
523
-
524
- test('selectFirst forces order with third succeeding', function (done) {
525
- function noSuccess(a, b, cb) {
526
- setTimeout(function () { cb(null); }, 100); // returns undefined result
527
- }
528
- function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
529
- var fn = react();
530
- var errors = fn.setAndValidateAST({
531
- inParams: ['a', 'b'],
532
- tasks: [
533
- { f: noSuccess, a: ['a', 'b'], out: ['c'] },
534
- { f: noSuccessNull, a: ['a', 'b'], out: ['c'], after: ['noSuccess']},
535
- { f: add, a: ['a', 'b'], out: ['c'], after: ['noSuccessNull'] },
536
- { f: noSuccess, a: ['a', 'b'], out: ['c'], after: ['add'] }
537
- ],
538
- outTask: { type: 'finalcbFirst', a: ['c'] }
539
- });
540
- t.deepEqual(errors, [], 'no validation errors');
541
-
542
- var collector = react.createEventCollector();
543
- collector.capture(fn, 'task.complete');
544
-
545
- fn(2, 3, function (err, c) {
546
- t.equal(err, null);
547
- t.equal(c, 5);
548
- var events = collector.list();
549
- t.equal(events.length, 3, 'should have seen three task compl events');
550
- t.equal(events[0].task.name, 'noSuccess', 'name matches');
551
- t.equal(events[1].task.name, 'noSuccessNull', 'name matches');
552
- t.equal(events[2].task.name, 'add', 'name matches');
553
- t.deepEqual(events[2].task.results, [5], 'results match');
554
- done();
555
- });
556
- });
557
-
558
- test('selectFirst using direct returns', function (done) {
559
- function noSuccess(a, b) { } // returns undefined result
560
- function noSuccessNull(a, b) { return null; } // returns null result
561
- function addRet(a, b) { return a + b; }
562
- var fn = react();
563
- var errors = fn.setAndValidateAST({
564
- inParams: ['a', 'b'],
565
- tasks: [
566
- { f: noSuccess, a: ['a', 'b'], out: ['c'], type: 'ret' },
567
- { f: noSuccessNull, a: ['a', 'b'], out: ['c'], type: 'ret', after: ['noSuccess'] },
568
- { f: addRet, a: ['a', 'b'], out: ['c'], type: 'ret', after: ['noSuccessNull'] }
569
- ],
570
- outTask: { type: 'finalcbFirst', a: ['c'] }
571
- });
572
- t.deepEqual(errors, [], 'no validation errors');
573
-
574
- var collector = react.createEventCollector();
575
- collector.capture(fn, 'task.complete');
576
-
577
- fn(2, 3, function (err, c) {
578
- t.equal(err, null);
579
- t.equal(c, 5);
580
- var events = collector.list();
581
- t.equal(events.length, 3, 'should have seen three task compl events');
582
- t.equal(events[2].task.name, 'addRet', 'name matches');
583
- t.deepEqual(events[2].task.results, [5], 'results match');
584
- done();
585
- });
586
- });
587
-
588
-
589
- }());