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/doc/color-def.png DELETED
Binary file
package/doc/simple.dot DELETED
@@ -1,25 +0,0 @@
1
- digraph loadRender {
2
- loadRender_input [ shape = box, style = filled, fillcolor = aquamarine ];
3
- fooPath [ style = filled, fillcolor = gainsboro ];
4
- barPath [ style = filled, fillcolor = gainsboro ];
5
- barP2 [ style = filled, fillcolor = gainsboro ];
6
- loadFoo [ shape = box, color = blue, fillcolor = beige, style = filled ];
7
- foo [ style = filled, fillcolor = gainsboro ];
8
- loadBar [ shape = box, color = blue, fillcolor = beige, style = filled ];
9
- bar [ style = filled, fillcolor = gainsboro ];
10
- render [ shape = box, color = blue, fillcolor = beige, style = filled ];
11
- renderedOut [ style = filled, fillcolor = gainsboro ];
12
- loadRender_output [ shape = box, style = filled, fillcolor = aquamarine ];
13
- loadRender_input -> fooPath;
14
- loadRender_input -> barPath;
15
- loadRender_input -> barP2;
16
- fooPath -> loadFoo;
17
- loadFoo -> foo;
18
- barPath -> loadBar;
19
- barP2 -> loadBar;
20
- loadBar -> bar;
21
- foo -> render;
22
- bar -> render;
23
- render -> renderedOut;
24
- renderedOut -> loadRender_output;
25
- }
package/doc/simple.png DELETED
Binary file
@@ -1,41 +0,0 @@
1
- 'use strict';
2
- /*jshint white: false */
3
-
4
- var react = require('../'); // require('react');
5
-
6
- function loadUser(uid, cb){ setTimeout(cb, 100, null, "User"+uid); }
7
- function loadFile(filename, cb){ setTimeout(cb, 100, null, 'Filedata'+filename); }
8
- function markdown(filedata) { return 'html'+filedata; }
9
- function prepareDirectory(outDirname, cb){ setTimeout(cb, 200, null, 'dircreated-'+outDirname); }
10
- function writeOutput(html, user, cb){ setTimeout(cb, 300, null, html+'_bytesWritten'); }
11
- function loadEmailTemplate(cb) { setTimeout(cb, 50, null, 'emailmd'); }
12
- function customizeEmail(user, emailHtml) { return 'cust-'+user+emailHtml; }
13
- function deliverEmail(custEmailHtml, cb) { setTimeout(cb, 100, null, 'delivered-'+custEmailHtml); }
14
-
15
- function useHtml(err, html, user, bytesWritten) {
16
- if (err) {
17
- console.log('***Error: %s', err);
18
- console.error(err.stack);
19
- return;
20
- }
21
- console.log('final result: %s, user: %s, written:%s', html, user, bytesWritten);
22
- }
23
-
24
- // define fn, glue together with react, it will parallelize
25
- // starts with name and in/out params, then the tasks
26
- var loadAndSave = react('loadAndSave', 'filename, uid, outDir, cb -> err, html, user, bytes',
27
- loadUser, 'uid, cb -> err, user', // calling async loadUser with uid, cb called with err and user
28
- loadFile, 'filename, cb -> err, filedata',
29
- markdown, 'filedata -> html', // using a sync function
30
- prepareDirectory, 'outDir, cb -> err, dircreated',
31
- writeOutput, 'html, user, cb -> err, bytes', { after: prepareDirectory }, // only after prepareDirectory done
32
- loadEmailTemplate, 'cb -> err, emailmd',
33
- markdown, 'emailmd -> emailHtml', // using a sync function
34
- customizeEmail, 'user, emailHtml -> custEmailHtml', // sync function
35
- deliverEmail, 'custEmailHtml, cb -> err, deliveredEmail', { after: writeOutput } // only after writeOutput is done
36
- );
37
-
38
- //in another module you can use this as any other exported fn
39
- loadAndSave('file.md', 100, '/tmp/foo', useHtml); // executing the flow
40
-
41
-
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- Simple example showing flow definition of two async functions feeding a
5
- synchronous function.
6
-
7
- First two async functions inputs are satisfied by the flow inputs, so
8
- they will both run immediately in parallel.
9
-
10
- The last function waits for the outputs of the previous ones, then
11
- executes synchronously.
12
-
13
- Finally the flow calls the callback with the output values once all
14
- the tasks have completed.
15
- */
16
-
17
- var react = require('../'); // require('react');
18
-
19
- function loadFoo(fooPath, cb) {
20
- setTimeout(function () {
21
- cb(null, [fooPath, 'data'].join(':'));
22
- }, 10);
23
- }
24
-
25
- function loadBar(barPath, barP2, cb) {
26
- setTimeout(function () {
27
- cb(null, [barPath, barP2, 'data'].join(':'));
28
- }, 10);
29
- }
30
-
31
- function render(foo, bar) {
32
- return ['<html>', foo, '/', bar, '</html>'].join('');
33
- }
34
-
35
-
36
- var fn = react('loadRender', 'fooPath, barPath, barP2, cb -> err, renderedOut',
37
- loadFoo, 'fooPath, cb -> err, foo',
38
- loadBar, 'barPath, barP2, cb -> err, bar',
39
- render, 'foo, bar -> renderedOut'
40
- );
41
-
42
-
43
- fn('foo.txt', 'bar.txt', 'BBB', function (err, renderedOut) {
44
- console.error('results:', renderedOut);
45
- });
@@ -1,30 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- Advanced example using the AST directly which most users will not do.
5
- For general use, see other examples like simple.js
6
- */
7
- var react = require('../'); // require('react');
8
-
9
- function load(res, cb) { setTimeout(cb, 100, null, res + '-loaded'); }
10
- function prefix(prefstr, str, cb) { setTimeout(cb, 100, null, prefstr + str); }
11
- function postfix(str, poststr, cb) { setTimeout(cb, 100, null, str + poststr); }
12
- function upper(str) { return str.toUpperCase(); }
13
-
14
- var fn = react();
15
- var errors = fn.setAndValidateAST({
16
- inParams: ['res', 'prefstr', 'poststr'],
17
- tasks: [
18
- { f: load, a: ['res'], out: ['lres'] },
19
- { f: upper, a: ['lres'], out: ['ulres'], type: 'ret' },
20
- { f: prefix, a: ['prefstr', 'ulres'], out: ['plres'] },
21
- { f: postfix, a: ['plres', 'poststr'], out: ['plresp'] }
22
- ],
23
- outTask: { a: ['plresp'] }
24
- });
25
- console.error('errors:', errors); // []
26
-
27
- fn('foo', 'pre-', '-post', function cb(err, lres) {
28
- console.error('err:', err); // null
29
- console.error('lres:', lres); // pre-FOO-LOADED-post
30
- });
@@ -1,79 +0,0 @@
1
- 'use strict';
2
- /*jshint white: false */
3
-
4
- /**
5
- Default DSL, showing use of events
6
- */
7
-
8
- var react = require('../'); // require('react');
9
- react.trackTasks(); // turn on flow and task tracking events
10
-
11
- //output events as tasks start and complete
12
- react.events.on('flow.*', function (obj) {
13
- /*jshint validthis: true */
14
- var time = new Date();
15
- time.setTime(obj.time);
16
- var argsNoCb = obj.args.filter(function (a) { return (typeof(a) !== 'function'); });
17
- var eventTimeStr = time.toISOString();
18
- if (this.event === 'flow.complete') {
19
- var env = obj;
20
- console.error('%s: %s \tmsecs:(%s) \n\targs:(%s) \n\tresults:(%s)\n',
21
- this.event, env.name, env.elapsedTime, argsNoCb, env.results);
22
- } else {
23
- var name = obj.name;
24
- var args = obj.args;
25
- console.error('%s: %s \n\targs:(%s)\n', this.event, name, argsNoCb);
26
- }
27
- });
28
-
29
- react.events.on('task.*', function (obj) {
30
- /*jshint validthis: true */
31
- var time = new Date();
32
- time.setTime(obj.time);
33
- var argsNoCb = obj.args.filter(function (a) { return (typeof(a) !== 'function'); });
34
- var eventTimeStr = time.toISOString();
35
- if (this.event === 'task.complete') {
36
- var task = obj;
37
- console.error('%s: %s \tmsecs:(%s) \n\targs:(%s) \n\tresults:(%s)\n',
38
- this.event, task.name, task.elapsedTime, argsNoCb, task.results);
39
- } else {
40
- var name = obj.name;
41
- var args = obj.args;
42
- console.error('%s: %s \n\targs:(%s)\n', this.event, name, argsNoCb);
43
- }
44
- });
45
-
46
-
47
-
48
- function loadUser(uid, cb){ setTimeout(cb, 100, null, "User"+uid); }
49
- function loadFile(filename, cb){ setTimeout(cb, 100, null, 'Filedata'+filename); }
50
- function markdown(filedata) { return 'html'+filedata; }
51
- function prepareDirectory(outDirname, cb){ setTimeout(cb, 200, null, 'dircreated-'+outDirname); }
52
- function writeOutput(html, user, cb){ setTimeout(cb, 300, null, html+'_bytesWritten'); }
53
- function loadEmailTemplate(cb) { setTimeout(cb, 50, null, 'emailmd'); }
54
- function customizeEmail(user, emailHtml) { return 'cust-'+user+emailHtml; }
55
- function deliverEmail(custEmailHtml, cb) { setTimeout(cb, 100, null, 'delivered-'+custEmailHtml); }
56
-
57
- function useHtml(err, html, user, bytesWritten) {
58
- if (err) {
59
- console.log('***Error: %s', err);
60
- return;
61
- }
62
- console.log('final result: %s, user: %s, written:%s', html, user, bytesWritten);
63
- }
64
-
65
- var loadAndSave = react('loadAndSave', 'filename, uid, outDirname, cb -> err, html, user, bytesWritten', // name, in/out params
66
- loadUser, 'uid, cb -> err, user', // calling async fn loadUser with uid, callback is called with err and user
67
- loadFile, 'filename, cb -> err, filedata',
68
- markdown, 'filedata -> html', // using a sync function
69
- prepareDirectory, 'outDirname, cb -> err, dircreated',
70
- writeOutput, 'html, user, cb -> err, bytesWritten', { after: prepareDirectory }, // only after prepareDirectory done
71
- loadEmailTemplate, 'cb -> err, emailmd',
72
- markdown, 'emailmd -> emailHtml', // using a sync function
73
- customizeEmail, 'user, emailHtml -> custEmailHtml', // sync fn
74
- deliverEmail, 'custEmailHtml, cb -> err, deliveredEmail', { after: writeOutput } // only after writeOutput is done
75
- );
76
-
77
- loadAndSave('file.md', 100, '/tmp/foo', useHtml); // executing the flow
78
-
79
-
@@ -1,43 +0,0 @@
1
- 'use strict';
2
- /*jshint white: false */
3
-
4
- /**
5
- Default DSL, showing use of events
6
- */
7
-
8
- var react = require('../'); // require('react');
9
- react.logEvents(); // turn on logging of all flow and task events for all react functions
10
-
11
-
12
- function loadUser(uid, cb){ setTimeout(cb, 100, null, "User"+uid); }
13
- function loadFile(filename, cb){ setTimeout(cb, 100, null, 'Filedata'+filename); }
14
- function markdown(filedata) { return 'html'+filedata; }
15
- function prepareDirectory(outDirname, cb){ setTimeout(cb, 200, null, 'dircreated-'+outDirname); }
16
- function writeOutput(html, user, cb){ setTimeout(cb, 300, null, html+'_bytesWritten'); }
17
- function loadEmailTemplate(cb) { setTimeout(cb, 50, null, 'emailmd'); }
18
- function customizeEmail(user, emailHtml) { return 'cust-'+user+emailHtml; }
19
- function deliverEmail(custEmailHtml, cb) { setTimeout(cb, 100, null, 'delivered-'+custEmailHtml); }
20
-
21
- function useHtml(err, html, user, bytesWritten) {
22
- if (err) {
23
- console.log('***Error: %s', err);
24
- return;
25
- }
26
- console.log('final result: %s, user: %s, written:%s', html, user, bytesWritten);
27
- }
28
-
29
- var loadAndSave = react('loadAndSave', 'filename, uid, outDirname, cb -> err, html, user, bytesWritten', // name, in/out params
30
- loadUser, 'uid, cb -> err, user', // calling async fn loadUser with uid, callback is called with err and user
31
- loadFile, 'filename, cb -> err, filedata',
32
- markdown, 'filedata -> html', // using a sync function
33
- prepareDirectory, 'outDirname, cb -> err, dircreated',
34
- writeOutput, 'html, user, cb -> err, bytesWritten', { after: prepareDirectory }, // only after prepareDirectory done
35
- loadEmailTemplate, 'cb -> err, emailmd',
36
- markdown, 'emailmd -> emailHtml', // using a sync function
37
- customizeEmail, 'user, emailHtml -> custEmailHtml', // sync fn
38
- deliverEmail, 'custEmailHtml, cb -> err, deliveredEmail', { after: writeOutput } // only after writeOutput is done
39
- );
40
-
41
- loadAndSave('file.md', 100, '/tmp/foo', useHtml); // executing the flow
42
-
43
-
package/lib/base-task.js DELETED
@@ -1,120 +0,0 @@
1
- /*global define:true */
2
-
3
- if (typeof define !== 'function') {
4
- var define = require('amdefine')(module);
5
- }
6
-
7
- define(['ensure-array', './status', './event-manager'],
8
- function (array, STATUS, EventManager) {
9
- 'use strict';
10
-
11
- function BaseTask() {
12
- }
13
-
14
- /**
15
- Getter Fn to retrieveAn array of the output param names for this task.
16
- */
17
- BaseTask.prototype.getOutParams = function () {
18
- return array(this.out); // ensure array
19
- };
20
-
21
- BaseTask.prototype.isComplete = function () {
22
- return (this.status === STATUS.COMPLETE);
23
- };
24
-
25
- BaseTask.prototype.start = function (args) { // mark task as started with args and note time
26
- /*jshint validthis: true */
27
- this.args = args;
28
- this.env.currentTask = this;
29
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_START, this);
30
- };
31
-
32
- BaseTask.prototype.complete = function (args) { //args that were used are available
33
- /*jshint validthis: true */
34
- this.status = STATUS.COMPLETE;
35
- this.results = args;
36
- this.env.currentTask = this;
37
- this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_COMPLETE, this);
38
- };
39
-
40
- BaseTask.prototype.functionExists = function (vCon) {
41
- var fn = this.f;
42
- if (!fn) return false;
43
- if (fn instanceof Function) return true;
44
- if (typeof(fn) === 'string') {
45
- var f = vCon.getVar(fn); // fn/method by string
46
- if (f && f instanceof Function) return true;
47
- }
48
- return false;
49
- };
50
-
51
- BaseTask.prototype.areAllDepArgsDefined = function (vCon) {
52
- return this.a.every(function (k) { return (vCon.getVar(k) !== undefined); });
53
- };
54
-
55
- BaseTask.prototype.depTasksAreDone = function (tasksByName) {
56
- return (!this.after || !this.after.length || // no dep tasks OR
57
- this.after.every(function (n) { return tasksByName[n].isComplete(); })); //all done
58
- };
59
-
60
- function isObjProperty(str) { return (str.indexOf('.') !== -1); }
61
-
62
- /**
63
- check that obj parent is def and not null so writing to obj.prop
64
- will not fail. ex: 'b.c' checks that b is def and not null.
65
- Also returns true if not obj.prop but simple var ex: 'b'.
66
- Tasks will implement outParentsExist() passing each out str
67
- to this if they want to do this check.
68
- */
69
- BaseTask.prototype.parentExists = function (objPropStr, vCon) {
70
- if (!isObjProperty(objPropStr)) return true; // NOT obj prop, just simple arg, ret true
71
- var nameAndProps = objPropStr.split('.');
72
- nameAndProps.pop(); // pop off final prop
73
- var parent = nameAndProps.reduce(function (accObj, prop) {
74
- if (accObj === undefined || accObj === null) return undefined; // prevent exception
75
- return accObj[prop];
76
- }, vCon.values); // vCon['foo']['bar']
77
- return (parent !== undefined && parent !== null);
78
- };
79
-
80
- /**
81
- If params are obj property writes make sure the dst objects
82
- are defined and not null. cb: ['b.c'] -> b is def and not null.
83
- If null is specified then param is valid and will be ignored.
84
- @returns true if all obj prop parents are def and non null
85
- */
86
- BaseTask.prototype.outParentsExist = function (vCon) {
87
- var self = this;
88
- return this.getOutParams().every(function (x) {
89
- if (x === null) return true;
90
- return self.parentExists(x, vCon);
91
- });
92
- };
93
-
94
- BaseTask.prototype.isReady = function (vCon, tasksByName) {
95
- return !this.status && // not started AND
96
- this.functionExists(vCon) && // function/method exists AND
97
- this.areAllDepArgsDefined(vCon) && // all dep vars defined AND
98
- this.depTasksAreDone(tasksByName) && // all dep tasks are done AND
99
- (!this.outParentsExist || // (task does not implement outParentsExist method OR
100
- this.outParentsExist(vCon)); // output parents exists (for obj property writes)
101
- };
102
-
103
- BaseTask.prototype.isMethodCall = function () {
104
- /*jshint regexp: false */
105
- return (typeof(this.f) === 'string' && /^.*\..*$/.test(this.f)); //str contains .
106
- };
107
-
108
- BaseTask.prototype.getMethodObj = function (vCon) { //obj.prop.prop2, returns obj.prop or undefined
109
- var name = this.f;
110
- if (!name) return undefined;
111
- var nameAndProps = name.split('.');
112
- nameAndProps.pop(); // pop off last one
113
- if (!nameAndProps.length) return undefined;
114
- var result = vCon.resolveNameArr(nameAndProps);
115
- return result;
116
- };
117
-
118
- return BaseTask;
119
-
120
- });
package/lib/cb-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
- function format_error(errmsg, obj) {
11
- return sprintf('%s - %s', errmsg, util.inspect(obj));
12
- }
13
-
14
- var REQ = 'cbTask requires f, a, out';
15
- var FN_REQ = 'cbTask requires f to be a function or string';
16
- var A_REQ = 'cbTask requires a to be an array of string param names';
17
- var CB_REQ = 'cbTask requires out to be an array of string param names';
18
-
19
- function CbTask(taskDef) {
20
- var self = this;
21
- Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
22
- }
23
-
24
- CbTask.prototype = new BaseTask();
25
- CbTask.prototype.constructor = CbTask;
26
-
27
- CbTask.validate = function (taskDef) {
28
- var errors = [];
29
- if (!taskDef.f || !taskDef.a || !taskDef.out) {
30
- errors.push(format_error(REQ, taskDef));
31
- } else {
32
- var ftype = typeof(taskDef.f);
33
- if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
34
- errors.push(format_error(FN_REQ, taskDef));
35
- }
36
- if (! (Array.isArray(taskDef.a) &&
37
- taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
38
- errors.push(format_error(A_REQ, taskDef));
39
- }
40
- if (! (Array.isArray(taskDef.out) &&
41
- taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
42
- errors.push(format_error(CB_REQ, taskDef));
43
- }
44
- }
45
- return errors;
46
- };
47
-
48
- CbTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
49
- var self = this;
50
- this.cbFun = function (err, arg0, arg1, argn) {
51
- var args = Array.prototype.slice.call(arguments, 1);
52
- if (err) { handleTaskError(self, err); return; } //handle error and return, we are done
53
-
54
- //no error, save callback args to vCon context, then continue execution
55
- vCon.saveResults(self.out, args);
56
- self.complete(args);
57
- contExec();
58
- };
59
- };
60
-
61
- CbTask.prototype.exec = function exec(vCon, handleError, contExec) {
62
- try {
63
- var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
64
- //console.error('CbTask.exec.args=', args);
65
- //console.error('CbTask.exec.vCon=', vCon);
66
- this.start(args); //note the start time, args
67
- args.push(this.cbFun); // push callback fn on end
68
- var func = this.f;
69
- var bindObj = vCon.getVar('this'); //global space or the original this
70
- if (this.isMethodCall()) { //if method call then reset func and bindObj
71
- func = vCon.getVar(this.f);
72
- bindObj = this.getMethodObj(vCon);
73
- } else if (typeof(func) === 'string') {
74
- func = vCon.getVar(func); // we want the actual fn from this string
75
- }
76
- func.apply(bindObj, args);
77
- } catch (err) { //catch and handle the task error, calling final cb
78
- handleError(this, err);
79
- }
80
- };
81
-
82
- return CbTask;
83
-
84
- });