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
@@ -1,20 +0,0 @@
1
- /*global define:true EventEmitter2:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['eventemitter2'], function (EventEmitterMod) {
8
- 'use strict';
9
-
10
- /**
11
- Abstract the details of getting an EventEmitter
12
- */
13
-
14
- // EventEmitter doesn't return itself in browser so need to get the global
15
- // EventEmitter api changed, so accomodate which ever version is available
16
- var EventEmitter = (EventEmitterMod) ?
17
- ((EventEmitterMod.EventEmitter2) ? EventEmitterMod.EventEmitter2 : EventEmitterMod) : EventEmitter2;
18
- return EventEmitter;
19
-
20
- });
@@ -1,68 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['./sprintf', 'util', './status', './vcon', './event-manager'],
8
- function (sprintf, util, STATUS, VContext, EventManager) {
9
- 'use strict';
10
-
11
- var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
12
-
13
- function FinalCbFirstSuccTask(outTaskOptions) {
14
- var taskDef = outTaskOptions.taskDef;
15
- if (typeof(outTaskOptions.cbFunc) !== 'function') throw new Error('callback is not a function');
16
- var self = this;
17
- for (var k in taskDef) {
18
- if (true) self[k] = taskDef[k]; // if to make jshint happy
19
- }
20
- this.f = outTaskOptions.cbFunc;
21
- this.tasks = outTaskOptions.tasks;
22
- this.vCon = outTaskOptions.vCon;
23
- this.retValue = outTaskOptions.retValue;
24
- this.env = outTaskOptions.env;
25
- }
26
-
27
- function format_error(errmsg, obj) {
28
- return sprintf('%s - %s', errmsg, util.inspect(obj));
29
- }
30
-
31
- FinalCbFirstSuccTask.validate = function (taskDef) {
32
- var errors = [];
33
- if (! (Array.isArray(taskDef.a) &&
34
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
35
- errors.push(format_error(OUTTASK_A_REQ, taskDef));
36
- }
37
- return errors;
38
- };
39
-
40
- /**
41
- is ready to exit when any task comes back with non-null defined value
42
- */
43
- FinalCbFirstSuccTask.prototype.isReady = function () {
44
- var lastres = this.vCon.getLastResults();
45
- if (!lastres) return false; // no results yet
46
- return (lastres.some(function (v) { return (v !== undefined && v !== null); }));
47
- };
48
-
49
- FinalCbFirstSuccTask.prototype.exec = function (err) {
50
- if (!this.f) return; //must have already been called
51
- if (err) {
52
- this.env.error = err;
53
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_ERRORED, this.env);
54
- this.f.call(null, err); //call the final callback with the first error hit
55
- } else { // no error, call with args
56
- var vCon = this.vCon;
57
- var finalArgs = this.a.map(function (k) { return vCon.getVar(k); });
58
- finalArgs.unshift(null); //unshift err=null to front
59
- this.env.results = finalArgs;
60
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_COMPLETE, this.env);
61
- this.f.apply(null, finalArgs);
62
- }
63
- this.f = null; // prevent multiple calls
64
- };
65
-
66
- return FinalCbFirstSuccTask;
67
-
68
- });
@@ -1,65 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['./sprintf', 'util', './status', './event-manager'],
8
- function (sprintf, util, STATUS, EventManager) {
9
- 'use strict';
10
-
11
- var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
12
-
13
- function FinalCbTask(outTaskOptions) {
14
- var taskDef = outTaskOptions.taskDef;
15
- if (typeof(outTaskOptions.cbFunc) !== 'function') throw new Error('callback is not a function');
16
- var self = this;
17
- for (var k in taskDef) {
18
- if (true) self[k] = taskDef[k]; // if to make jshint happy
19
- }
20
- this.f = outTaskOptions.cbFunc;
21
- this.tasks = outTaskOptions.tasks;
22
- this.vCon = outTaskOptions.vCon;
23
- this.retValue = outTaskOptions.retValue;
24
- this.execOptions = outTaskOptions.execOptions;
25
- this.env = outTaskOptions.env;
26
- }
27
-
28
- function format_error(errmsg, obj) {
29
- return sprintf('%s - %s', errmsg, util.inspect(obj));
30
- }
31
-
32
-
33
- FinalCbTask.validate = function (taskDef) {
34
- var errors = [];
35
- if (! (Array.isArray(taskDef.a) &&
36
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
37
- errors.push(format_error(OUTTASK_A_REQ, taskDef));
38
- }
39
- return errors;
40
- };
41
-
42
- FinalCbTask.prototype.isReady = function () {
43
- return (this.tasks.every(function (t) { return (t.status === STATUS.COMPLETE); }));
44
- };
45
-
46
- FinalCbTask.prototype.exec = function (err) {
47
- if (!this.f) return; //must have already been called
48
- if (err) {
49
- this.env.error = err;
50
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_ERRORED, this.env);
51
- this.f.call(null, err); //call the final callback with the first error hit
52
- } else { // no error, call with args
53
- var vCon = this.vCon;
54
- var finalArgs = this.a.map(function (k) { return vCon.getVar(k); });
55
- finalArgs.unshift(null); //unshift err=null to front
56
- this.env.results = finalArgs;
57
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_COMPLETE, this.env);
58
- this.f.apply(null, finalArgs);
59
- }
60
- this.f = null; // prevent multiple calls
61
- };
62
-
63
- return FinalCbTask;
64
-
65
- });
package/lib/id.js DELETED
@@ -1,22 +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 startingId = 0;
11
-
12
- function createUniqueId() {
13
- startingId += 1;
14
- if (startingId === Number.MAX_VALUE) startingId = 0; // if hits this start over //TODO need something better?
15
- return startingId;
16
- }
17
-
18
- return {
19
- createUniqueId: createUniqueId
20
- };
21
-
22
- });
@@ -1,56 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['./event-manager'], function (EventManager) {
8
- 'use strict';
9
-
10
- var defaultExecOptions = {
11
- reactExecOptions: true,
12
- outputStyle: 'cb',
13
- };
14
-
15
- var OUTPUT_STYLES = {
16
- CALLBACK: 'cb',
17
- NONE: 'none'
18
- };
19
-
20
- function isExecOptions(x) { return (x && x.reactExecOptions); }
21
- function execOptionsFilter(x) { return isExecOptions(x); }
22
- function nonExecOptionsFilter(x) { return !isExecOptions(x); }
23
- function mergeExecOptions(accum, options) {
24
- Object.keys(options).forEach(function (k) { accum[k] = options[k]; });
25
- return accum;
26
- }
27
-
28
- function splitArgs(args, inParams, style) {
29
- var result = { };
30
- result.args = inParams.map(function (p) { return args.shift(); }); // take args for input params first
31
- if (style === OUTPUT_STYLES.CALLBACK && args.length) result.cb = args.shift(); // next take the cb
32
- result.extra = args; // these remaining were after the callback
33
- return result;
34
- }
35
-
36
- function inputParser(inputArgs, ast) {
37
- var parsedInput = { };
38
- var execOptionsArr = inputArgs.filter(execOptionsFilter);
39
- execOptionsArr.unshift(defaultExecOptions);
40
- parsedInput.options = execOptionsArr.reduce(mergeExecOptions, {});
41
-
42
- var args = inputArgs.filter(nonExecOptionsFilter);
43
- var splitResult = splitArgs(args, ast.inParams, parsedInput.options.outputStyle);
44
- parsedInput.args = splitResult.args;
45
- parsedInput.cb = splitResult.cb;
46
- if (splitResult.outputStyle) parsedInput.options.outputStyle = splitResult.outputStyle;
47
- if (splitResult.extra) parsedInput.extraArgs = splitResult.extra;
48
- EventManager.global.emit(EventManager.TYPES.EXEC_INPUT_PREPROCESS, parsedInput); // hook
49
- return parsedInput;
50
- }
51
-
52
-
53
- inputParser.defaultExecOptions = defaultExecOptions;
54
- return inputParser;
55
-
56
- });
package/lib/log-events.js DELETED
@@ -1,101 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['util'], function (util) { // TODO replace util.inspect with something portable to browser
8
- 'use strict';
9
-
10
- var logEventsMod = { };
11
-
12
- /**
13
- Log events to console.error
14
-
15
- @example
16
- var react = require('react');
17
- react.logEvents(); // log all task and flow events on all react functions
18
- react.logEvents('task.*'); // log all task events on all react functions
19
- react.logEvents(flowFn); // log all task and flow events on flowFn only
20
- react.logEvents(flowFn, 'flow.*'); // log all flow events on flowFn only
21
- */
22
-
23
- var ALL_FLOW_EVENTS = 'flow.*';
24
- var ALL_TASK_EVENTS = 'task.*';
25
- var FLOW_RE = /^flow\./;
26
-
27
- function flowLog(obj) {
28
- /*jshint validthis: true */
29
- var time = new Date();
30
- time.setTime(obj.startTime);
31
- var argsNoCb = obj.args.filter(function (a) { return (typeof(a) !== 'function'); });
32
- var eventTimeStr = time.toISOString();
33
- if (this.event === 'flow.complete') {
34
- var env = obj;
35
- console.error('%s: %s \tmsecs: %s \n\targs: %s \n\tresults: %s\n',
36
- this.event, env.name, env.elapsedTime, util.inspect(argsNoCb), util.inspect(env.results));
37
- } else {
38
- var name = obj.name;
39
- var args = obj.args;
40
- console.error('%s: %s \n\targs: %s\n', this.event, name, util.inspect(argsNoCb));
41
- }
42
- }
43
-
44
- function taskLog(obj) {
45
- /*jshint validthis: true */
46
- var time = new Date();
47
- time.setTime(obj.startTime);
48
- var argsNoCb = obj.args.filter(function (a) { return (typeof(a) !== 'function'); });
49
- var eventTimeStr = time.toISOString();
50
- if (this.event === 'task.complete') {
51
- var task = obj;
52
- console.error('%s: %s:%s \tmsecs: %s \n\targs: %s \n\tresults: %s\n',
53
- this.event, task.env.name, task.name, task.elapsedTime, util.inspect(argsNoCb), util.inspect(task.results));
54
- } else {
55
- var name = obj.name;
56
- var args = obj.args;
57
- console.error('%s: %s:%s \n\targs: %s\n', this.event, obj.env.name, obj.name, util.inspect(argsNoCb));
58
- }
59
-
60
- }
61
-
62
- /**
63
- Log flow and task events for a flowFn or all of react.
64
- If called multiple times, remove previous listener (if any) before
65
- adding.
66
-
67
- @example
68
- var react = require('react');
69
- react.logEvents(flowFn, eventWildcard); //log events on flowfn matching wildcard
70
-
71
- @param flowFn Flow function or global react object
72
- @param eventWildcard wildcarded event type, if not provided use flow.* and task.*
73
- */
74
- function logEvents(flowFn, eventWildcard) {
75
- if (!flowFn) throw new Error('flowFn is required');
76
- if (!flowFn.events._loggingEvents) flowFn.events._loggingEvents = [];
77
- if (eventWildcard === false) { // turn off logging
78
- flowFn.events._loggingEvents.forEach(function (evt) {
79
- flowFn.events.removeAllListeners(evt);
80
- });
81
- flowFn.events._loggingEvents.length = 0; // clear
82
- } else if (eventWildcard && eventWildcard !== '*') {
83
- var logFn = (FLOW_RE.test(eventWildcard)) ? flowLog : taskLog;
84
- flowFn.events.removeListener(eventWildcard, logFn);
85
- flowFn.events.on(eventWildcard, logFn);
86
- flowFn.events._loggingEvents.push(eventWildcard);
87
- } else { // none provided, use flow.* and task.*
88
- //output events as tasks start and complete
89
- flowFn.events.removeListener(ALL_FLOW_EVENTS, flowLog);
90
- flowFn.events.on(ALL_FLOW_EVENTS, flowLog);
91
- flowFn.events._loggingEvents.push(ALL_FLOW_EVENTS);
92
- flowFn.events.removeListener(ALL_TASK_EVENTS, taskLog);
93
- flowFn.events.on(ALL_TASK_EVENTS, taskLog);
94
- flowFn.events._loggingEvents.push(ALL_TASK_EVENTS);
95
- }
96
- }
97
-
98
- logEventsMod.logEvents = logEvents;
99
- return logEventsMod;
100
-
101
- });
package/lib/parse.js DELETED
@@ -1,41 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['./sprintf'], function (sprintf) {
8
- 'use strict';
9
-
10
- function splitTrimFilterArgs(commaSepArgs) { //parse 'one, two' into ['one', 'two']
11
- if (!commaSepArgs) return [];
12
- return commaSepArgs.split(',') //split on commas
13
- .map(function (s) { return s.trim(); }) //trim
14
- .filter(function (s) { return (s); }); //filter out empty strings
15
- }
16
-
17
- /**
18
- @param patternFn regex + fn or splitStr + fn
19
- */
20
- function parseReduce(accum, patternFn) {
21
- if (typeof(accum) !== 'string') return accum; // already matched
22
- var m = (patternFn.regex) ? patternFn.regex.exec(accum) : accum.split(patternFn.splitStr);
23
- if (m) return patternFn.fn(m, accum); // pass in matches and origStr, return result obj
24
- return accum; // no match, return str, will try next matcher
25
- }
26
-
27
- function parseStr(str, parseMatchers, errStr) {
28
- var result = parseMatchers.reduce(parseReduce, str);
29
- if (typeof(result) !== 'string') { // matched
30
- return result;
31
- } else { // no match
32
- throw new Error(sprintf(errStr, str));
33
- }
34
- }
35
-
36
- return {
37
- splitTrimFilterArgs: splitTrimFilterArgs,
38
- parseStr: parseStr
39
- };
40
-
41
- });
@@ -1,50 +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
- /**
11
- Auto resolve promises passed in as arguments to the flow
12
-
13
- - Detects promises by checking for .then()
14
- - Create promise name for param (param__promise)
15
- - moves existing vCon promise into the param__promise
16
- - creates WhenTask which resolves param__promise into param
17
- */
18
-
19
-
20
- var PROMISE_SUFFIX = '__promise'; // added to param names that are promises
21
-
22
- var resolvingPromises = false;
23
-
24
- function resolvePromises(react) {
25
- if (resolvingPromises) return; // already resolving
26
- resolvingPromises = true;
27
-
28
- react.events.on(react.events.TYPES.EXEC_TASKS_PRECREATE, function (env) {
29
- var vConValues = env.vCon.values;
30
- var promiseParams = env.ast.inParams.filter(function (p) {
31
- var value = vConValues[p];
32
- return (value && typeof(value.then) === 'function');
33
- });
34
- promiseParams.forEach(function (p) {
35
- var promiseName = p + PROMISE_SUFFIX;
36
- vConValues[promiseName] = vConValues[p];
37
- vConValues[p] = undefined;
38
- env.taskDefs.push({
39
- type: 'when',
40
- a: [promiseName],
41
- out: [p]
42
- });
43
- });
44
- });
45
-
46
- }
47
-
48
- return resolvePromises;
49
-
50
- });
@@ -1,93 +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
- PromiseTask is a task which executes a fn that returns a promise
12
- and when it completes it sets the values in vCon
13
- */
14
-
15
- function format_error(errmsg, obj) {
16
- return sprintf('%s - %s', errmsg, util.inspect(obj));
17
- }
18
-
19
- var REQ = 'promiseTask requires f, a, out';
20
- var FN_REQ = 'promiseTask requires f to be a function or string';
21
- var A_REQ = 'promiseTask requires a to be an array of string param names';
22
- var OUT_REQ = 'promiseTask requires out to be an array[1] of string param names';
23
-
24
- function PromiseTask(taskDef) {
25
- var self = this;
26
- Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
27
- }
28
-
29
- PromiseTask.prototype = new BaseTask();
30
- PromiseTask.prototype.constructor = PromiseTask;
31
-
32
- PromiseTask.validate = function (taskDef) {
33
- var errors = [];
34
- if (!taskDef.f || !taskDef.a || !taskDef.out) {
35
- errors.push(format_error(REQ, taskDef));
36
- } else {
37
- var ftype = typeof(taskDef.f);
38
- if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
39
- errors.push(format_error(FN_REQ, taskDef));
40
- }
41
- if (! (Array.isArray(taskDef.a) &&
42
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
43
- errors.push(format_error(A_REQ, taskDef));
44
- }
45
- if (! (Array.isArray(taskDef.out) && taskDef.out.length <= 1 &&
46
- taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
47
- errors.push(format_error(OUT_REQ, taskDef));
48
- }
49
- }
50
- return errors;
51
- };
52
-
53
- PromiseTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
54
- var self = this;
55
- this.nextFn = function (arg) {
56
- var args = Array.prototype.slice.call(arguments);
57
- vCon.saveResults(self.out, args);
58
- self.complete(args);
59
- contExec();
60
- };
61
- this.failFn = function (err) {
62
- handleTaskError(self, err);
63
- };
64
- };
65
-
66
- PromiseTask.prototype.exec = function exec(vCon, handleError, contExec) {
67
- try {
68
- var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
69
- //console.error('PromiseTask.exec.args=', args);
70
- //console.error('PromiseTask.exec.vCon=', vCon);
71
- this.start(args); //note the start time, args
72
- var func = this.f;
73
- var bindObj = vCon.getVar('this'); //global space or the original this
74
- if (this.isMethodCall()) { //if method call then reset func and bindObj
75
- func = vCon.getVar(this.f);
76
- bindObj = this.getMethodObj(vCon);
77
- } else if (typeof(func) === 'string') {
78
- func = vCon.getVar(func); // we want the actual fn from this string
79
- }
80
- var retValue = func.apply(bindObj, args);
81
- if (retValue && typeof(retValue.then) === 'function') { // is a promise
82
- retValue.then(this.nextFn, this.failFn);
83
- } else { // just a value, proceed now
84
- this.nextFn(retValue);
85
- }
86
- } catch (err) { //catch and handle the task error, calling final cb
87
- handleError(this, err);
88
- }
89
- };
90
-
91
- return PromiseTask;
92
-
93
- });