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.
- package/README.md +10 -231
- package/addons.js +1 -0
- package/lib/AutoFocusMixin.js +30 -0
- package/lib/CSSCore.js +115 -0
- package/lib/CSSProperty.js +121 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/ChangeEventPlugin.js +387 -0
- package/lib/ClientReactRootIndex.js +30 -0
- package/lib/CompositionEventPlugin.js +260 -0
- package/lib/DOMChildrenOperations.js +165 -0
- package/lib/DOMProperty.js +268 -0
- package/lib/DOMPropertyOperations.js +181 -0
- package/lib/Danger.js +187 -0
- package/lib/DefaultDOMPropertyConfig.js +203 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +145 -0
- package/lib/EventConstants.js +76 -0
- package/lib/EventListener.js +69 -0
- package/lib/EventPluginHub.js +293 -0
- package/lib/EventPluginRegistry.js +281 -0
- package/lib/EventPluginUtils.js +214 -0
- package/lib/EventPropagators.js +143 -0
- package/lib/ExecutionEnvironment.js +44 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueUtils.js +161 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +119 -0
- package/lib/React.js +95 -0
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/ReactCSSTransitionGroupChild.js +138 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +550 -0
- package/lib/ReactComponentBrowserEnvironment.js +158 -0
- package/lib/ReactComponentEnvironment.js +26 -0
- package/lib/ReactCompositeComponent.js +1455 -0
- package/lib/ReactContext.js +67 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +207 -0
- package/lib/ReactDOMButton.js +68 -0
- package/lib/ReactDOMComponent.js +399 -0
- package/lib/ReactDOMForm.js +59 -0
- package/lib/ReactDOMIDOperations.js +218 -0
- package/lib/ReactDOMImg.js +58 -0
- package/lib/ReactDOMInput.js +181 -0
- package/lib/ReactDOMOption.js +51 -0
- package/lib/ReactDOMSelect.js +179 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +140 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +115 -0
- package/lib/ReactDefaultPerf.js +244 -0
- package/lib/ReactDefaultPerfAnalysis.js +199 -0
- package/lib/ReactErrorUtils.js +37 -0
- package/lib/ReactEventEmitter.js +339 -0
- package/lib/ReactEventEmitterMixin.js +57 -0
- package/lib/ReactEventTopLevelCallback.js +149 -0
- package/lib/ReactInjection.js +39 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +338 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +641 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +425 -0
- package/lib/ReactMultiChildUpdateTypes.js +38 -0
- package/lib/ReactOwner.js +154 -0
- package/lib/ReactPerf.js +85 -0
- package/lib/ReactPropTransferer.js +147 -0
- package/lib/ReactPropTypeLocationNames.js +31 -0
- package/lib/ReactPropTypeLocations.js +29 -0
- package/lib/ReactPropTypes.js +359 -0
- package/lib/ReactPutListenerQueue.js +61 -0
- package/lib/ReactReconcileTransaction.js +181 -0
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +59 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTestUtils.js +394 -0
- package/lib/ReactTextComponent.js +99 -0
- package/lib/ReactTransitionChildMapping.js +106 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +187 -0
- package/lib/ReactUpdates.js +148 -0
- package/lib/ReactWithAddons.js +51 -0
- package/lib/SelectEventPlugin.js +200 -0
- package/lib/ServerReactRootIndex.js +36 -0
- package/lib/SimpleEventPlugin.js +413 -0
- package/lib/SyntheticClipboardEvent.js +51 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticDragEvent.js +44 -0
- package/lib/SyntheticEvent.js +164 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +58 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +66 -0
- package/lib/Transaction.js +276 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/cloneWithProps.js +59 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +91 -0
- package/lib/createFullPageComponent.js +63 -0
- package/lib/createNodesFromMarkup.js +93 -0
- package/lib/createObjectFrom.js +61 -0
- package/lib/cx.js +44 -0
- package/lib/dangerousStyleValue.js +57 -0
- package/lib/emptyFunction.js +43 -0
- package/lib/escapeTextForBrowser.js +47 -0
- package/lib/flattenChildren.js +57 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/getActiveElement.js +34 -0
- package/lib/getEventKey.js +85 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +118 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +42 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +62 -0
- package/lib/isEventSupported.js +70 -0
- package/lib/isNode.js +33 -0
- package/lib/isTextInputElement.js +49 -0
- package/lib/isTextNode.js +30 -0
- package/lib/joinClasses.js +44 -0
- package/lib/keyMirror.js +58 -0
- package/lib/keyOf.js +41 -0
- package/lib/memoizeStringOnly.js +39 -0
- package/lib/merge.js +37 -0
- package/lib/mergeHelpers.js +136 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/onlyChild.js +43 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/shouldUpdateReactComponent.js +58 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +189 -0
- package/lib/warning.js +48 -0
- package/package.json +33 -21
- package/react.js +1 -0
- package/.npmignore +0 -7
- package/.travis.yml +0 -7
- package/Jakefile.js +0 -39
- package/LICENSE +0 -19
- package/browser-test/dist.html +0 -90
- package/browser-test/index.html +0 -86
- package/browser-test/min.html +0 -90
- package/dist/react.js +0 -3141
- package/dist/react.min.js +0 -22
- package/doc/advanced.md +0 -174
- package/doc/color-def.graffle +0 -938
- package/doc/color-def.png +0 -0
- package/doc/simple.dot +0 -25
- package/doc/simple.png +0 -0
- package/examples/longer-example.js +0 -41
- package/examples/simple.js +0 -45
- package/examples/using-ast-directly.js +0 -30
- package/examples/using-events1.js +0 -79
- package/examples/using-log-events.js +0 -43
- package/lib/base-task.js +0 -120
- package/lib/cb-task.js +0 -84
- package/lib/core.js +0 -138
- package/lib/dsl.js +0 -138
- package/lib/error.js +0 -55
- package/lib/event-collector.js +0 -81
- package/lib/event-manager.js +0 -89
- package/lib/eventemitter.js +0 -20
- package/lib/finalcb-first-task.js +0 -68
- package/lib/finalcb-task.js +0 -65
- package/lib/id.js +0 -22
- package/lib/input-parser.js +0 -56
- package/lib/log-events.js +0 -101
- package/lib/parse.js +0 -41
- package/lib/promise-resolve.js +0 -50
- package/lib/promise-task.js +0 -93
- package/lib/react.js +0 -59
- package/lib/ret-task.js +0 -71
- package/lib/sprintf.js +0 -18
- package/lib/status.js +0 -14
- package/lib/task.js +0 -251
- package/lib/track-tasks.js +0 -74
- package/lib/validate.js +0 -159
- package/lib/vcon.js +0 -113
- package/lib/when-task.js +0 -84
- package/src/dist.build.requirejs +0 -20
- package/test/ast.mocha.js +0 -136
- package/test/cb-task.mocha.js +0 -220
- package/test/core-deferred.mocha.js +0 -143
- package/test/core-when.mocha.js +0 -96
- package/test/core.mocha.js +0 -589
- package/test/dsl.mocha.js +0 -352
- package/test/event-manager.mocha.js +0 -119
- package/test/exec-options.mocha.js +0 -48
- package/test/finalcb-task.mocha.js +0 -58
- package/test/input-parser.mocha.js +0 -86
- package/test/log-events.mocha.js +0 -88
- package/test/mocha.opts +0 -2
- package/test/module-use.mocha.js +0 -164
- package/test/promise-auto-resolve.mocha.js +0 -68
- package/test/ret-task.mocha.js +0 -220
- package/test/task.mocha.js +0 -42
- package/test/validate-cb-task.mocha.js +0 -100
- package/test/validate-ret-task.mocha.js +0 -110
- package/test/validate.mocha.js +0 -324
- package/test/vcon.mocha.js +0 -193
- package/vendor/chai/chai.js +0 -4251
- package/vendor/jquery/jquery-1.7.1.js +0 -9266
- package/vendor/jquery/jquery-1.7.1.min.js +0 -4
- package/vendor/node/util.js +0 -531
- package/vendor/requirejs/require.js +0 -2045
- 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
|
-
|
package/examples/simple.js
DELETED
|
@@ -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
|
-
});
|