react 0.7.0 → 0.9.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 (217) hide show
  1. package/README.md +10 -231
  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 +203 -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 +293 -0
  20. package/lib/EventPluginRegistry.js +281 -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 +339 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +149 -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/ReactTestUtils.js +394 -0
  78. package/lib/ReactTextComponent.js +99 -0
  79. package/lib/ReactTransitionChildMapping.js +106 -0
  80. package/lib/ReactTransitionEvents.js +97 -0
  81. package/lib/ReactTransitionGroup.js +187 -0
  82. package/lib/ReactUpdates.js +148 -0
  83. package/lib/ReactWithAddons.js +51 -0
  84. package/lib/SelectEventPlugin.js +200 -0
  85. package/lib/ServerReactRootIndex.js +36 -0
  86. package/lib/SimpleEventPlugin.js +413 -0
  87. package/lib/SyntheticClipboardEvent.js +51 -0
  88. package/lib/SyntheticCompositionEvent.js +51 -0
  89. package/lib/SyntheticDragEvent.js +44 -0
  90. package/lib/SyntheticEvent.js +164 -0
  91. package/lib/SyntheticFocusEvent.js +44 -0
  92. package/lib/SyntheticKeyboardEvent.js +58 -0
  93. package/lib/SyntheticMouseEvent.js +85 -0
  94. package/lib/SyntheticTouchEvent.js +50 -0
  95. package/lib/SyntheticUIEvent.js +45 -0
  96. package/lib/SyntheticWheelEvent.js +66 -0
  97. package/lib/Transaction.js +276 -0
  98. package/lib/ViewportMetrics.js +37 -0
  99. package/lib/accumulate.js +54 -0
  100. package/lib/adler32.js +39 -0
  101. package/lib/cloneWithProps.js +59 -0
  102. package/lib/containsNode.js +49 -0
  103. package/lib/copyProperties.js +54 -0
  104. package/lib/createArrayFrom.js +91 -0
  105. package/lib/createFullPageComponent.js +63 -0
  106. package/lib/createNodesFromMarkup.js +93 -0
  107. package/lib/createObjectFrom.js +61 -0
  108. package/lib/cx.js +44 -0
  109. package/lib/dangerousStyleValue.js +57 -0
  110. package/lib/emptyFunction.js +43 -0
  111. package/lib/escapeTextForBrowser.js +47 -0
  112. package/lib/flattenChildren.js +57 -0
  113. package/lib/forEachAccumulated.js +36 -0
  114. package/lib/getActiveElement.js +34 -0
  115. package/lib/getEventKey.js +85 -0
  116. package/lib/getEventTarget.js +36 -0
  117. package/lib/getMarkupWrap.js +118 -0
  118. package/lib/getNodeForCharacterOffset.js +80 -0
  119. package/lib/getReactRootElementInContainer.js +40 -0
  120. package/lib/getTextContentAccessor.js +42 -0
  121. package/lib/getUnboundedScrollPosition.js +45 -0
  122. package/lib/hyphenate.js +35 -0
  123. package/lib/invariant.js +62 -0
  124. package/lib/isEventSupported.js +70 -0
  125. package/lib/isNode.js +33 -0
  126. package/lib/isTextInputElement.js +49 -0
  127. package/lib/isTextNode.js +30 -0
  128. package/lib/joinClasses.js +44 -0
  129. package/lib/keyMirror.js +58 -0
  130. package/lib/keyOf.js +41 -0
  131. package/lib/memoizeStringOnly.js +39 -0
  132. package/lib/merge.js +37 -0
  133. package/lib/mergeHelpers.js +136 -0
  134. package/lib/mergeInto.js +45 -0
  135. package/lib/mixInto.js +34 -0
  136. package/lib/objMap.js +47 -0
  137. package/lib/objMapKeyVal.js +47 -0
  138. package/lib/onlyChild.js +43 -0
  139. package/lib/performanceNow.js +42 -0
  140. package/lib/shallowEqual.js +49 -0
  141. package/lib/shouldUpdateReactComponent.js +58 -0
  142. package/lib/toArray.js +75 -0
  143. package/lib/traverseAllChildren.js +189 -0
  144. package/lib/warning.js +48 -0
  145. package/package.json +33 -21
  146. package/react.js +1 -0
  147. package/.npmignore +0 -7
  148. package/.travis.yml +0 -7
  149. package/Jakefile.js +0 -39
  150. package/LICENSE +0 -19
  151. package/browser-test/dist.html +0 -90
  152. package/browser-test/index.html +0 -86
  153. package/browser-test/min.html +0 -90
  154. package/dist/react.js +0 -3141
  155. package/dist/react.min.js +0 -22
  156. package/doc/advanced.md +0 -174
  157. package/doc/color-def.graffle +0 -938
  158. package/doc/color-def.png +0 -0
  159. package/doc/simple.dot +0 -25
  160. package/doc/simple.png +0 -0
  161. package/examples/longer-example.js +0 -41
  162. package/examples/simple.js +0 -45
  163. package/examples/using-ast-directly.js +0 -30
  164. package/examples/using-events1.js +0 -79
  165. package/examples/using-log-events.js +0 -43
  166. package/lib/base-task.js +0 -120
  167. package/lib/cb-task.js +0 -84
  168. package/lib/core.js +0 -138
  169. package/lib/dsl.js +0 -138
  170. package/lib/error.js +0 -55
  171. package/lib/event-collector.js +0 -81
  172. package/lib/event-manager.js +0 -89
  173. package/lib/eventemitter.js +0 -20
  174. package/lib/finalcb-first-task.js +0 -68
  175. package/lib/finalcb-task.js +0 -65
  176. package/lib/id.js +0 -22
  177. package/lib/input-parser.js +0 -56
  178. package/lib/log-events.js +0 -101
  179. package/lib/parse.js +0 -41
  180. package/lib/promise-resolve.js +0 -50
  181. package/lib/promise-task.js +0 -93
  182. package/lib/react.js +0 -59
  183. package/lib/ret-task.js +0 -71
  184. package/lib/sprintf.js +0 -18
  185. package/lib/status.js +0 -14
  186. package/lib/task.js +0 -251
  187. package/lib/track-tasks.js +0 -74
  188. package/lib/validate.js +0 -159
  189. package/lib/vcon.js +0 -113
  190. package/lib/when-task.js +0 -84
  191. package/src/dist.build.requirejs +0 -20
  192. package/test/ast.mocha.js +0 -136
  193. package/test/cb-task.mocha.js +0 -220
  194. package/test/core-deferred.mocha.js +0 -143
  195. package/test/core-when.mocha.js +0 -96
  196. package/test/core.mocha.js +0 -589
  197. package/test/dsl.mocha.js +0 -352
  198. package/test/event-manager.mocha.js +0 -119
  199. package/test/exec-options.mocha.js +0 -48
  200. package/test/finalcb-task.mocha.js +0 -58
  201. package/test/input-parser.mocha.js +0 -86
  202. package/test/log-events.mocha.js +0 -88
  203. package/test/mocha.opts +0 -2
  204. package/test/module-use.mocha.js +0 -164
  205. package/test/promise-auto-resolve.mocha.js +0 -68
  206. package/test/ret-task.mocha.js +0 -220
  207. package/test/task.mocha.js +0 -42
  208. package/test/validate-cb-task.mocha.js +0 -100
  209. package/test/validate-ret-task.mocha.js +0 -110
  210. package/test/validate.mocha.js +0 -324
  211. package/test/vcon.mocha.js +0 -193
  212. package/vendor/chai/chai.js +0 -4251
  213. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  214. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  215. package/vendor/node/util.js +0 -531
  216. package/vendor/requirejs/require.js +0 -2045
  217. package/vendor/requirejs/require.min.js +0 -36
package/lib/validate.js DELETED
@@ -1,159 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['util', './sprintf', 'ensure-array', './task'], function (util, sprintf, array, taskUtil) {
8
- 'use strict';
9
- /*jshint latedef:false */
10
-
11
- var AST_IS_OBJECT = 'ast must be an object with inParams, tasks, and outTask';
12
- var INPARAMS_ARR_STR = 'ast.inParams must be an array of strings';
13
- var TASKS_ARR = 'ast.tasks must be an array of tasks';
14
- var NAMES_UNIQUE = 'ast.tasks that specify name need to be unique, duplicate:';
15
- var LOCALS_NOTNULL = 'ast.locals should not be null';
16
- var DUP_OUTPUTS = 'multiple tasks output the same param, must be unique. param';
17
- var MISSING_INPUTS = 'missing or mispelled variable referenced in flow definition: %s';
18
-
19
- // match any of our literals true, false, int, float, quoted strings, or is property (has dot), match vcon.js
20
- var LITERAL_OR_PROP_RE = /^(true|false|this|null|\-?[0-9\.]+)$|'|"|\./i;
21
-
22
- function format_error(errmsg, obj) {
23
- return sprintf('%s - %s', errmsg, util.inspect(obj));
24
- }
25
-
26
- /**
27
- true if is a literal name
28
- */
29
- function isLiteralOrProp(name) { // need to match what is in vcon.js, TODO consolidate?
30
- return LITERAL_OR_PROP_RE.test(name);
31
- }
32
-
33
- /**
34
- validate the AST return Errors
35
- @example
36
- var validate = require('./validate');
37
- var errors = validate(ast);
38
- @returns array of errors, could be empty
39
- */
40
- function validate(ast) {
41
- if (!ast || !ast.inParams || !ast.tasks || !ast.outTask) return [AST_IS_OBJECT];
42
- var errors = [];
43
- errors = errors.concat(validateInParams(ast.inParams));
44
- errors = errors.concat(validateTasks(ast.tasks));
45
- errors = errors.concat(validateTaskNamesUnique(ast.tasks));
46
- errors = errors.concat(taskUtil.validateOutTask(ast.outTask));
47
- errors = errors.concat(validateLocals(ast.locals));
48
- if (errors.length === 0) { // if no errors do additional validation
49
- if (ast.outTask.type !== 'finalcbFirst') errors = errors.concat(validateOuputsUnique(ast.tasks));
50
- errors = errors.concat(taskUtil.validateLocalFunctions(ast.inParams, ast.tasks, ast.locals));
51
- errors = errors.concat(validateNoMissingNames(ast));
52
- }
53
- return errors;
54
- }
55
-
56
- /**
57
- @returns array of errors, could be empty
58
- */
59
- function validateInParams(inParams) {
60
- if (!Array.isArray(inParams) ||
61
- !inParams.every(function (x) { return (typeof(x) === 'string'); })) {
62
- return [INPARAMS_ARR_STR];
63
- }
64
- return [];
65
- }
66
-
67
- /**
68
- @returns array of errors, could be empty
69
- */
70
- function validateTasks(tasks) {
71
- if (!Array.isArray(tasks)) return [TASKS_ARR];
72
- var errors = [];
73
- tasks.forEach(function (t) {
74
- errors = errors.concat(taskUtil.validate(t));
75
- });
76
- return errors;
77
- }
78
-
79
- function validateTaskNamesUnique(tasks) {
80
- if (!Array.isArray(tasks)) return [];
81
- var errors = [];
82
- var namedTasks = tasks.filter(function (t) { return (t.name); });
83
- var names = namedTasks.map(function (t) { return t.name; });
84
- names.reduce(function (accum, name) {
85
- if (accum[name]) errors.push(sprintf('%s %s', NAMES_UNIQUE, name));
86
- else accum[name] = true;
87
- return accum;
88
- }, {});
89
- return errors;
90
- }
91
-
92
- function validateLocals(locals) {
93
- var errors = [];
94
- if (locals === null) errors.push(LOCALS_NOTNULL);
95
- return errors;
96
- }
97
-
98
- function getOutputParams(taskDef) {
99
- return array(taskDef.out); //ensure array
100
- }
101
-
102
- function validateOuputsUnique(taskDefs) {
103
- var errors = [];
104
- taskDefs.reduce(function (accum, t) {
105
- getOutputParams(t).forEach(function (param) {
106
- if (accum[param] !== undefined) errors.push(sprintf('%s: %s', DUP_OUTPUTS, param));
107
- else accum[param] = true;
108
- });
109
- return accum;
110
- }, {});
111
- return errors;
112
- }
113
-
114
-
115
- /**
116
- validate there are no missing or mispelled param names in any task inputs
117
- or the final task output
118
-
119
- @return array of errors, or empty array if none
120
- */
121
- function validateNoMissingNames(ast) {
122
- var errors = [];
123
- var names = {};
124
- if (ast.locals) {
125
- names = Object.keys(ast.locals).reduce(function (accum, k) { // start with locals
126
- accum[k] = true;
127
- return accum;
128
- }, names);
129
- }
130
- ast.inParams.reduce(function (accum, p) { // add input params
131
- accum[p] = true;
132
- return accum;
133
- }, names);
134
- ast.tasks.reduce(function (accum, t) { // add task outputs
135
- return t.out.reduce(function (innerAccum, p) {
136
- innerAccum[p] = true;
137
- return innerAccum;
138
- }, accum);
139
- }, names);
140
-
141
- // now we have all possible provided vars, check task inputs are accounted for
142
- ast.tasks.reduce(function (accum, t) { // for all tasks
143
- return t.a.reduce(function (innerAccum, p) { // for all in params, except property
144
- if (!isLiteralOrProp(p) && !names[p]) innerAccum.push(sprintf(MISSING_INPUTS, p)); // add error if missing
145
- return innerAccum;
146
- }, accum);
147
- }, errors);
148
-
149
- // now check the final task outputs
150
- ast.outTask.a.reduce(function (accum, p) { // for final task out params
151
- if (!isLiteralOrProp(p) && !names[p]) accum.push(sprintf(MISSING_INPUTS, p)); // add error if missing
152
- return accum;
153
- }, errors);
154
- return errors;
155
- }
156
-
157
- return validate;
158
-
159
- });
package/lib/vcon.js DELETED
@@ -1,113 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define([], function () {
8
- 'use strict';
9
-
10
- var LAST_RESULTS_KEY = ':LAST_RESULTS';
11
-
12
- function VContext() {
13
- }
14
-
15
- VContext.prototype.getLastResults = function () { return this.getVar(LAST_RESULTS_KEY); };
16
- VContext.prototype.setLastResults = function (args) { this.setVar(LAST_RESULTS_KEY, args); };
17
-
18
- VContext.prototype.getVar = function (name) { //name might be simple or obj.prop, also literals
19
- /*jshint regexp: false */
20
- var vConValues = this.values;
21
- if (typeof(name) !== 'string') return name; // literal boolean or number
22
- name = name.trim();
23
- // literal checks need to match what is in validate.js
24
- if (name === 'true') return true;
25
- if (name === 'false') return false;
26
- if (name === 'null') return null;
27
- if (/^-?[0-9]+$/.test(name)) return parseInt(name, 10); //int
28
- if (/^-?[0-9.]+$/.test(name)) return parseFloat(name); //float
29
- var m = /^("|')([^\1]*)\1$/.exec(name); //check for quoted string " or '
30
- if (m) return m[2]; // if is quoted str, return inside of the quotes
31
- var nameAndProps = name.split('.');
32
- var result = this.resolveNameArr(nameAndProps);
33
- return result;
34
- };
35
-
36
- VContext.prototype.resolveNameArr = function (nameAndProps) {
37
- var vConValues = this.values;
38
- var result = nameAndProps.reduce(function (accObj, prop) {
39
- if (accObj === undefined || accObj === null) return undefined; // prevent exception
40
- return accObj[prop];
41
- }, vConValues); // vCon['foo']['bar']
42
- if (result === undefined && this.global !== undefined) { // see if matches any global
43
- result = nameAndProps.reduce(function (accObj, prop) {
44
- if (accObj === undefined || accObj === null) return undefined; // prevent exception
45
- return accObj[prop];
46
- }, this.global); // global['foo']['bar']
47
- }
48
- return result;
49
- };
50
-
51
- /**
52
- Saves all the results from a task as a unit, also sets special
53
- variable :LAST_RESULTS which keeps an array of the last values
54
- which can be used for chaining and testing last results, etc.
55
- */
56
- VContext.prototype.saveResults = function (paramArr, valuesArr) { // set values for params
57
- var self = this;
58
- paramArr.forEach(function (k, idx) { //save values to v context
59
- self.setVar(k, (valuesArr[idx] !== undefined) ? valuesArr[idx] : null); //upgrade any undefined to null
60
- });
61
- this.setLastResults(valuesArr);
62
- };
63
-
64
- VContext.prototype.setVar = function (name, value) { //name might be simple or obj.prop
65
- if (!name) return; // if name is undefined or null, then discard
66
- var vConValues = this.values;
67
- var nameAndProps = name.split('.');
68
- var lastProp = nameAndProps.pop();
69
- var obj = nameAndProps.reduce(function (accObj, prop) {
70
- var o = accObj[prop];
71
- if (o === undefined || o === null) { // if doesn't exist create it
72
- o = accObj[prop] = { };
73
- }
74
- return o;
75
- }, vConValues); // vCon['foo']['bar']
76
- obj[lastProp] = value;
77
- };
78
-
79
-
80
- /**
81
- Create Variable Context using arguments passed in.
82
- Ignore extra arguments passed in. Locals can be
83
- passed into seed the VContext otherwise empty {}
84
- will be used
85
- @param self used to pass 'this' context in
86
- */
87
- VContext.create = function (args, inParams, locals, self) {
88
- /*jshint validthis:true, evil:true */
89
- var initValues = {};
90
- if (self) initValues['this'] = self;
91
- if (locals) Object.keys(locals).forEach(function (k) { initValues[k] = locals[k]; }); // copy over keys
92
- var vContext = new VContext();
93
- vContext.values = args.reduce(function (vcon, x, idx) { // create vCon start with input args
94
- var param = inParams[idx];
95
- if (param) vcon[param] = (x !== undefined) ? x : null; // upgrade undefined to null
96
- return vcon;
97
- }, initValues);
98
-
99
- // add in global
100
- if (typeof global === 'object') { // node.js and modern browsers expose global
101
- vContext.global = global;
102
- } else { // try to access this using Function eval of this
103
- // http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript
104
- vContext.global = new Function('return this')();
105
- }
106
-
107
- return vContext;
108
- };
109
-
110
-
111
- return VContext;
112
-
113
- });
package/lib/when-task.js DELETED
@@ -1,84 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
8
- 'use strict';
9
-
10
- /**
11
- When task which checks if is a promise (has a then method)
12
- and waits for it to resolve.
13
-
14
- If argument does not have a then method, it resolves immediately
15
- */
16
-
17
- function format_error(errmsg, obj) {
18
- return sprintf('%s - %s', errmsg, util.inspect(obj));
19
- }
20
-
21
- var REQ = 'whenTask requires a, out';
22
- var A_REQ = 'whenTask requires a to be an array[1] of string param names';
23
- var OUT_REQ = 'whenTask requires out to be an array[1] of string param names';
24
-
25
- function WhenTask(taskDef) {
26
- var self = this;
27
- Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
28
- }
29
-
30
- WhenTask.prototype = new BaseTask();
31
- WhenTask.prototype.constructor = WhenTask;
32
-
33
- WhenTask.prototype.f = function when() { }; // just here to keep validations happy
34
-
35
- WhenTask.validate = function (taskDef) {
36
- var errors = [];
37
- if (!taskDef.a || !taskDef.out) {
38
- errors.push(format_error(REQ, taskDef));
39
- } else {
40
- if (! (Array.isArray(taskDef.a) && taskDef.a.length === 1 &&
41
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
42
- errors.push(format_error(A_REQ, taskDef));
43
- }
44
- if (! (Array.isArray(taskDef.out) && taskDef.out.length <= 1 &&
45
- taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
46
- errors.push(format_error(OUT_REQ, taskDef));
47
- }
48
- }
49
- return errors;
50
- };
51
-
52
- WhenTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
53
- var self = this;
54
- this.nextFn = function (arg) {
55
- var args = Array.prototype.slice.call(arguments);
56
- vCon.saveResults(self.out, args);
57
- self.complete(args);
58
- contExec();
59
- };
60
- this.failFn = function (err) {
61
- handleTaskError(self, err);
62
- };
63
- };
64
-
65
- WhenTask.prototype.exec = function exec(vCon, handleError, contExec) {
66
- try {
67
- var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
68
- //console.error('WhenTask.exec.args=', args);
69
- //console.error('WhenTask.exec.vCon=', vCon);
70
- this.start(args); //note the start time, args
71
- var arg = args[0]; // one value allowed
72
- if (arg && typeof(arg.then) === 'function') { // is a promise
73
- arg.then(this.nextFn, this.failFn);
74
- } else { // not a promise continue immediately
75
- this.nextFn(arg);
76
- }
77
- } catch (err) { //catch and handle the task error, calling final cb
78
- handleError(this, err);
79
- }
80
- };
81
-
82
- return WhenTask;
83
-
84
- });
@@ -1,20 +0,0 @@
1
- ({
2
- baseUrl: "..",
3
- optimize: "none",
4
- packages: [
5
- {
6
- name: "react",
7
- location: "lib",
8
- main: "react"
9
- }
10
- ],
11
- paths: {
12
- jQuery: "empty:",
13
- eventemitter2: "node_modules/eventemitter2/lib/eventemitter2",
14
- util: "vendor/node/util",
15
- sprint: "node_modules/sprint/lib/sprint",
16
- "ensure-array": "node_modules/ensure-array/ensure-array"
17
- },
18
- name: "react",
19
- out: "dist/react.js"
20
- })
package/test/ast.mocha.js DELETED
@@ -1,136 +0,0 @@
1
- /*global react: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 ast
18
- */
19
-
20
-
21
- suite('ast');
22
-
23
- function load(res, cb) { cb(null, res + '-loaded'); }
24
- function prefix(prefstr, str, cb) { cb(null, prefstr + str); }
25
- function postfix(str, poststr, cb) { cb(null, str + poststr); }
26
- function upper(str) { return str.toUpperCase(); }
27
- function makeError(str, cb) { cb(new Error('makeErr-' + str)); }
28
-
29
- test('mixed', function (done) {
30
- var fn = react();
31
- var errors = fn.setAndValidateAST({
32
- inParams: ['res', 'prefstr', 'poststr'],
33
- tasks: [
34
- { f: load, a: ['res'], out: ['lres'] },
35
- { f: upper, a: ['lres'], out: ['ulres'], type: 'ret' },
36
- { f: prefix, a: ['prefstr', 'ulres'], out: ['plres'] },
37
- { f: postfix, a: ['plres', 'poststr'], out: ['plresp'] }
38
- ],
39
- outTask: { a: ['plresp'] }
40
- });
41
-
42
- t.deepEqual(errors, []);
43
-
44
- fn('foo', 'pre-', '-post', function cb(err, lres) {
45
- t.equal(err, null);
46
- t.equal(lres, 'pre-FOO-LOADED-post');
47
- });
48
-
49
- fn('bar', 'PRE-', '-POST', function cb(err, lres) {
50
- t.equal(err, null);
51
- t.equal(lres, 'PRE-BAR-LOADED-POST');
52
- done();
53
- });
54
- });
55
-
56
- test('ast.defined event called when ast is defined', function (done) {
57
- var fn = react();
58
- var collector = react.createEventCollector();
59
- collector.capture(fn, 'ast.*');
60
-
61
- var errors = fn.setAndValidateAST({
62
- inParams: ['res', 'prefstr', 'poststr'],
63
- tasks: [
64
- { f: load, a: ['res'], out: ['lres'] },
65
- { f: upper, a: ['lres'], out: ['ulres'], type: 'ret' },
66
- { f: prefix, a: ['prefstr', 'ulres'], out: ['plres'] },
67
- { f: postfix, a: ['plres', 'poststr'], out: ['plresp'] }
68
- ],
69
- outTask: { a: ['plresp'] }
70
- });
71
-
72
- var events = collector.list();
73
- t.equal(events.length, 1);
74
- t.isObject(events[0].ast);
75
- t.isNotNull(events[0].ast.inParams);
76
- t.isNotNull(events[0].ast.tasks);
77
- t.isNotNull(events[0].ast.outTask);
78
- done();
79
- });
80
-
81
- test('ast.defined event is passed to process', function (done) {
82
- // browser might not have this, so only if process is an eventemitter
83
- if (typeof process !== 'undefined' && process && process.once) {
84
- var fn = react();
85
- process.once('ast.defined', function (ast) {
86
- t.isObject(ast);
87
- t.isNotNull(ast.inParams);
88
- t.isNotNull(ast.tasks);
89
- t.isNotNull(ast.outTask);
90
- t.deepEqual(ast.inParams, ['res', 'prefstr', 'poststr']);
91
- done();
92
- });
93
- var errors = fn.setAndValidateAST({
94
- inParams: ['res', 'prefstr', 'poststr'],
95
- tasks: [
96
- { f: load, a: ['res'], out: ['lres'] },
97
- { f: upper, a: ['lres'], out: ['ulres'], type: 'ret' },
98
- { f: prefix, a: ['prefstr', 'ulres'], out: ['plres'] },
99
- { f: postfix, a: ['plres', 'poststr'], out: ['plresp'] }
100
- ],
101
- outTask: { a: ['plresp'] }
102
- });
103
- } else {
104
- done(); //skipping in browser
105
- }
106
- });
107
-
108
- test('cb with err', function (done) {
109
- var fn = react();
110
- var errors = fn.setAndValidateAST({
111
- inParams: ['res', 'prefstr', 'poststr'],
112
- tasks: [
113
- { f: load, a: ['res'], out: ['lres'] },
114
- { f: upper, a: ['lres'], out: ['ulres'], type: 'ret' },
115
- { f: makeError, a: ['ulres'], out: ['na'] },
116
- { f: prefix, a: ['prefstr', 'na'], out: ['plres'] },
117
- { f: postfix, a: ['plres', 'poststr'], out: ['plresp'] }
118
- ],
119
- outTask: { a: ['plresp'] }
120
- });
121
-
122
- t.deepEqual(errors, []);
123
-
124
- fn('foo', 'pre-', '-post', function cb(err, lres) {
125
- t.equal(err.message, 'makeErr-FOO-LOADED');
126
- t.equal(lres, undefined);
127
- });
128
-
129
- fn('bar', 'PRE-', '-POST', function cb(err, lres) {
130
- t.equal(err.message, 'makeErr-BAR-LOADED');
131
- t.equal(lres, undefined);
132
- done();
133
- });
134
- });
135
-
136
- }());