react 0.7.1 → 0.8.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 +15 -228
- package/ReactJSErrors.js +40 -0
- package/addons.js +4 -0
- package/lib/$.js +46 -0
- package/lib/CSSCore.js +114 -0
- package/lib/CSSProperty.js +90 -0
- package/lib/CSSPropertyOperations.js +97 -0
- package/lib/CallbackRegistry.js +91 -0
- package/lib/ChangeEventPlugin.js +365 -0
- package/lib/CompositionEventPlugin.js +212 -0
- package/lib/DOMChildrenOperations.js +135 -0
- package/lib/DOMProperty.js +266 -0
- package/lib/DOMPropertyOperations.js +168 -0
- package/lib/Danger.js +186 -0
- package/lib/DefaultDOMPropertyConfig.js +187 -0
- package/lib/DefaultEventPluginOrder.js +44 -0
- package/lib/EnterLeaveEventPlugin.js +112 -0
- package/lib/EventConstants.js +73 -0
- package/lib/EventListener.js +61 -0
- package/lib/EventPluginHub.js +190 -0
- package/lib/EventPluginRegistry.js +237 -0
- package/lib/EventPluginUtils.js +185 -0
- package/lib/EventPropagators.js +179 -0
- package/lib/ExecutionEnvironment.js +41 -0
- package/lib/LinkedStateMixin.js +46 -0
- package/lib/LinkedValueMixin.js +68 -0
- package/lib/MobileSafariClickEventPlugin.js +63 -0
- package/lib/PooledClass.js +113 -0
- package/lib/React.js +71 -0
- package/lib/ReactChildren.js +132 -0
- package/lib/ReactComponent.js +515 -0
- package/lib/ReactComponentBrowserEnvironment.js +140 -0
- package/lib/ReactComponentEnvironment.js +24 -0
- package/lib/ReactCompositeComponent.js +1020 -0
- package/lib/ReactCurrentOwner.js +39 -0
- package/lib/ReactDOM.js +194 -0
- package/lib/ReactDOMButton.js +64 -0
- package/lib/ReactDOMComponent.js +374 -0
- package/lib/ReactDOMForm.js +52 -0
- package/lib/ReactDOMIDOperations.js +173 -0
- package/lib/ReactDOMInput.js +169 -0
- package/lib/ReactDOMOption.js +50 -0
- package/lib/ReactDOMSelect.js +160 -0
- package/lib/ReactDOMSelection.js +189 -0
- package/lib/ReactDOMTextarea.js +136 -0
- package/lib/ReactDefaultBatchingStrategy.js +75 -0
- package/lib/ReactDefaultInjection.js +91 -0
- package/lib/ReactDefaultPerf.js +407 -0
- package/lib/ReactErrorUtils.js +46 -0
- package/lib/ReactEventEmitter.js +341 -0
- package/lib/ReactEventEmitterMixin.js +89 -0
- package/lib/ReactEventTopLevelCallback.js +89 -0
- package/lib/ReactInputSelection.js +140 -0
- package/lib/ReactInstanceHandles.js +322 -0
- package/lib/ReactLink.js +54 -0
- package/lib/ReactMarkupChecksum.js +53 -0
- package/lib/ReactMount.js +617 -0
- package/lib/ReactMountReady.js +95 -0
- package/lib/ReactMultiChild.js +441 -0
- package/lib/ReactMultiChildUpdateTypes.js +36 -0
- package/lib/ReactOwner.js +146 -0
- package/lib/ReactPerf.js +88 -0
- package/lib/ReactPropTransferer.js +128 -0
- package/lib/ReactPropTypes.js +158 -0
- package/lib/ReactReconcileTransaction.js +161 -0
- package/lib/ReactServerRendering.js +62 -0
- package/lib/ReactStateSetters.js +111 -0
- package/lib/ReactTextComponent.js +94 -0
- package/lib/ReactTransitionEvents.js +97 -0
- package/lib/ReactTransitionGroup.js +112 -0
- package/lib/ReactTransitionKeySet.js +111 -0
- package/lib/ReactTransitionableChild.js +152 -0
- package/lib/ReactUpdates.js +145 -0
- package/lib/ReactWithAddons.js +41 -0
- package/lib/SelectEventPlugin.js +217 -0
- package/lib/SimpleEventPlugin.js +365 -0
- package/lib/SyntheticClipboardEvent.js +45 -0
- package/lib/SyntheticCompositionEvent.js +51 -0
- package/lib/SyntheticEvent.js +163 -0
- package/lib/SyntheticFocusEvent.js +44 -0
- package/lib/SyntheticKeyboardEvent.js +56 -0
- package/lib/SyntheticMouseEvent.js +85 -0
- package/lib/SyntheticTouchEvent.js +50 -0
- package/lib/SyntheticUIEvent.js +45 -0
- package/lib/SyntheticWheelEvent.js +63 -0
- package/lib/Transaction.js +251 -0
- package/lib/ViewportMetrics.js +37 -0
- package/lib/accumulate.js +54 -0
- package/lib/adler32.js +39 -0
- package/lib/containsNode.js +49 -0
- package/lib/copyProperties.js +54 -0
- package/lib/createArrayFrom.js +94 -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/ex.js +49 -0
- package/lib/filterAttributes.js +45 -0
- package/lib/flattenChildren.js +54 -0
- package/lib/forEachAccumulated.js +36 -0
- package/lib/ge.js +76 -0
- package/lib/getActiveElement.js +33 -0
- package/lib/getEventTarget.js +36 -0
- package/lib/getMarkupWrap.js +108 -0
- package/lib/getNodeForCharacterOffset.js +80 -0
- package/lib/getReactRootElementInContainer.js +40 -0
- package/lib/getTextContentAccessor.js +40 -0
- package/lib/getUnboundedScrollPosition.js +45 -0
- package/lib/hyphenate.js +35 -0
- package/lib/invariant.js +54 -0
- package/lib/isEventSupported.js +74 -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 +137 -0
- package/lib/mergeInto.js +45 -0
- package/lib/mixInto.js +34 -0
- package/lib/mutateHTMLNodeWithMarkup.js +100 -0
- package/lib/objMap.js +47 -0
- package/lib/objMapKeyVal.js +47 -0
- package/lib/performanceNow.js +42 -0
- package/lib/shallowEqual.js +49 -0
- package/lib/traverseAllChildren.js +127 -0
- package/package.json +33 -31
- package/react.js +4 -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 -175
- 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/package.json
CHANGED
|
@@ -1,36 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.7.1",
|
|
5
|
-
"author": "Jeff Barczewski <jeff.barczewski@gmail.com>",
|
|
6
|
-
"repository": { "type": "git", "url": "http://github.com/jeffbski/react.git" },
|
|
7
|
-
"bugs" : { "url": "http://github.com/jeffbski/react/issues" },
|
|
8
|
-
"licenses": [{ "type": "MIT", "url" : "http://github.com/jeffbski/react/raw/master/LICENSE" }],
|
|
9
|
-
"main": "lib/react",
|
|
10
|
-
"engines": { "node": ">=0.6" },
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"amdefine": "~0.0.5",
|
|
13
|
-
"eventemitter2": "~0.4.11",
|
|
14
|
-
"ensure-array": "~0.0.5"
|
|
15
|
-
},
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"requirejs": "~2.1.6",
|
|
18
|
-
"mocha": "~1.10.0",
|
|
19
|
-
"chai": "~1.6.0",
|
|
20
|
-
"jake": "~0.5.15",
|
|
21
|
-
"Deferred" : "~0.1.1"
|
|
22
|
-
},
|
|
3
|
+
"version": "0.8.0",
|
|
23
4
|
"keywords": [
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
5
|
+
"react"
|
|
6
|
+
],
|
|
7
|
+
"homepage": "https://github.com/facebook/react/tree/master/npm-react",
|
|
8
|
+
"bugs": "https://github.com/facebook/react/issues?labels=react-core",
|
|
9
|
+
"licenses": [
|
|
10
|
+
{
|
|
11
|
+
"type": "Apache-2.0",
|
|
12
|
+
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"files": [
|
|
16
|
+
"README.md",
|
|
17
|
+
"addons.js",
|
|
18
|
+
"react.js",
|
|
19
|
+
"ReactJSErrors.js",
|
|
20
|
+
"lib/"
|
|
32
21
|
],
|
|
33
|
-
"
|
|
34
|
-
|
|
22
|
+
"main": "react.js",
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/facebook/react"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=0.10.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"envify": "~0.2.0"
|
|
32
|
+
},
|
|
33
|
+
"browserify": {
|
|
34
|
+
"transform": [
|
|
35
|
+
"envify"
|
|
36
|
+
]
|
|
35
37
|
}
|
|
36
|
-
}
|
|
38
|
+
}
|
package/react.js
ADDED
package/.npmignore
DELETED
package/.travis.yml
DELETED
package/Jakefile.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/*global fail:false, complete:false, desc:false, jake:false, namespace:false, task:false */
|
|
3
|
-
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var child_process = require('child_process');
|
|
6
|
-
|
|
7
|
-
var REQUIREJS = path.resolve(__dirname, 'node_modules/requirejs/bin/r.js');
|
|
8
|
-
|
|
9
|
-
desc('Default - build all dist versions');
|
|
10
|
-
task('default', ['dist-all'], function (params) { });
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function runRequireJs(argStr) {
|
|
14
|
-
var proc = child_process.spawn(REQUIREJS, argStr.split(' '));
|
|
15
|
-
proc.stdout.pipe(process.stdout);
|
|
16
|
-
proc.stderr.pipe(process.stderr);
|
|
17
|
-
proc.on('exit', function (exitCode) {
|
|
18
|
-
if (exitCode !== 0) {
|
|
19
|
-
console.error('Child process exited with error code: %s, exiting', exitCode);
|
|
20
|
-
process.exit(exitCode);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
desc('Create core single-file developer dist');
|
|
26
|
-
task('dist', function () {
|
|
27
|
-
runRequireJs('-o src/dist.build.requirejs out=dist/react.js');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
desc('Create full single-file minified dist');
|
|
31
|
-
task('min', function () {
|
|
32
|
-
runRequireJs('-o src/dist.build.requirejs out=dist/react.min.js optimize=uglify');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
desc('Create all dist versions');
|
|
36
|
-
task('dist-all', ['dist', 'min']);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
package/LICENSE
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2011 Jeff Barczewski
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
package/browser-test/dist.html
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<meta charset="utf-8">
|
|
4
|
-
<title>Mocha Tests</title>
|
|
5
|
-
<link rel="stylesheet" href="../vendor/mocha/mocha.css" />
|
|
6
|
-
<script type="text/javascript" src="../vendor/jquery/jquery-1.7.1.js"></script>
|
|
7
|
-
<script type="text/javascript" src="../vendor/chai/chai.js"></script>
|
|
8
|
-
<script type="text/javascript" src="../vendor/mocha/mocha.js"></script>
|
|
9
|
-
<script>mocha.setup('qunit')</script>
|
|
10
|
-
<script src="../vendor/requirejs/require.min.js"></script>
|
|
11
|
-
<script type="text/javascript">
|
|
12
|
-
require.config({
|
|
13
|
-
baseUrl: "..",
|
|
14
|
-
packages: [
|
|
15
|
-
{
|
|
16
|
-
name: "react",
|
|
17
|
-
location: "dist",
|
|
18
|
-
main: "react"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
paths: {
|
|
22
|
-
jQuery: "vendor/jquery/jquery-1.7.1",
|
|
23
|
-
eventemitter2: "dist/react",
|
|
24
|
-
util: "dist/react",
|
|
25
|
-
"ensure-array": "dist/react",
|
|
26
|
-
test: "test"
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
require(["react", "jQuery"],
|
|
31
|
-
function (react, jquery) {
|
|
32
|
-
|
|
33
|
-
require(["react/sprintf", "react/validate", "react/task", "react/cb-task",
|
|
34
|
-
"react/vcon", "react/event-manager", "react/input-parser",
|
|
35
|
-
"react/base-task", "react/ret-task", "util"],
|
|
36
|
-
function (sprintf, validate, taskUtil, CbTask,
|
|
37
|
-
VContext, EventManager, inputParser,
|
|
38
|
-
BaseTask, RetTask, util) {
|
|
39
|
-
// save refs on window for these
|
|
40
|
-
window.react = react;
|
|
41
|
-
window.sprintf = sprintf;
|
|
42
|
-
window.util = util;
|
|
43
|
-
window.validate = validate;
|
|
44
|
-
window.taskUtil = taskUtil;
|
|
45
|
-
window.CbTask = CbTask;
|
|
46
|
-
window.VContext = VContext;
|
|
47
|
-
window.EventManager = EventManager;
|
|
48
|
-
window.inputParser = inputParser;
|
|
49
|
-
window.BaseTask = BaseTask;
|
|
50
|
-
window.RetTask = RetTask;
|
|
51
|
-
window.validate = validate;
|
|
52
|
-
window.Deferred = jQuery.Deferred;
|
|
53
|
-
window.Deferred.when = jQuery.when;
|
|
54
|
-
var testFiles = [
|
|
55
|
-
"test/ast.mocha",
|
|
56
|
-
"test/cb-task.mocha",
|
|
57
|
-
"test/core-deferred.mocha",
|
|
58
|
-
"test/core-when.mocha",
|
|
59
|
-
"test/core.mocha",
|
|
60
|
-
"test/dsl.mocha",
|
|
61
|
-
"test/event-manager.mocha",
|
|
62
|
-
"test/exec-options.mocha",
|
|
63
|
-
"test/finalcb-task.mocha",
|
|
64
|
-
"test/input-parser.mocha",
|
|
65
|
-
"test/log-events.mocha",
|
|
66
|
-
"test/module-use.mocha",
|
|
67
|
-
"test/promise-auto-resolve.mocha",
|
|
68
|
-
"test/ret-task.mocha",
|
|
69
|
-
"test/task.mocha",
|
|
70
|
-
"test/validate-cb-task.mocha",
|
|
71
|
-
"test/validate-ret-task.mocha",
|
|
72
|
-
"test/validate.mocha",
|
|
73
|
-
"test/vcon.mocha"
|
|
74
|
-
];
|
|
75
|
-
require(testFiles, function () {
|
|
76
|
-
var runner = mocha.run().on('end', function () {
|
|
77
|
-
console.log('mocha finished');
|
|
78
|
-
jQuery("#mocha-result").text('completed');
|
|
79
|
-
});
|
|
80
|
-
//mocha.reporters.TAP(runner);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
</script>
|
|
85
|
-
</head>
|
|
86
|
-
<body>
|
|
87
|
-
<div id="mocha"></div>
|
|
88
|
-
<div id="mocha-result"></div>
|
|
89
|
-
</body>
|
|
90
|
-
</html>
|
package/browser-test/index.html
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<meta charset="utf-8">
|
|
4
|
-
<title>Mocha Tests</title>
|
|
5
|
-
<link rel="stylesheet" href="../vendor/mocha/mocha.css" />
|
|
6
|
-
<script type="text/javascript" src="../vendor/jquery/jquery-1.7.1.js"></script>
|
|
7
|
-
<script type="text/javascript" src="../vendor/chai/chai.js"></script>
|
|
8
|
-
<script type="text/javascript" src="../vendor/mocha/mocha.js"></script>
|
|
9
|
-
<script>mocha.setup('qunit')</script>
|
|
10
|
-
<script src="../vendor/requirejs/require.min.js"></script>
|
|
11
|
-
<script type="text/javascript">
|
|
12
|
-
require.config({
|
|
13
|
-
baseUrl: "..",
|
|
14
|
-
packages: [
|
|
15
|
-
{
|
|
16
|
-
name: "react",
|
|
17
|
-
location: "lib",
|
|
18
|
-
main: "react"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
paths: {
|
|
22
|
-
jquery: "vendor/jquery/jquery-1.7.1",
|
|
23
|
-
eventemitter2: "node_modules/eventemitter2/lib/eventemitter2",
|
|
24
|
-
util: "vendor/node/util",
|
|
25
|
-
"ensure-array": "node_modules/ensure-array/ensure-array",
|
|
26
|
-
test: "test"
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
require(["react", "react/sprintf", "util", "react/validate", "react/task",
|
|
31
|
-
"react/cb-task", "react/vcon", "react/event-manager", "react/input-parser",
|
|
32
|
-
"react/base-task", "react/ret-task", "react/validate", "jquery"],
|
|
33
|
-
function (react, sprintf, util, validate, taskUtil,
|
|
34
|
-
CbTask, VContext, EventManager, inputParser,
|
|
35
|
-
BaseTask, RetTask, validate, jquery) {
|
|
36
|
-
// save refs on window for these
|
|
37
|
-
window.react = react;
|
|
38
|
-
window.sprintf = sprintf;
|
|
39
|
-
window.util = util;
|
|
40
|
-
window.validate = validate;
|
|
41
|
-
window.taskUtil = taskUtil;
|
|
42
|
-
window.CbTask = CbTask;
|
|
43
|
-
window.VContext = VContext;
|
|
44
|
-
window.EventManager = EventManager;
|
|
45
|
-
window.inputParser = inputParser;
|
|
46
|
-
window.BaseTask = BaseTask;
|
|
47
|
-
window.RetTask = RetTask;
|
|
48
|
-
window.validate = validate;
|
|
49
|
-
window.Deferred = jQuery.Deferred;
|
|
50
|
-
window.Deferred.when = jQuery.when;
|
|
51
|
-
var testFiles = [
|
|
52
|
-
"test/ast.mocha",
|
|
53
|
-
"test/cb-task.mocha",
|
|
54
|
-
"test/core-deferred.mocha",
|
|
55
|
-
"test/core-when.mocha",
|
|
56
|
-
"test/core.mocha",
|
|
57
|
-
"test/dsl.mocha",
|
|
58
|
-
"test/event-manager.mocha",
|
|
59
|
-
"test/exec-options.mocha",
|
|
60
|
-
"test/finalcb-task.mocha",
|
|
61
|
-
"test/input-parser.mocha",
|
|
62
|
-
"test/log-events.mocha",
|
|
63
|
-
"test/module-use.mocha",
|
|
64
|
-
"test/promise-auto-resolve.mocha",
|
|
65
|
-
"test/ret-task.mocha",
|
|
66
|
-
"test/task.mocha",
|
|
67
|
-
"test/validate-cb-task.mocha",
|
|
68
|
-
"test/validate-ret-task.mocha",
|
|
69
|
-
"test/validate.mocha",
|
|
70
|
-
"test/vcon.mocha"
|
|
71
|
-
];
|
|
72
|
-
require(testFiles, function () {
|
|
73
|
-
var runner = mocha.run().on('end', function () {
|
|
74
|
-
console.log('mocha finished');
|
|
75
|
-
jQuery("#mocha-result").text('completed');
|
|
76
|
-
});
|
|
77
|
-
//mocha.reporters.TAP(runner);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
</script>
|
|
81
|
-
</head>
|
|
82
|
-
<body>
|
|
83
|
-
<div id="mocha"></div>
|
|
84
|
-
<div id="mocha-result"></div>
|
|
85
|
-
</body>
|
|
86
|
-
</html>
|
package/browser-test/min.html
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<head>
|
|
3
|
-
<meta charset="utf-8">
|
|
4
|
-
<title>Mocha Tests</title>
|
|
5
|
-
<link rel="stylesheet" href="../vendor/mocha/mocha.css" />
|
|
6
|
-
<script type="text/javascript" src="../vendor/jquery/jquery-1.7.1.js"></script>
|
|
7
|
-
<script type="text/javascript" src="../vendor/chai/chai.js"></script>
|
|
8
|
-
<script type="text/javascript" src="../vendor/mocha/mocha.js"></script>
|
|
9
|
-
<script>mocha.setup('qunit')</script>
|
|
10
|
-
<script src="../vendor/requirejs/require.min.js"></script>
|
|
11
|
-
<script type="text/javascript">
|
|
12
|
-
require.config({
|
|
13
|
-
baseUrl: "..",
|
|
14
|
-
packages: [
|
|
15
|
-
{
|
|
16
|
-
name: "react",
|
|
17
|
-
location: "dist",
|
|
18
|
-
main: "react.min"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
paths: {
|
|
22
|
-
jQuery: "vendor/jquery/jquery-1.7.1.min",
|
|
23
|
-
eventemitter2: "dist/react.min",
|
|
24
|
-
util: "dist/react.min",
|
|
25
|
-
"ensure-array": "dist/react.min",
|
|
26
|
-
test: "test"
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
require(["react", "jQuery"],
|
|
31
|
-
function (react, jquery) {
|
|
32
|
-
|
|
33
|
-
require(["react/sprintf", "react/validate", "react/task", "react/cb-task",
|
|
34
|
-
"react/vcon", "react/event-manager", "react/input-parser",
|
|
35
|
-
"react/base-task", "react/ret-task", "util"],
|
|
36
|
-
function (sprintf, validate, taskUtil, CbTask,
|
|
37
|
-
VContext, EventManager, inputParser,
|
|
38
|
-
BaseTask, RetTask, util) {
|
|
39
|
-
// save refs on window for these
|
|
40
|
-
window.react = react;
|
|
41
|
-
window.sprintf = sprintf;
|
|
42
|
-
window.util = util;
|
|
43
|
-
window.validate = validate;
|
|
44
|
-
window.taskUtil = taskUtil;
|
|
45
|
-
window.CbTask = CbTask;
|
|
46
|
-
window.VContext = VContext;
|
|
47
|
-
window.EventManager = EventManager;
|
|
48
|
-
window.inputParser = inputParser;
|
|
49
|
-
window.BaseTask = BaseTask;
|
|
50
|
-
window.RetTask = RetTask;
|
|
51
|
-
window.validate = validate;
|
|
52
|
-
window.Deferred = jQuery.Deferred;
|
|
53
|
-
window.Deferred.when = jQuery.when;
|
|
54
|
-
var testFiles = [
|
|
55
|
-
"test/ast.mocha",
|
|
56
|
-
"test/cb-task.mocha",
|
|
57
|
-
"test/core-deferred.mocha",
|
|
58
|
-
"test/core-when.mocha",
|
|
59
|
-
"test/core.mocha",
|
|
60
|
-
"test/dsl.mocha",
|
|
61
|
-
"test/event-manager.mocha",
|
|
62
|
-
"test/exec-options.mocha",
|
|
63
|
-
"test/finalcb-task.mocha",
|
|
64
|
-
"test/input-parser.mocha",
|
|
65
|
-
"test/log-events.mocha",
|
|
66
|
-
"test/module-use.mocha",
|
|
67
|
-
"test/promise-auto-resolve.mocha",
|
|
68
|
-
"test/ret-task.mocha",
|
|
69
|
-
"test/task.mocha",
|
|
70
|
-
"test/validate-cb-task.mocha",
|
|
71
|
-
"test/validate-ret-task.mocha",
|
|
72
|
-
"test/validate.mocha",
|
|
73
|
-
"test/vcon.mocha"
|
|
74
|
-
];
|
|
75
|
-
require(testFiles, function () {
|
|
76
|
-
var runner = mocha.run().on('end', function () {
|
|
77
|
-
console.log('mocha finished');
|
|
78
|
-
jQuery("#mocha-result").text('completed');
|
|
79
|
-
});
|
|
80
|
-
//mocha.reporters.TAP(runner);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
</script>
|
|
85
|
-
</head>
|
|
86
|
-
<body>
|
|
87
|
-
<div id="mocha"></div>
|
|
88
|
-
<div id="mocha-result"></div>
|
|
89
|
-
</body>
|
|
90
|
-
</html>
|
package/dist/react.js
DELETED
|
@@ -1,3141 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
;!function(exports, undefined) {
|
|
3
|
-
|
|
4
|
-
var isArray = Array.isArray ? Array.isArray : function _isArray(obj) {
|
|
5
|
-
return Object.prototype.toString.call(obj) === "[object Array]";
|
|
6
|
-
};
|
|
7
|
-
var defaultMaxListeners = 10;
|
|
8
|
-
|
|
9
|
-
function init() {
|
|
10
|
-
this._events = {};
|
|
11
|
-
if (this._conf) {
|
|
12
|
-
configure.call(this, this._conf);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function configure(conf) {
|
|
17
|
-
if (conf) {
|
|
18
|
-
|
|
19
|
-
this._conf = conf;
|
|
20
|
-
|
|
21
|
-
conf.delimiter && (this.delimiter = conf.delimiter);
|
|
22
|
-
conf.maxListeners && (this._events.maxListeners = conf.maxListeners);
|
|
23
|
-
conf.wildcard && (this.wildcard = conf.wildcard);
|
|
24
|
-
conf.newListener && (this.newListener = conf.newListener);
|
|
25
|
-
|
|
26
|
-
if (this.wildcard) {
|
|
27
|
-
this.listenerTree = {};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function EventEmitter(conf) {
|
|
33
|
-
this._events = {};
|
|
34
|
-
this.newListener = false;
|
|
35
|
-
configure.call(this, conf);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
// Attention, function return type now is array, always !
|
|
40
|
-
// It has zero elements if no any matches found and one or more
|
|
41
|
-
// elements (leafs) if there are matches
|
|
42
|
-
//
|
|
43
|
-
function searchListenerTree(handlers, type, tree, i) {
|
|
44
|
-
if (!tree) {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
var listeners=[], leaf, len, branch, xTree, xxTree, isolatedBranch, endReached,
|
|
48
|
-
typeLength = type.length, currentType = type[i], nextType = type[i+1];
|
|
49
|
-
if (i === typeLength && tree._listeners) {
|
|
50
|
-
//
|
|
51
|
-
// If at the end of the event(s) list and the tree has listeners
|
|
52
|
-
// invoke those listeners.
|
|
53
|
-
//
|
|
54
|
-
if (typeof tree._listeners === 'function') {
|
|
55
|
-
handlers && handlers.push(tree._listeners);
|
|
56
|
-
return [tree];
|
|
57
|
-
} else {
|
|
58
|
-
for (leaf = 0, len = tree._listeners.length; leaf < len; leaf++) {
|
|
59
|
-
handlers && handlers.push(tree._listeners[leaf]);
|
|
60
|
-
}
|
|
61
|
-
return [tree];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if ((currentType === '*' || currentType === '**') || tree[currentType]) {
|
|
66
|
-
//
|
|
67
|
-
// If the event emitted is '*' at this part
|
|
68
|
-
// or there is a concrete match at this patch
|
|
69
|
-
//
|
|
70
|
-
if (currentType === '*') {
|
|
71
|
-
for (branch in tree) {
|
|
72
|
-
if (branch !== '_listeners' && tree.hasOwnProperty(branch)) {
|
|
73
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i+1));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return listeners;
|
|
77
|
-
} else if(currentType === '**') {
|
|
78
|
-
endReached = (i+1 === typeLength || (i+2 === typeLength && nextType === '*'));
|
|
79
|
-
if(endReached && tree._listeners) {
|
|
80
|
-
// The next element has a _listeners, add it to the handlers.
|
|
81
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree, typeLength));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
for (branch in tree) {
|
|
85
|
-
if (branch !== '_listeners' && tree.hasOwnProperty(branch)) {
|
|
86
|
-
if(branch === '*' || branch === '**') {
|
|
87
|
-
if(tree[branch]._listeners && !endReached) {
|
|
88
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], typeLength));
|
|
89
|
-
}
|
|
90
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i));
|
|
91
|
-
} else if(branch === nextType) {
|
|
92
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i+2));
|
|
93
|
-
} else {
|
|
94
|
-
// No match on this one, shift into the tree but not in the type array.
|
|
95
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree[branch], i));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return listeners;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
listeners = listeners.concat(searchListenerTree(handlers, type, tree[currentType], i+1));
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
xTree = tree['*'];
|
|
106
|
-
if (xTree) {
|
|
107
|
-
//
|
|
108
|
-
// If the listener tree will allow any match for this part,
|
|
109
|
-
// then recursively explore all branches of the tree
|
|
110
|
-
//
|
|
111
|
-
searchListenerTree(handlers, type, xTree, i+1);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
xxTree = tree['**'];
|
|
115
|
-
if(xxTree) {
|
|
116
|
-
if(i < typeLength) {
|
|
117
|
-
if(xxTree._listeners) {
|
|
118
|
-
// If we have a listener on a '**', it will catch all, so add its handler.
|
|
119
|
-
searchListenerTree(handlers, type, xxTree, typeLength);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Build arrays of matching next branches and others.
|
|
123
|
-
for(branch in xxTree) {
|
|
124
|
-
if(branch !== '_listeners' && xxTree.hasOwnProperty(branch)) {
|
|
125
|
-
if(branch === nextType) {
|
|
126
|
-
// We know the next element will match, so jump twice.
|
|
127
|
-
searchListenerTree(handlers, type, xxTree[branch], i+2);
|
|
128
|
-
} else if(branch === currentType) {
|
|
129
|
-
// Current node matches, move into the tree.
|
|
130
|
-
searchListenerTree(handlers, type, xxTree[branch], i+1);
|
|
131
|
-
} else {
|
|
132
|
-
isolatedBranch = {};
|
|
133
|
-
isolatedBranch[branch] = xxTree[branch];
|
|
134
|
-
searchListenerTree(handlers, type, { '**': isolatedBranch }, i+1);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
} else if(xxTree._listeners) {
|
|
139
|
-
// We have reached the end and still on a '**'
|
|
140
|
-
searchListenerTree(handlers, type, xxTree, typeLength);
|
|
141
|
-
} else if(xxTree['*'] && xxTree['*']._listeners) {
|
|
142
|
-
searchListenerTree(handlers, type, xxTree['*'], typeLength);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return listeners;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function growListenerTree(type, listener) {
|
|
150
|
-
|
|
151
|
-
type = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
|
|
152
|
-
|
|
153
|
-
//
|
|
154
|
-
// Looks for two consecutive '**', if so, don't add the event at all.
|
|
155
|
-
//
|
|
156
|
-
for(var i = 0, len = type.length; i+1 < len; i++) {
|
|
157
|
-
if(type[i] === '**' && type[i+1] === '**') {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var tree = this.listenerTree;
|
|
163
|
-
var name = type.shift();
|
|
164
|
-
|
|
165
|
-
while (name) {
|
|
166
|
-
|
|
167
|
-
if (!tree[name]) {
|
|
168
|
-
tree[name] = {};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
tree = tree[name];
|
|
172
|
-
|
|
173
|
-
if (type.length === 0) {
|
|
174
|
-
|
|
175
|
-
if (!tree._listeners) {
|
|
176
|
-
tree._listeners = listener;
|
|
177
|
-
}
|
|
178
|
-
else if(typeof tree._listeners === 'function') {
|
|
179
|
-
tree._listeners = [tree._listeners, listener];
|
|
180
|
-
}
|
|
181
|
-
else if (isArray(tree._listeners)) {
|
|
182
|
-
|
|
183
|
-
tree._listeners.push(listener);
|
|
184
|
-
|
|
185
|
-
if (!tree._listeners.warned) {
|
|
186
|
-
|
|
187
|
-
var m = defaultMaxListeners;
|
|
188
|
-
|
|
189
|
-
if (typeof this._events.maxListeners !== 'undefined') {
|
|
190
|
-
m = this._events.maxListeners;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (m > 0 && tree._listeners.length > m) {
|
|
194
|
-
|
|
195
|
-
tree._listeners.warned = true;
|
|
196
|
-
console.error('(node) warning: possible EventEmitter memory ' +
|
|
197
|
-
'leak detected. %d listeners added. ' +
|
|
198
|
-
'Use emitter.setMaxListeners() to increase limit.',
|
|
199
|
-
tree._listeners.length);
|
|
200
|
-
console.trace();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return true;
|
|
205
|
-
}
|
|
206
|
-
name = type.shift();
|
|
207
|
-
}
|
|
208
|
-
return true;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// By default EventEmitters will print a warning if more than
|
|
212
|
-
// 10 listeners are added to it. This is a useful default which
|
|
213
|
-
// helps finding memory leaks.
|
|
214
|
-
//
|
|
215
|
-
// Obviously not all Emitters should be limited to 10. This function allows
|
|
216
|
-
// that to be increased. Set to zero for unlimited.
|
|
217
|
-
|
|
218
|
-
EventEmitter.prototype.delimiter = '.';
|
|
219
|
-
|
|
220
|
-
EventEmitter.prototype.setMaxListeners = function(n) {
|
|
221
|
-
this._events || init.call(this);
|
|
222
|
-
this._events.maxListeners = n;
|
|
223
|
-
if (!this._conf) this._conf = {};
|
|
224
|
-
this._conf.maxListeners = n;
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
EventEmitter.prototype.event = '';
|
|
228
|
-
|
|
229
|
-
EventEmitter.prototype.once = function(event, fn) {
|
|
230
|
-
this.many(event, 1, fn);
|
|
231
|
-
return this;
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
EventEmitter.prototype.many = function(event, ttl, fn) {
|
|
235
|
-
var self = this;
|
|
236
|
-
|
|
237
|
-
if (typeof fn !== 'function') {
|
|
238
|
-
throw new Error('many only accepts instances of Function');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function listener() {
|
|
242
|
-
if (--ttl === 0) {
|
|
243
|
-
self.off(event, listener);
|
|
244
|
-
}
|
|
245
|
-
fn.apply(this, arguments);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
listener._origin = fn;
|
|
249
|
-
|
|
250
|
-
this.on(event, listener);
|
|
251
|
-
|
|
252
|
-
return self;
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
EventEmitter.prototype.emit = function() {
|
|
256
|
-
|
|
257
|
-
this._events || init.call(this);
|
|
258
|
-
|
|
259
|
-
var type = arguments[0];
|
|
260
|
-
|
|
261
|
-
if (type === 'newListener' && !this.newListener) {
|
|
262
|
-
if (!this._events.newListener) { return false; }
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// Loop through the *_all* functions and invoke them.
|
|
266
|
-
if (this._all) {
|
|
267
|
-
var l = arguments.length;
|
|
268
|
-
var args = new Array(l - 1);
|
|
269
|
-
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
|
|
270
|
-
for (i = 0, l = this._all.length; i < l; i++) {
|
|
271
|
-
this.event = type;
|
|
272
|
-
this._all[i].apply(this, args);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// If there is no 'error' event listener then throw.
|
|
277
|
-
if (type === 'error') {
|
|
278
|
-
|
|
279
|
-
if (!this._all &&
|
|
280
|
-
!this._events.error &&
|
|
281
|
-
!(this.wildcard && this.listenerTree.error)) {
|
|
282
|
-
|
|
283
|
-
if (arguments[1] instanceof Error) {
|
|
284
|
-
throw arguments[1]; // Unhandled 'error' event
|
|
285
|
-
} else {
|
|
286
|
-
throw new Error("Uncaught, unspecified 'error' event.");
|
|
287
|
-
}
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
var handler;
|
|
293
|
-
|
|
294
|
-
if(this.wildcard) {
|
|
295
|
-
handler = [];
|
|
296
|
-
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
|
|
297
|
-
searchListenerTree.call(this, handler, ns, this.listenerTree, 0);
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
handler = this._events[type];
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (typeof handler === 'function') {
|
|
304
|
-
this.event = type;
|
|
305
|
-
if (arguments.length === 1) {
|
|
306
|
-
handler.call(this);
|
|
307
|
-
}
|
|
308
|
-
else if (arguments.length > 1)
|
|
309
|
-
switch (arguments.length) {
|
|
310
|
-
case 2:
|
|
311
|
-
handler.call(this, arguments[1]);
|
|
312
|
-
break;
|
|
313
|
-
case 3:
|
|
314
|
-
handler.call(this, arguments[1], arguments[2]);
|
|
315
|
-
break;
|
|
316
|
-
// slower
|
|
317
|
-
default:
|
|
318
|
-
var l = arguments.length;
|
|
319
|
-
var args = new Array(l - 1);
|
|
320
|
-
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
|
|
321
|
-
handler.apply(this, args);
|
|
322
|
-
}
|
|
323
|
-
return true;
|
|
324
|
-
}
|
|
325
|
-
else if (handler) {
|
|
326
|
-
var l = arguments.length;
|
|
327
|
-
var args = new Array(l - 1);
|
|
328
|
-
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
|
|
329
|
-
|
|
330
|
-
var listeners = handler.slice();
|
|
331
|
-
for (var i = 0, l = listeners.length; i < l; i++) {
|
|
332
|
-
this.event = type;
|
|
333
|
-
listeners[i].apply(this, args);
|
|
334
|
-
}
|
|
335
|
-
return (listeners.length > 0) || this._all;
|
|
336
|
-
}
|
|
337
|
-
else {
|
|
338
|
-
return this._all;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
EventEmitter.prototype.on = function(type, listener) {
|
|
344
|
-
|
|
345
|
-
if (typeof type === 'function') {
|
|
346
|
-
this.onAny(type);
|
|
347
|
-
return this;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (typeof listener !== 'function') {
|
|
351
|
-
throw new Error('on only accepts instances of Function');
|
|
352
|
-
}
|
|
353
|
-
this._events || init.call(this);
|
|
354
|
-
|
|
355
|
-
// To avoid recursion in the case that type == "newListeners"! Before
|
|
356
|
-
// adding it to the listeners, first emit "newListeners".
|
|
357
|
-
this.emit('newListener', type, listener);
|
|
358
|
-
|
|
359
|
-
if(this.wildcard) {
|
|
360
|
-
growListenerTree.call(this, type, listener);
|
|
361
|
-
return this;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
if (!this._events[type]) {
|
|
365
|
-
// Optimize the case of one listener. Don't need the extra array object.
|
|
366
|
-
this._events[type] = listener;
|
|
367
|
-
}
|
|
368
|
-
else if(typeof this._events[type] === 'function') {
|
|
369
|
-
// Adding the second element, need to change to array.
|
|
370
|
-
this._events[type] = [this._events[type], listener];
|
|
371
|
-
}
|
|
372
|
-
else if (isArray(this._events[type])) {
|
|
373
|
-
// If we've already got an array, just append.
|
|
374
|
-
this._events[type].push(listener);
|
|
375
|
-
|
|
376
|
-
// Check for listener leak
|
|
377
|
-
if (!this._events[type].warned) {
|
|
378
|
-
|
|
379
|
-
var m = defaultMaxListeners;
|
|
380
|
-
|
|
381
|
-
if (typeof this._events.maxListeners !== 'undefined') {
|
|
382
|
-
m = this._events.maxListeners;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
if (m > 0 && this._events[type].length > m) {
|
|
386
|
-
|
|
387
|
-
this._events[type].warned = true;
|
|
388
|
-
console.error('(node) warning: possible EventEmitter memory ' +
|
|
389
|
-
'leak detected. %d listeners added. ' +
|
|
390
|
-
'Use emitter.setMaxListeners() to increase limit.',
|
|
391
|
-
this._events[type].length);
|
|
392
|
-
console.trace();
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
return this;
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
EventEmitter.prototype.onAny = function(fn) {
|
|
400
|
-
|
|
401
|
-
if(!this._all) {
|
|
402
|
-
this._all = [];
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
if (typeof fn !== 'function') {
|
|
406
|
-
throw new Error('onAny only accepts instances of Function');
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
// Add the function to the event listener collection.
|
|
410
|
-
this._all.push(fn);
|
|
411
|
-
return this;
|
|
412
|
-
};
|
|
413
|
-
|
|
414
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
415
|
-
|
|
416
|
-
EventEmitter.prototype.off = function(type, listener) {
|
|
417
|
-
if (typeof listener !== 'function') {
|
|
418
|
-
throw new Error('removeListener only takes instances of Function');
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
var handlers,leafs=[];
|
|
422
|
-
|
|
423
|
-
if(this.wildcard) {
|
|
424
|
-
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
|
|
425
|
-
leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0);
|
|
426
|
-
}
|
|
427
|
-
else {
|
|
428
|
-
// does not use listeners(), so no side effect of creating _events[type]
|
|
429
|
-
if (!this._events[type]) return this;
|
|
430
|
-
handlers = this._events[type];
|
|
431
|
-
leafs.push({_listeners:handlers});
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
for (var iLeaf=0; iLeaf<leafs.length; iLeaf++) {
|
|
435
|
-
var leaf = leafs[iLeaf];
|
|
436
|
-
handlers = leaf._listeners;
|
|
437
|
-
if (isArray(handlers)) {
|
|
438
|
-
|
|
439
|
-
var position = -1;
|
|
440
|
-
|
|
441
|
-
for (var i = 0, length = handlers.length; i < length; i++) {
|
|
442
|
-
if (handlers[i] === listener ||
|
|
443
|
-
(handlers[i].listener && handlers[i].listener === listener) ||
|
|
444
|
-
(handlers[i]._origin && handlers[i]._origin === listener)) {
|
|
445
|
-
position = i;
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
if (position < 0) {
|
|
451
|
-
return this;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
if(this.wildcard) {
|
|
455
|
-
leaf._listeners.splice(position, 1)
|
|
456
|
-
}
|
|
457
|
-
else {
|
|
458
|
-
this._events[type].splice(position, 1);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (handlers.length === 0) {
|
|
462
|
-
if(this.wildcard) {
|
|
463
|
-
delete leaf._listeners;
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
delete this._events[type];
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
else if (handlers === listener ||
|
|
471
|
-
(handlers.listener && handlers.listener === listener) ||
|
|
472
|
-
(handlers._origin && handlers._origin === listener)) {
|
|
473
|
-
if(this.wildcard) {
|
|
474
|
-
delete leaf._listeners;
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
delete this._events[type];
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
return this;
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
EventEmitter.prototype.offAny = function(fn) {
|
|
486
|
-
var i = 0, l = 0, fns;
|
|
487
|
-
if (fn && this._all && this._all.length > 0) {
|
|
488
|
-
fns = this._all;
|
|
489
|
-
for(i = 0, l = fns.length; i < l; i++) {
|
|
490
|
-
if(fn === fns[i]) {
|
|
491
|
-
fns.splice(i, 1);
|
|
492
|
-
return this;
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
} else {
|
|
496
|
-
this._all = [];
|
|
497
|
-
}
|
|
498
|
-
return this;
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
EventEmitter.prototype.removeListener = EventEmitter.prototype.off;
|
|
502
|
-
|
|
503
|
-
EventEmitter.prototype.removeAllListeners = function(type) {
|
|
504
|
-
if (arguments.length === 0) {
|
|
505
|
-
!this._events || init.call(this);
|
|
506
|
-
return this;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
if(this.wildcard) {
|
|
510
|
-
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
|
|
511
|
-
var leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0);
|
|
512
|
-
|
|
513
|
-
for (var iLeaf=0; iLeaf<leafs.length; iLeaf++) {
|
|
514
|
-
var leaf = leafs[iLeaf];
|
|
515
|
-
leaf._listeners = null;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
if (!this._events[type]) return this;
|
|
520
|
-
this._events[type] = null;
|
|
521
|
-
}
|
|
522
|
-
return this;
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
EventEmitter.prototype.listeners = function(type) {
|
|
526
|
-
if(this.wildcard) {
|
|
527
|
-
var handlers = [];
|
|
528
|
-
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice();
|
|
529
|
-
searchListenerTree.call(this, handlers, ns, this.listenerTree, 0);
|
|
530
|
-
return handlers;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
this._events || init.call(this);
|
|
534
|
-
|
|
535
|
-
if (!this._events[type]) this._events[type] = [];
|
|
536
|
-
if (!isArray(this._events[type])) {
|
|
537
|
-
this._events[type] = [this._events[type]];
|
|
538
|
-
}
|
|
539
|
-
return this._events[type];
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
EventEmitter.prototype.listenersAny = function() {
|
|
543
|
-
|
|
544
|
-
if(this._all) {
|
|
545
|
-
return this._all;
|
|
546
|
-
}
|
|
547
|
-
else {
|
|
548
|
-
return [];
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
if (typeof define === 'function' && define.amd) {
|
|
554
|
-
define('eventemitter2',[],function() {
|
|
555
|
-
return EventEmitter;
|
|
556
|
-
});
|
|
557
|
-
} else {
|
|
558
|
-
exports.EventEmitter2 = EventEmitter;
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
}(typeof process !== 'undefined' && typeof process.title !== 'undefined' && typeof exports !== 'undefined' ? exports : window);
|
|
562
|
-
|
|
563
|
-
/*global define:true EventEmitter2:true */
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
define('react/eventemitter',['eventemitter2'], function (EventEmitterMod) {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
Abstract the details of getting an EventEmitter
|
|
572
|
-
*/
|
|
573
|
-
|
|
574
|
-
// EventEmitter doesn't return itself in browser so need to get the global
|
|
575
|
-
// EventEmitter api changed, so accomodate which ever version is available
|
|
576
|
-
var EventEmitter = (EventEmitterMod) ?
|
|
577
|
-
((EventEmitterMod.EventEmitter2) ? EventEmitterMod.EventEmitter2 : EventEmitterMod) : EventEmitter2;
|
|
578
|
-
return EventEmitter;
|
|
579
|
-
|
|
580
|
-
});
|
|
581
|
-
/*global define:true */
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
// Copyright Joyent, Inc. and other Node contributors.
|
|
586
|
-
//
|
|
587
|
-
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
588
|
-
// copy of this software and associated documentation files (the
|
|
589
|
-
// "Software"), to deal in the Software without restriction, including
|
|
590
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
|
591
|
-
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
592
|
-
// persons to whom the Software is furnished to do so, subject to the
|
|
593
|
-
// following conditions:
|
|
594
|
-
//
|
|
595
|
-
// The above copyright notice and this permission notice shall be included
|
|
596
|
-
// in all copies or substantial portions of the Software.
|
|
597
|
-
//
|
|
598
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
599
|
-
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
600
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
601
|
-
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
602
|
-
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
603
|
-
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
604
|
-
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
605
|
-
|
|
606
|
-
define('util',['require','exports','module'],function (require, exports, module) {
|
|
607
|
-
/*jshint white:false */
|
|
608
|
-
|
|
609
|
-
var formatRegExp = /%[sdj%]/g;
|
|
610
|
-
exports.format = function(f) {
|
|
611
|
-
if (typeof f !== 'string') {
|
|
612
|
-
var objects = [];
|
|
613
|
-
for (var j = 0; j < arguments.length; j++) {
|
|
614
|
-
objects.push(inspect(arguments[j]));
|
|
615
|
-
}
|
|
616
|
-
return objects.join(' ');
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
var i = 1;
|
|
620
|
-
var args = arguments;
|
|
621
|
-
var len = args.length;
|
|
622
|
-
var str = String(f).replace(formatRegExp, function(x) {
|
|
623
|
-
if (x === '%%') return '%';
|
|
624
|
-
if (i >= len) return x;
|
|
625
|
-
switch (x) {
|
|
626
|
-
case '%s': return String(args[i++]);
|
|
627
|
-
case '%d': return Number(args[i++]);
|
|
628
|
-
case '%j': return JSON.stringify(args[i++]);
|
|
629
|
-
default:
|
|
630
|
-
return x;
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
for (var x = args[i]; i < len; x = args[++i]) {
|
|
634
|
-
if (x === null || typeof x !== 'object') {
|
|
635
|
-
str += ' ' + x;
|
|
636
|
-
} else {
|
|
637
|
-
str += ' ' + inspect(x);
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
return str;
|
|
641
|
-
};
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
exports.print = function() {
|
|
645
|
-
for (var i = 0, len = arguments.length; i < len; ++i) {
|
|
646
|
-
process.stdout.write(String(arguments[i]));
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
exports.puts = function() {
|
|
652
|
-
for (var i = 0, len = arguments.length; i < len; ++i) {
|
|
653
|
-
process.stdout.write(arguments[i] + '\n');
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
exports.debug = function(x) {
|
|
659
|
-
process.stderr.write('DEBUG: ' + x + '\n');
|
|
660
|
-
};
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
var error = exports.error = function(x) {
|
|
664
|
-
for (var i = 0, len = arguments.length; i < len; ++i) {
|
|
665
|
-
process.stderr.write(arguments[i] + '\n');
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* Echos the value of a value. Trys to print the value out
|
|
672
|
-
* in the best way possible given the different types.
|
|
673
|
-
*
|
|
674
|
-
* @param {Object} obj The object to print out.
|
|
675
|
-
* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
|
|
676
|
-
* properties of objects.
|
|
677
|
-
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
|
678
|
-
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
|
679
|
-
* output. Default is false (no coloring).
|
|
680
|
-
*/
|
|
681
|
-
function inspect(obj, showHidden, depth, colors) {
|
|
682
|
-
var ctx = {
|
|
683
|
-
showHidden: showHidden,
|
|
684
|
-
seen: [],
|
|
685
|
-
stylize: colors ? stylizeWithColor : stylizeNoColor
|
|
686
|
-
};
|
|
687
|
-
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
|
688
|
-
}
|
|
689
|
-
exports.inspect = inspect;
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
|
|
693
|
-
var colors = {
|
|
694
|
-
'bold' : [1, 22],
|
|
695
|
-
'italic' : [3, 23],
|
|
696
|
-
'underline' : [4, 24],
|
|
697
|
-
'inverse' : [7, 27],
|
|
698
|
-
'white' : [37, 39],
|
|
699
|
-
'grey' : [90, 39],
|
|
700
|
-
'black' : [30, 39],
|
|
701
|
-
'blue' : [34, 39],
|
|
702
|
-
'cyan' : [36, 39],
|
|
703
|
-
'green' : [32, 39],
|
|
704
|
-
'magenta' : [35, 39],
|
|
705
|
-
'red' : [31, 39],
|
|
706
|
-
'yellow' : [33, 39]
|
|
707
|
-
};
|
|
708
|
-
|
|
709
|
-
// Don't use 'blue' not visible on cmd.exe
|
|
710
|
-
var styles = {
|
|
711
|
-
'special': 'cyan',
|
|
712
|
-
'number': 'yellow',
|
|
713
|
-
'boolean': 'yellow',
|
|
714
|
-
'undefined': 'grey',
|
|
715
|
-
'null': 'bold',
|
|
716
|
-
'string': 'green',
|
|
717
|
-
'date': 'magenta',
|
|
718
|
-
// "name": intentionally not styling
|
|
719
|
-
'regexp': 'red'
|
|
720
|
-
};
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
function stylizeWithColor(str, styleType) {
|
|
724
|
-
var style = styles[styleType];
|
|
725
|
-
|
|
726
|
-
if (style) {
|
|
727
|
-
return '\033[' + colors[style][0] + 'm' + str +
|
|
728
|
-
'\033[' + colors[style][1] + 'm';
|
|
729
|
-
} else {
|
|
730
|
-
return str;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
function stylizeNoColor(str, styleType) {
|
|
736
|
-
return str;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
function formatValue(ctx, value, recurseTimes) {
|
|
741
|
-
// Provide a hook for user-specified inspect functions.
|
|
742
|
-
// Check that value is an object with an inspect function on it
|
|
743
|
-
if (value && typeof value.inspect === 'function' &&
|
|
744
|
-
// Filter out the util module, it's inspect function is special
|
|
745
|
-
value.inspect !== exports.inspect &&
|
|
746
|
-
// Also filter out any prototype objects using the circular check.
|
|
747
|
-
!(value.constructor && value.constructor.prototype === value)) {
|
|
748
|
-
return value.inspect(recurseTimes);
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
// Primitive types cannot have properties
|
|
752
|
-
var primitive = formatPrimitive(ctx, value);
|
|
753
|
-
if (primitive) {
|
|
754
|
-
return primitive;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// Look up the keys of the object.
|
|
758
|
-
var visibleKeys = Object.keys(value);
|
|
759
|
-
var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys;
|
|
760
|
-
|
|
761
|
-
// Some type of object without properties can be shortcutted.
|
|
762
|
-
if (keys.length === 0) {
|
|
763
|
-
if (typeof value === 'function') {
|
|
764
|
-
var name = value.name ? ': ' + value.name : '';
|
|
765
|
-
return ctx.stylize('[Function' + name + ']', 'special');
|
|
766
|
-
}
|
|
767
|
-
if (isRegExp(value)) {
|
|
768
|
-
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
769
|
-
}
|
|
770
|
-
if (isDate(value)) {
|
|
771
|
-
return ctx.stylize(Date.prototype.toString.call(value), 'date');
|
|
772
|
-
}
|
|
773
|
-
if (isError(value)) {
|
|
774
|
-
return formatError(value);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
var base = '', array = false, braces = ['{', '}'];
|
|
779
|
-
|
|
780
|
-
// Make Array say that they are Array
|
|
781
|
-
if (isArray(value)) {
|
|
782
|
-
array = true;
|
|
783
|
-
braces = ['[', ']'];
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// Make functions say that they are functions
|
|
787
|
-
if (typeof value === 'function') {
|
|
788
|
-
var n = value.name ? ': ' + value.name : '';
|
|
789
|
-
base = ' [Function' + n + ']';
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
// Make RegExps say that they are RegExps
|
|
793
|
-
if (isRegExp(value)) {
|
|
794
|
-
base = ' ' + RegExp.prototype.toString.call(value);
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// Make dates with properties first say the date
|
|
798
|
-
if (isDate(value)) {
|
|
799
|
-
base = ' ' + Date.prototype.toUTCString.call(value);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
// Make error with message first say the error
|
|
803
|
-
if (isError(value)) {
|
|
804
|
-
base = ' ' + formatError(value);
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
if (keys.length === 0 && (!array || value.length === 0)) {
|
|
808
|
-
return braces[0] + base + braces[1];
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
if (recurseTimes < 0) {
|
|
812
|
-
if (isRegExp(value)) {
|
|
813
|
-
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
|
814
|
-
} else {
|
|
815
|
-
return ctx.stylize('[Object]', 'special');
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
ctx.seen.push(value);
|
|
820
|
-
|
|
821
|
-
var output;
|
|
822
|
-
if (array) {
|
|
823
|
-
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
|
824
|
-
} else {
|
|
825
|
-
output = keys.map(function(key) {
|
|
826
|
-
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
ctx.seen.pop();
|
|
831
|
-
|
|
832
|
-
return reduceToSingleString(output, base, braces);
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
function formatPrimitive(ctx, value) {
|
|
837
|
-
switch (typeof value) {
|
|
838
|
-
case 'undefined':
|
|
839
|
-
return ctx.stylize('undefined', 'undefined');
|
|
840
|
-
|
|
841
|
-
case 'string':
|
|
842
|
-
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
|
843
|
-
.replace(/'/g, "\\'")
|
|
844
|
-
.replace(/\\"/g, '"') + '\'';
|
|
845
|
-
return ctx.stylize(simple, 'string');
|
|
846
|
-
|
|
847
|
-
case 'number':
|
|
848
|
-
return ctx.stylize('' + value, 'number');
|
|
849
|
-
|
|
850
|
-
case 'boolean':
|
|
851
|
-
return ctx.stylize('' + value, 'boolean');
|
|
852
|
-
}
|
|
853
|
-
// For some reason typeof null is "object", so special case here.
|
|
854
|
-
if (value === null) {
|
|
855
|
-
return ctx.stylize('null', 'null');
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
function formatError(value) {
|
|
861
|
-
return '[' + Error.prototype.toString.call(value) + ']';
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
|
866
|
-
var output = [];
|
|
867
|
-
for (var i = 0, l = value.length; i < l; ++i) {
|
|
868
|
-
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
|
|
869
|
-
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
870
|
-
String(i), true));
|
|
871
|
-
} else {
|
|
872
|
-
output.push('');
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
keys.forEach(function(key) {
|
|
876
|
-
if (!key.match(/^\d+$/)) {
|
|
877
|
-
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
|
878
|
-
key, true));
|
|
879
|
-
}
|
|
880
|
-
});
|
|
881
|
-
return output;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
|
886
|
-
var name, str, desc;
|
|
887
|
-
desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
|
|
888
|
-
if (desc.get) {
|
|
889
|
-
if (desc.set) {
|
|
890
|
-
str = ctx.stylize('[Getter/Setter]', 'special');
|
|
891
|
-
} else {
|
|
892
|
-
str = ctx.stylize('[Getter]', 'special');
|
|
893
|
-
}
|
|
894
|
-
} else {
|
|
895
|
-
if (desc.set) {
|
|
896
|
-
str = ctx.stylize('[Setter]', 'special');
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
if (visibleKeys.indexOf(key) < 0) {
|
|
900
|
-
name = '[' + key + ']';
|
|
901
|
-
}
|
|
902
|
-
if (!str) {
|
|
903
|
-
if (ctx.seen.indexOf(desc.value) < 0) {
|
|
904
|
-
if (recurseTimes === null) {
|
|
905
|
-
str = formatValue(ctx, desc.value, null);
|
|
906
|
-
} else {
|
|
907
|
-
str = formatValue(ctx, desc.value, recurseTimes - 1);
|
|
908
|
-
}
|
|
909
|
-
if (str.indexOf('\n') > -1) {
|
|
910
|
-
if (array) {
|
|
911
|
-
str = str.split('\n').map(function(line) {
|
|
912
|
-
return ' ' + line;
|
|
913
|
-
}).join('\n').substr(2);
|
|
914
|
-
} else {
|
|
915
|
-
str = '\n' + str.split('\n').map(function(line) {
|
|
916
|
-
return ' ' + line;
|
|
917
|
-
}).join('\n');
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
} else {
|
|
921
|
-
str = ctx.stylize('[Circular]', 'special');
|
|
922
|
-
}
|
|
923
|
-
}
|
|
924
|
-
if (typeof name === 'undefined') {
|
|
925
|
-
if (array && key.match(/^\d+$/)) {
|
|
926
|
-
return str;
|
|
927
|
-
}
|
|
928
|
-
name = JSON.stringify('' + key);
|
|
929
|
-
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
|
930
|
-
name = name.substr(1, name.length - 2);
|
|
931
|
-
name = ctx.stylize(name, 'name');
|
|
932
|
-
} else {
|
|
933
|
-
name = name.replace(/'/g, "\\'")
|
|
934
|
-
.replace(/\\"/g, '"')
|
|
935
|
-
.replace(/(^"|"$)/g, "'");
|
|
936
|
-
name = ctx.stylize(name, 'string');
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
return name + ': ' + str;
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
function reduceToSingleString(output, base, braces) {
|
|
945
|
-
var numLinesEst = 0;
|
|
946
|
-
var length = output.reduce(function(prev, cur) {
|
|
947
|
-
numLinesEst++;
|
|
948
|
-
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
|
949
|
-
return prev + cur.length + 1;
|
|
950
|
-
}, 0);
|
|
951
|
-
|
|
952
|
-
if (length > 60) {
|
|
953
|
-
return braces[0] +
|
|
954
|
-
(base === '' ? '' : base + '\n ') +
|
|
955
|
-
' ' +
|
|
956
|
-
output.join(',\n ') +
|
|
957
|
-
' ' +
|
|
958
|
-
braces[1];
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
// NOTE: These type checking functions intentionally don't use `instanceof`
|
|
966
|
-
// because it is fragile and can be easily faked with `Object.create()`.
|
|
967
|
-
function isArray(ar) {
|
|
968
|
-
return Array.isArray(ar) ||
|
|
969
|
-
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
|
|
970
|
-
}
|
|
971
|
-
exports.isArray = isArray;
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
function isRegExp(re) {
|
|
975
|
-
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
|
|
976
|
-
}
|
|
977
|
-
exports.isRegExp = isRegExp;
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
function isDate(d) {
|
|
981
|
-
return typeof d === 'object' && objectToString(d) === '[object Date]';
|
|
982
|
-
}
|
|
983
|
-
exports.isDate = isDate;
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
function isError(e) {
|
|
987
|
-
return typeof e === 'object' && objectToString(e) === '[object Error]';
|
|
988
|
-
}
|
|
989
|
-
exports.isError = isError;
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
function objectToString(o) {
|
|
993
|
-
return Object.prototype.toString.call(o);
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
// exports.p = function() {
|
|
998
|
-
// for (var i = 0, len = arguments.length; i < len; ++i) {
|
|
999
|
-
// error(exports.inspect(arguments[i]));
|
|
1000
|
-
// }
|
|
1001
|
-
// };
|
|
1002
|
-
// module.deprecate('p', 'Use `util.puts(util.inspect())` instead.');
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
function pad(n) {
|
|
1006
|
-
return n < 10 ? '0' + n.toString(10) : n.toString(10);
|
|
1007
|
-
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
|
|
1011
|
-
'Oct', 'Nov', 'Dec'];
|
|
1012
|
-
|
|
1013
|
-
// 26 Feb 16:19:34
|
|
1014
|
-
function timestamp() {
|
|
1015
|
-
var d = new Date();
|
|
1016
|
-
var time = [pad(d.getHours()),
|
|
1017
|
-
pad(d.getMinutes()),
|
|
1018
|
-
pad(d.getSeconds())].join(':');
|
|
1019
|
-
return [d.getDate(), months[d.getMonth()], time].join(' ');
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
exports.log = function(msg) {
|
|
1024
|
-
exports.puts(timestamp() + ' - ' + msg.toString());
|
|
1025
|
-
};
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
// exports.exec = function() {
|
|
1029
|
-
// return require('child_process').exec.apply(this, arguments);
|
|
1030
|
-
// };
|
|
1031
|
-
// module.deprecate('exec', 'It is now called `child_process.exec`.');
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
exports.pump = function(readStream, writeStream, callback) {
|
|
1035
|
-
var callbackCalled = false;
|
|
1036
|
-
|
|
1037
|
-
function call(a, b, c) {
|
|
1038
|
-
if (callback && !callbackCalled) {
|
|
1039
|
-
callback(a, b, c);
|
|
1040
|
-
callbackCalled = true;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
readStream.addListener('data', function(chunk) {
|
|
1045
|
-
if (writeStream.write(chunk) === false) readStream.pause();
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
|
-
writeStream.addListener('drain', function() {
|
|
1049
|
-
readStream.resume();
|
|
1050
|
-
});
|
|
1051
|
-
|
|
1052
|
-
readStream.addListener('end', function() {
|
|
1053
|
-
writeStream.end();
|
|
1054
|
-
});
|
|
1055
|
-
|
|
1056
|
-
readStream.addListener('close', function() {
|
|
1057
|
-
call();
|
|
1058
|
-
});
|
|
1059
|
-
|
|
1060
|
-
readStream.addListener('error', function(err) {
|
|
1061
|
-
writeStream.end();
|
|
1062
|
-
call(err);
|
|
1063
|
-
});
|
|
1064
|
-
|
|
1065
|
-
writeStream.addListener('error', function(err) {
|
|
1066
|
-
readStream.destroy();
|
|
1067
|
-
call(err);
|
|
1068
|
-
});
|
|
1069
|
-
};
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
/**
|
|
1073
|
-
* Inherit the prototype methods from one constructor into another.
|
|
1074
|
-
*
|
|
1075
|
-
* The Function.prototype.inherits from lang.js rewritten as a standalone
|
|
1076
|
-
* function (not on Function.prototype). NOTE: If this file is to be loaded
|
|
1077
|
-
* during bootstrapping this function needs to be rewritten using some native
|
|
1078
|
-
* functions as prototype setup using normal JavaScript does not work as
|
|
1079
|
-
* expected during bootstrapping (see mirror.js in r114903).
|
|
1080
|
-
*
|
|
1081
|
-
* @param {function} ctor Constructor function which needs to inherit the
|
|
1082
|
-
* prototype.
|
|
1083
|
-
* @param {function} superCtor Constructor function to inherit prototype from.
|
|
1084
|
-
*/
|
|
1085
|
-
exports.inherits = function(ctor, superCtor) {
|
|
1086
|
-
ctor.super_ = superCtor;
|
|
1087
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
|
1088
|
-
constructor: {
|
|
1089
|
-
value: ctor,
|
|
1090
|
-
enumerable: false,
|
|
1091
|
-
writable: true,
|
|
1092
|
-
configurable: true
|
|
1093
|
-
}
|
|
1094
|
-
});
|
|
1095
|
-
};
|
|
1096
|
-
|
|
1097
|
-
exports._extend = function(origin, add) {
|
|
1098
|
-
// Don't do anything if add isn't an object
|
|
1099
|
-
if (!add) return origin;
|
|
1100
|
-
|
|
1101
|
-
var keys = Object.keys(add);
|
|
1102
|
-
var i = keys.length;
|
|
1103
|
-
while (i--) {
|
|
1104
|
-
origin[keys[i]] = add[keys[i]];
|
|
1105
|
-
}
|
|
1106
|
-
return origin;
|
|
1107
|
-
};
|
|
1108
|
-
|
|
1109
|
-
});
|
|
1110
|
-
/*global define:true */
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
define('react/error',['util'], function (util) {
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
function ensureStackTraceLimitSet(stackTraceLimit) {
|
|
1118
|
-
if (!Error.stackTraceLimit || Error.stackTraceLimit < stackTraceLimit) {
|
|
1119
|
-
Error.stackTraceLimit = stackTraceLimit;
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
function fName(fn) {
|
|
1124
|
-
if (!fn) return 'undefined';
|
|
1125
|
-
return (fn && fn.name) ? fn.name : fn;
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
function formatErrorMeta(err) {
|
|
1129
|
-
if (!err.meta) return;
|
|
1130
|
-
var vcon = err.meta.vcon;
|
|
1131
|
-
var task = err.meta.task;
|
|
1132
|
-
var errString = '\n\n';
|
|
1133
|
-
if (task && task.f && task.a) {
|
|
1134
|
-
errString += ('Error occurs in Task function: ' + fName(task.f) + '(' + task.a.join(',') + ')\n\n');
|
|
1135
|
-
}
|
|
1136
|
-
if (vcon) {
|
|
1137
|
-
errString += 'Variable Context: \n';
|
|
1138
|
-
errString += util.inspect(vcon);
|
|
1139
|
-
errString += '\n\n';
|
|
1140
|
-
}
|
|
1141
|
-
if (task && task.f) {
|
|
1142
|
-
errString += 'Task Source:\n\n';
|
|
1143
|
-
errString += task.f.toString(); //TODO need to pretty print function, gets collapsed
|
|
1144
|
-
errString += '\n\n';
|
|
1145
|
-
}
|
|
1146
|
-
return errString;
|
|
1147
|
-
}
|
|
1148
|
-
|
|
1149
|
-
function augmentError(err, meta) {
|
|
1150
|
-
if (typeof(err) === 'string') { err = new Error(err); } //props will be lost on non-objects
|
|
1151
|
-
var origMsg = err.toString();
|
|
1152
|
-
err.meta = meta;
|
|
1153
|
-
err.toString = function () { return origMsg + formatErrorMeta(err); };
|
|
1154
|
-
return err;
|
|
1155
|
-
}
|
|
1156
|
-
|
|
1157
|
-
return {
|
|
1158
|
-
ensureStackTraceLimitSet: ensureStackTraceLimitSet,
|
|
1159
|
-
augmentError: augmentError
|
|
1160
|
-
};
|
|
1161
|
-
|
|
1162
|
-
});
|
|
1163
|
-
/*global define:true sprint:true */
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
define('react/sprintf',['util'], function (util) {
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
/**
|
|
1171
|
-
Abstract the details of getting a sprintf function.
|
|
1172
|
-
Currently using the simple format capabilities of node's util.format
|
|
1173
|
-
*/
|
|
1174
|
-
|
|
1175
|
-
var sprintf = util.format;
|
|
1176
|
-
return sprintf;
|
|
1177
|
-
|
|
1178
|
-
});
|
|
1179
|
-
(function (root, factory) {
|
|
1180
|
-
/*global define:true */
|
|
1181
|
-
|
|
1182
|
-
if (typeof exports === 'object') {
|
|
1183
|
-
// Node. Does not work with strict CommonJS, but
|
|
1184
|
-
// only CommonJS-like enviroments that support module.exports,
|
|
1185
|
-
// like Node.
|
|
1186
|
-
module.exports = factory();
|
|
1187
|
-
} else if (typeof define === 'function' && define.amd) {
|
|
1188
|
-
// AMD. Register as an anonymous module.
|
|
1189
|
-
define('ensure-array',[], factory);
|
|
1190
|
-
} else {
|
|
1191
|
-
// Browser globals
|
|
1192
|
-
root.ensureArray = factory();
|
|
1193
|
-
}
|
|
1194
|
-
}(this, function () {
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
function ensureArray(a, b, n) {
|
|
1198
|
-
if (arguments.length === 0) return []; //no args, ret []
|
|
1199
|
-
if (arguments.length === 1) { //single argument
|
|
1200
|
-
if (a === undefined || a === null) return []; // undefined or null, ret []
|
|
1201
|
-
if (Array.isArray(a)) return a; // isArray, return it
|
|
1202
|
-
}
|
|
1203
|
-
return Array.prototype.slice.call(arguments); //return array with copy of all arguments
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
return ensureArray;
|
|
1207
|
-
}));
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
/*global define:true */
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
define('react/status',[], function () {
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
var STATUS = { READY: 'ready', RUNNING: 'running', ERRORED: 'errored', COMPLETE: 'complete' };
|
|
1218
|
-
|
|
1219
|
-
return STATUS;
|
|
1220
|
-
|
|
1221
|
-
});
|
|
1222
|
-
/*global define:true process:false*/
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
define('react/event-manager',['./eventemitter'], function (EventEmitter) {
|
|
1227
|
-
|
|
1228
|
-
/*jshint regexp:false */
|
|
1229
|
-
|
|
1230
|
-
var EVENT_EMITTER2_CONFIG = {
|
|
1231
|
-
wildcard: true, // should the event emitter use wildcards.
|
|
1232
|
-
delimiter: '.', // the delimiter used to segment namespaces, defaults to `.`.
|
|
1233
|
-
maxListeners: 30 // the max number of listeners that can be assigned to an event, defaults to 10.
|
|
1234
|
-
};
|
|
1235
|
-
|
|
1236
|
-
var PASS_EVENTS_PROCESS_RE = /^ast.defined$/; // events to pass up to global process
|
|
1237
|
-
|
|
1238
|
-
var TYPES = {
|
|
1239
|
-
// Flow monitoring events and their params
|
|
1240
|
-
AST_DEFINED: 'ast.defined', // ast
|
|
1241
|
-
FLOW_BEGIN: 'flow.begin', // env
|
|
1242
|
-
TASK_BEGIN: 'task.begin', // task
|
|
1243
|
-
TASK_COMPLETE: 'task.complete', // task
|
|
1244
|
-
TASK_ERRORED: 'task.errored', // task
|
|
1245
|
-
FLOW_COMPLETE: 'flow.complete', // env
|
|
1246
|
-
FLOW_ERRORED: 'flow.errored', // env
|
|
1247
|
-
|
|
1248
|
-
// Internal Hooks
|
|
1249
|
-
EXEC_FLOW_START: 'exec.flow.start', // env
|
|
1250
|
-
EXEC_INPUT_PREPROCESS: 'exec.input.preprocess', // parsedInput
|
|
1251
|
-
EXEC_TASKS_PRECREATE: 'exec.tasks.precreate', // env
|
|
1252
|
-
EXEC_OUTTASK_CREATE: 'exec.outTask.create', // outTaskOptions
|
|
1253
|
-
EXEC_TASK_START: 'exec.task.start', // task
|
|
1254
|
-
EXEC_TASK_COMPLETE: 'exec.task.complete', // task
|
|
1255
|
-
EXEC_TASK_ERRORED: 'exec.task.errored', // task
|
|
1256
|
-
EXEC_FLOW_COMPLETE: 'exec.flow.complete', // env
|
|
1257
|
-
EXEC_FLOW_ERRORED: 'exec.flow.errored' // env
|
|
1258
|
-
};
|
|
1259
|
-
|
|
1260
|
-
/**
|
|
1261
|
-
Event manager which emits events up to its parent if exists.
|
|
1262
|
-
Allows a hierarchy of emitters, which communicate up the
|
|
1263
|
-
chain.
|
|
1264
|
-
*/
|
|
1265
|
-
function EventManager() {
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
EventManager.create = function () { return new EventManager(); };
|
|
1269
|
-
|
|
1270
|
-
EventManager.TYPES = TYPES;
|
|
1271
|
-
EventManager.prototype.TYPES = TYPES;
|
|
1272
|
-
|
|
1273
|
-
EventManager.prototype.isEnabled = function () { // if has listener or an ancestor has listener
|
|
1274
|
-
return !!(this.emitter || (this.parent && this.parent.isEnabled()));
|
|
1275
|
-
};
|
|
1276
|
-
|
|
1277
|
-
/**
|
|
1278
|
-
Add listener. Wildcard events are allowed like 'foo.*'
|
|
1279
|
-
Use '*' to listen to any event
|
|
1280
|
-
*/
|
|
1281
|
-
EventManager.prototype.on = function (event, listener) {
|
|
1282
|
-
if (!this.emitter) this.emitter = new EventEmitter(EVENT_EMITTER2_CONFIG);
|
|
1283
|
-
if (event === '*') this.emitter.onAny(listener);
|
|
1284
|
-
else this.emitter.on(event, listener);
|
|
1285
|
-
};
|
|
1286
|
-
|
|
1287
|
-
EventManager.prototype.emit = function (event, arg1, arg2, argN) {
|
|
1288
|
-
if (event === undefined) throw new Error('event is undefined');
|
|
1289
|
-
if (this.emitter) this.emitter.emit.apply(this.emitter, arguments);
|
|
1290
|
-
if (this.parent && this.parent.isEnabled()) this.parent.emit.apply(this.parent, arguments);
|
|
1291
|
-
if (PASS_EVENTS_PROCESS_RE.test(event) && typeof(process) !== 'undefined' && process.emit) {
|
|
1292
|
-
process.emit.apply(process, arguments); // pass some to process
|
|
1293
|
-
}
|
|
1294
|
-
};
|
|
1295
|
-
|
|
1296
|
-
EventManager.prototype.removeListener = function (event, listener) {
|
|
1297
|
-
if (this.emitter) this.emitter.removeListener.apply(this.emitter, arguments);
|
|
1298
|
-
};
|
|
1299
|
-
|
|
1300
|
-
EventManager.prototype.removeAllListeners = function (event) {
|
|
1301
|
-
if (this.emitter) this.emitter.removeAllListeners.apply(this.emitter, arguments);
|
|
1302
|
-
};
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
EventManager.global = EventManager.create(); // create one top level emitter
|
|
1306
|
-
return EventManager;
|
|
1307
|
-
|
|
1308
|
-
});
|
|
1309
|
-
/*global define:true */
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
define('react/base-task',['ensure-array', './status', './event-manager'],
|
|
1314
|
-
function (array, STATUS, EventManager) {
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
function BaseTask() {
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
/**
|
|
1321
|
-
Getter Fn to retrieveAn array of the output param names for this task.
|
|
1322
|
-
*/
|
|
1323
|
-
BaseTask.prototype.getOutParams = function () {
|
|
1324
|
-
return array(this.out); // ensure array
|
|
1325
|
-
};
|
|
1326
|
-
|
|
1327
|
-
BaseTask.prototype.isComplete = function () {
|
|
1328
|
-
return (this.status === STATUS.COMPLETE);
|
|
1329
|
-
};
|
|
1330
|
-
|
|
1331
|
-
BaseTask.prototype.start = function (args) { // mark task as started with args and note time
|
|
1332
|
-
/*jshint validthis: true */
|
|
1333
|
-
this.args = args;
|
|
1334
|
-
this.env.currentTask = this;
|
|
1335
|
-
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_START, this);
|
|
1336
|
-
};
|
|
1337
|
-
|
|
1338
|
-
BaseTask.prototype.complete = function (args) { //args that were used are available
|
|
1339
|
-
/*jshint validthis: true */
|
|
1340
|
-
this.status = STATUS.COMPLETE;
|
|
1341
|
-
this.results = args;
|
|
1342
|
-
this.env.currentTask = this;
|
|
1343
|
-
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_COMPLETE, this);
|
|
1344
|
-
};
|
|
1345
|
-
|
|
1346
|
-
BaseTask.prototype.functionExists = function (vCon) {
|
|
1347
|
-
var fn = this.f;
|
|
1348
|
-
if (!fn) return false;
|
|
1349
|
-
if (fn instanceof Function) return true;
|
|
1350
|
-
if (typeof(fn) === 'string') {
|
|
1351
|
-
var f = vCon.getVar(fn); // fn/method by string
|
|
1352
|
-
if (f && f instanceof Function) return true;
|
|
1353
|
-
}
|
|
1354
|
-
return false;
|
|
1355
|
-
};
|
|
1356
|
-
|
|
1357
|
-
BaseTask.prototype.areAllDepArgsDefined = function (vCon) {
|
|
1358
|
-
return this.a.every(function (k) { return (vCon.getVar(k) !== undefined); });
|
|
1359
|
-
};
|
|
1360
|
-
|
|
1361
|
-
BaseTask.prototype.depTasksAreDone = function (tasksByName) {
|
|
1362
|
-
return (!this.after || !this.after.length || // no dep tasks OR
|
|
1363
|
-
this.after.every(function (n) { return tasksByName[n].isComplete(); })); //all done
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
|
-
function isObjProperty(str) { return (str.indexOf('.') !== -1); }
|
|
1367
|
-
|
|
1368
|
-
/**
|
|
1369
|
-
check that obj parent is def and not null so writing to obj.prop
|
|
1370
|
-
will not fail. ex: 'b.c' checks that b is def and not null.
|
|
1371
|
-
Also returns true if not obj.prop but simple var ex: 'b'.
|
|
1372
|
-
Tasks will implement outParentsExist() passing each out str
|
|
1373
|
-
to this if they want to do this check.
|
|
1374
|
-
*/
|
|
1375
|
-
BaseTask.prototype.parentExists = function (objPropStr, vCon) {
|
|
1376
|
-
if (!isObjProperty(objPropStr)) return true; // NOT obj prop, just simple arg, ret true
|
|
1377
|
-
var nameAndProps = objPropStr.split('.');
|
|
1378
|
-
nameAndProps.pop(); // pop off final prop
|
|
1379
|
-
var parent = nameAndProps.reduce(function (accObj, prop) {
|
|
1380
|
-
if (accObj === undefined || accObj === null) return undefined; // prevent exception
|
|
1381
|
-
return accObj[prop];
|
|
1382
|
-
}, vCon.values); // vCon['foo']['bar']
|
|
1383
|
-
return (parent !== undefined && parent !== null);
|
|
1384
|
-
};
|
|
1385
|
-
|
|
1386
|
-
/**
|
|
1387
|
-
If params are obj property writes make sure the dst objects
|
|
1388
|
-
are defined and not null. cb: ['b.c'] -> b is def and not null.
|
|
1389
|
-
If null is specified then param is valid and will be ignored.
|
|
1390
|
-
@returns true if all obj prop parents are def and non null
|
|
1391
|
-
*/
|
|
1392
|
-
BaseTask.prototype.outParentsExist = function (vCon) {
|
|
1393
|
-
var self = this;
|
|
1394
|
-
return this.getOutParams().every(function (x) {
|
|
1395
|
-
if (x === null) return true;
|
|
1396
|
-
return self.parentExists(x, vCon);
|
|
1397
|
-
});
|
|
1398
|
-
};
|
|
1399
|
-
|
|
1400
|
-
BaseTask.prototype.isReady = function (vCon, tasksByName) {
|
|
1401
|
-
return !this.status && // not started AND
|
|
1402
|
-
this.functionExists(vCon) && // function/method exists AND
|
|
1403
|
-
this.areAllDepArgsDefined(vCon) && // all dep vars defined AND
|
|
1404
|
-
this.depTasksAreDone(tasksByName) && // all dep tasks are done AND
|
|
1405
|
-
(!this.outParentsExist || // (task does not implement outParentsExist method OR
|
|
1406
|
-
this.outParentsExist(vCon)); // output parents exists (for obj property writes)
|
|
1407
|
-
};
|
|
1408
|
-
|
|
1409
|
-
BaseTask.prototype.isMethodCall = function () {
|
|
1410
|
-
/*jshint regexp: false */
|
|
1411
|
-
return (typeof(this.f) === 'string' && /^.*\..*$/.test(this.f)); //str contains .
|
|
1412
|
-
};
|
|
1413
|
-
|
|
1414
|
-
BaseTask.prototype.getMethodObj = function (vCon) { //obj.prop.prop2, returns obj.prop or undefined
|
|
1415
|
-
var name = this.f;
|
|
1416
|
-
if (!name) return undefined;
|
|
1417
|
-
var nameAndProps = name.split('.');
|
|
1418
|
-
nameAndProps.pop(); // pop off last one
|
|
1419
|
-
if (!nameAndProps.length) return undefined;
|
|
1420
|
-
var result = vCon.resolveNameArr(nameAndProps);
|
|
1421
|
-
return result;
|
|
1422
|
-
};
|
|
1423
|
-
|
|
1424
|
-
return BaseTask;
|
|
1425
|
-
|
|
1426
|
-
});
|
|
1427
|
-
|
|
1428
|
-
/*global define:true */
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
define('react/cb-task',['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
function format_error(errmsg, obj) {
|
|
1436
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
var REQ = 'cbTask requires f, a, out';
|
|
1440
|
-
var FN_REQ = 'cbTask requires f to be a function or string';
|
|
1441
|
-
var A_REQ = 'cbTask requires a to be an array of string param names';
|
|
1442
|
-
var CB_REQ = 'cbTask requires out to be an array of string param names';
|
|
1443
|
-
|
|
1444
|
-
function CbTask(taskDef) {
|
|
1445
|
-
var self = this;
|
|
1446
|
-
Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
CbTask.prototype = new BaseTask();
|
|
1450
|
-
CbTask.prototype.constructor = CbTask;
|
|
1451
|
-
|
|
1452
|
-
CbTask.validate = function (taskDef) {
|
|
1453
|
-
var errors = [];
|
|
1454
|
-
if (!taskDef.f || !taskDef.a || !taskDef.out) {
|
|
1455
|
-
errors.push(format_error(REQ, taskDef));
|
|
1456
|
-
} else {
|
|
1457
|
-
var ftype = typeof(taskDef.f);
|
|
1458
|
-
if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
|
|
1459
|
-
errors.push(format_error(FN_REQ, taskDef));
|
|
1460
|
-
}
|
|
1461
|
-
if (! (Array.isArray(taskDef.a) &&
|
|
1462
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1463
|
-
errors.push(format_error(A_REQ, taskDef));
|
|
1464
|
-
}
|
|
1465
|
-
if (! (Array.isArray(taskDef.out) &&
|
|
1466
|
-
taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1467
|
-
errors.push(format_error(CB_REQ, taskDef));
|
|
1468
|
-
}
|
|
1469
|
-
}
|
|
1470
|
-
return errors;
|
|
1471
|
-
};
|
|
1472
|
-
|
|
1473
|
-
CbTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
|
|
1474
|
-
var self = this;
|
|
1475
|
-
this.cbFun = function (err, arg0, arg1, argn) {
|
|
1476
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
|
1477
|
-
if (err) { handleTaskError(self, err); return; } //handle error and return, we are done
|
|
1478
|
-
|
|
1479
|
-
//no error, save callback args to vCon context, then continue execution
|
|
1480
|
-
vCon.saveResults(self.out, args);
|
|
1481
|
-
self.complete(args);
|
|
1482
|
-
contExec();
|
|
1483
|
-
};
|
|
1484
|
-
};
|
|
1485
|
-
|
|
1486
|
-
CbTask.prototype.exec = function exec(vCon, handleError, contExec) {
|
|
1487
|
-
try {
|
|
1488
|
-
var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
|
|
1489
|
-
//console.error('CbTask.exec.args=', args);
|
|
1490
|
-
//console.error('CbTask.exec.vCon=', vCon);
|
|
1491
|
-
this.start(args); //note the start time, args
|
|
1492
|
-
args.push(this.cbFun); // push callback fn on end
|
|
1493
|
-
var func = this.f;
|
|
1494
|
-
var bindObj = vCon.getVar('this'); //global space or the original this
|
|
1495
|
-
if (this.isMethodCall()) { //if method call then reset func and bindObj
|
|
1496
|
-
func = vCon.getVar(this.f);
|
|
1497
|
-
bindObj = this.getMethodObj(vCon);
|
|
1498
|
-
} else if (typeof(func) === 'string') {
|
|
1499
|
-
func = vCon.getVar(func); // we want the actual fn from this string
|
|
1500
|
-
}
|
|
1501
|
-
func.apply(bindObj, args);
|
|
1502
|
-
} catch (err) { //catch and handle the task error, calling final cb
|
|
1503
|
-
handleError(this, err);
|
|
1504
|
-
}
|
|
1505
|
-
};
|
|
1506
|
-
|
|
1507
|
-
return CbTask;
|
|
1508
|
-
|
|
1509
|
-
});
|
|
1510
|
-
|
|
1511
|
-
/*global define:true */
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
define('react/promise-task',['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
/**
|
|
1519
|
-
PromiseTask is a task which executes a fn that returns a promise
|
|
1520
|
-
and when it completes it sets the values in vCon
|
|
1521
|
-
*/
|
|
1522
|
-
|
|
1523
|
-
function format_error(errmsg, obj) {
|
|
1524
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
1525
|
-
}
|
|
1526
|
-
|
|
1527
|
-
var REQ = 'promiseTask requires f, a, out';
|
|
1528
|
-
var FN_REQ = 'promiseTask requires f to be a function or string';
|
|
1529
|
-
var A_REQ = 'promiseTask requires a to be an array of string param names';
|
|
1530
|
-
var OUT_REQ = 'promiseTask requires out to be an array[1] of string param names';
|
|
1531
|
-
|
|
1532
|
-
function PromiseTask(taskDef) {
|
|
1533
|
-
var self = this;
|
|
1534
|
-
Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
|
|
1535
|
-
}
|
|
1536
|
-
|
|
1537
|
-
PromiseTask.prototype = new BaseTask();
|
|
1538
|
-
PromiseTask.prototype.constructor = PromiseTask;
|
|
1539
|
-
|
|
1540
|
-
PromiseTask.validate = function (taskDef) {
|
|
1541
|
-
var errors = [];
|
|
1542
|
-
if (!taskDef.f || !taskDef.a || !taskDef.out) {
|
|
1543
|
-
errors.push(format_error(REQ, taskDef));
|
|
1544
|
-
} else {
|
|
1545
|
-
var ftype = typeof(taskDef.f);
|
|
1546
|
-
if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
|
|
1547
|
-
errors.push(format_error(FN_REQ, taskDef));
|
|
1548
|
-
}
|
|
1549
|
-
if (! (Array.isArray(taskDef.a) &&
|
|
1550
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1551
|
-
errors.push(format_error(A_REQ, taskDef));
|
|
1552
|
-
}
|
|
1553
|
-
if (! (Array.isArray(taskDef.out) && taskDef.out.length <= 1 &&
|
|
1554
|
-
taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1555
|
-
errors.push(format_error(OUT_REQ, taskDef));
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
return errors;
|
|
1559
|
-
};
|
|
1560
|
-
|
|
1561
|
-
PromiseTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
|
|
1562
|
-
var self = this;
|
|
1563
|
-
this.nextFn = function (arg) {
|
|
1564
|
-
var args = Array.prototype.slice.call(arguments);
|
|
1565
|
-
vCon.saveResults(self.out, args);
|
|
1566
|
-
self.complete(args);
|
|
1567
|
-
contExec();
|
|
1568
|
-
};
|
|
1569
|
-
this.failFn = function (err) {
|
|
1570
|
-
handleTaskError(self, err);
|
|
1571
|
-
};
|
|
1572
|
-
};
|
|
1573
|
-
|
|
1574
|
-
PromiseTask.prototype.exec = function exec(vCon, handleError, contExec) {
|
|
1575
|
-
try {
|
|
1576
|
-
var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
|
|
1577
|
-
//console.error('PromiseTask.exec.args=', args);
|
|
1578
|
-
//console.error('PromiseTask.exec.vCon=', vCon);
|
|
1579
|
-
this.start(args); //note the start time, args
|
|
1580
|
-
var func = this.f;
|
|
1581
|
-
var bindObj = vCon.getVar('this'); //global space or the original this
|
|
1582
|
-
if (this.isMethodCall()) { //if method call then reset func and bindObj
|
|
1583
|
-
func = vCon.getVar(this.f);
|
|
1584
|
-
bindObj = this.getMethodObj(vCon);
|
|
1585
|
-
} else if (typeof(func) === 'string') {
|
|
1586
|
-
func = vCon.getVar(func); // we want the actual fn from this string
|
|
1587
|
-
}
|
|
1588
|
-
var retValue = func.apply(bindObj, args);
|
|
1589
|
-
if (retValue && typeof(retValue.then) === 'function') { // is a promise
|
|
1590
|
-
retValue.then(this.nextFn, this.failFn);
|
|
1591
|
-
} else { // just a value, proceed now
|
|
1592
|
-
this.nextFn(retValue);
|
|
1593
|
-
}
|
|
1594
|
-
} catch (err) { //catch and handle the task error, calling final cb
|
|
1595
|
-
handleError(this, err);
|
|
1596
|
-
}
|
|
1597
|
-
};
|
|
1598
|
-
|
|
1599
|
-
return PromiseTask;
|
|
1600
|
-
|
|
1601
|
-
});
|
|
1602
|
-
/*global define:true */
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
define('react/ret-task',['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
function format_error(errmsg, obj) {
|
|
1610
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
var REQ = 'retTask requires f, a, out';
|
|
1614
|
-
var FN_REQ = 'retTask requires f to be a function or string';
|
|
1615
|
-
var A_REQ = 'retTask requires a to be an array of string param names';
|
|
1616
|
-
var RET_REQ = 'retTask requires out to be an array with single string param name or []';
|
|
1617
|
-
|
|
1618
|
-
function RetTask(taskDef) {
|
|
1619
|
-
var self = this;
|
|
1620
|
-
Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
RetTask.prototype = new BaseTask();
|
|
1624
|
-
RetTask.prototype.constructor = RetTask;
|
|
1625
|
-
|
|
1626
|
-
RetTask.validate = function (taskDef) {
|
|
1627
|
-
var errors = [];
|
|
1628
|
-
if (!taskDef.f || !taskDef.a || !taskDef.out) {
|
|
1629
|
-
errors.push(format_error(REQ, taskDef));
|
|
1630
|
-
} else {
|
|
1631
|
-
var ftype = typeof(taskDef.f);
|
|
1632
|
-
if (! ((taskDef.f instanceof Function) || (ftype === 'string'))) {
|
|
1633
|
-
errors.push(format_error(FN_REQ, taskDef));
|
|
1634
|
-
}
|
|
1635
|
-
if (! (Array.isArray(taskDef.a) &&
|
|
1636
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1637
|
-
errors.push(format_error(A_REQ, taskDef));
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
if (! (Array.isArray(taskDef.out) &&
|
|
1641
|
-
(taskDef.out.length === 0 ||
|
|
1642
|
-
(taskDef.out.length === 1 && typeof(taskDef.out[0] === 'string'))))) {
|
|
1643
|
-
errors.push(format_error(RET_REQ, taskDef));
|
|
1644
|
-
}
|
|
1645
|
-
}
|
|
1646
|
-
return errors;
|
|
1647
|
-
};
|
|
1648
|
-
|
|
1649
|
-
RetTask.prototype.exec = function exec(vCon, handleError, contExec) {
|
|
1650
|
-
try {
|
|
1651
|
-
var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
|
|
1652
|
-
this.start(args); //note the start time, args
|
|
1653
|
-
var func = this.f;
|
|
1654
|
-
var bindObj = vCon.getVar('this'); //global space or the original this
|
|
1655
|
-
if (this.isMethodCall()) { //if method call then reset func and bindObj
|
|
1656
|
-
func = vCon.getVar(this.f);
|
|
1657
|
-
bindObj = this.getMethodObj(vCon);
|
|
1658
|
-
} else if (typeof(func) === 'string') {
|
|
1659
|
-
func = vCon.getVar(func); // we want the actual fn from this string
|
|
1660
|
-
}
|
|
1661
|
-
var results = [func.apply(bindObj, args)];
|
|
1662
|
-
vCon.saveResults(this.out, results); // save retval, takes arrays
|
|
1663
|
-
this.complete(results);
|
|
1664
|
-
contExec(); // continue since no callback to run this
|
|
1665
|
-
} catch (err) { handleError(this, err); } // catch and handle the task error, calling final cb
|
|
1666
|
-
};
|
|
1667
|
-
|
|
1668
|
-
return RetTask;
|
|
1669
|
-
|
|
1670
|
-
});
|
|
1671
|
-
/*global define:true */
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
define('react/when-task',['util', './sprintf', './base-task'], function (util, sprintf, BaseTask) {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
/**
|
|
1679
|
-
When task which checks if is a promise (has a then method)
|
|
1680
|
-
and waits for it to resolve.
|
|
1681
|
-
|
|
1682
|
-
If argument does not have a then method, it resolves immediately
|
|
1683
|
-
*/
|
|
1684
|
-
|
|
1685
|
-
function format_error(errmsg, obj) {
|
|
1686
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
1687
|
-
}
|
|
1688
|
-
|
|
1689
|
-
var REQ = 'whenTask requires a, out';
|
|
1690
|
-
var A_REQ = 'whenTask requires a to be an array[1] of string param names';
|
|
1691
|
-
var OUT_REQ = 'whenTask requires out to be an array[1] of string param names';
|
|
1692
|
-
|
|
1693
|
-
function WhenTask(taskDef) {
|
|
1694
|
-
var self = this;
|
|
1695
|
-
Object.keys(taskDef).forEach(function (k) { self[k] = taskDef[k]; });
|
|
1696
|
-
}
|
|
1697
|
-
|
|
1698
|
-
WhenTask.prototype = new BaseTask();
|
|
1699
|
-
WhenTask.prototype.constructor = WhenTask;
|
|
1700
|
-
|
|
1701
|
-
WhenTask.prototype.f = function when() { }; // just here to keep validations happy
|
|
1702
|
-
|
|
1703
|
-
WhenTask.validate = function (taskDef) {
|
|
1704
|
-
var errors = [];
|
|
1705
|
-
if (!taskDef.a || !taskDef.out) {
|
|
1706
|
-
errors.push(format_error(REQ, taskDef));
|
|
1707
|
-
} else {
|
|
1708
|
-
if (! (Array.isArray(taskDef.a) && taskDef.a.length === 1 &&
|
|
1709
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1710
|
-
errors.push(format_error(A_REQ, taskDef));
|
|
1711
|
-
}
|
|
1712
|
-
if (! (Array.isArray(taskDef.out) && taskDef.out.length <= 1 &&
|
|
1713
|
-
taskDef.out.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1714
|
-
errors.push(format_error(OUT_REQ, taskDef));
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
return errors;
|
|
1718
|
-
};
|
|
1719
|
-
|
|
1720
|
-
WhenTask.prototype.prepare = function prepare(handleTaskError, vCon, contExec) {
|
|
1721
|
-
var self = this;
|
|
1722
|
-
this.nextFn = function (arg) {
|
|
1723
|
-
var args = Array.prototype.slice.call(arguments);
|
|
1724
|
-
vCon.saveResults(self.out, args);
|
|
1725
|
-
self.complete(args);
|
|
1726
|
-
contExec();
|
|
1727
|
-
};
|
|
1728
|
-
this.failFn = function (err) {
|
|
1729
|
-
handleTaskError(self, err);
|
|
1730
|
-
};
|
|
1731
|
-
};
|
|
1732
|
-
|
|
1733
|
-
WhenTask.prototype.exec = function exec(vCon, handleError, contExec) {
|
|
1734
|
-
try {
|
|
1735
|
-
var args = this.a.map(function (k) { return vCon.getVar(k); }); //get args from vCon
|
|
1736
|
-
//console.error('WhenTask.exec.args=', args);
|
|
1737
|
-
//console.error('WhenTask.exec.vCon=', vCon);
|
|
1738
|
-
this.start(args); //note the start time, args
|
|
1739
|
-
var arg = args[0]; // one value allowed
|
|
1740
|
-
if (arg && typeof(arg.then) === 'function') { // is a promise
|
|
1741
|
-
arg.then(this.nextFn, this.failFn);
|
|
1742
|
-
} else { // not a promise continue immediately
|
|
1743
|
-
this.nextFn(arg);
|
|
1744
|
-
}
|
|
1745
|
-
} catch (err) { //catch and handle the task error, calling final cb
|
|
1746
|
-
handleError(this, err);
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
|
|
1750
|
-
return WhenTask;
|
|
1751
|
-
|
|
1752
|
-
});
|
|
1753
|
-
/*global define:true */
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
define('react/finalcb-task',['./sprintf', 'util', './status', './event-manager'],
|
|
1758
|
-
function (sprintf, util, STATUS, EventManager) {
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
|
|
1762
|
-
|
|
1763
|
-
function FinalCbTask(outTaskOptions) {
|
|
1764
|
-
var taskDef = outTaskOptions.taskDef;
|
|
1765
|
-
if (typeof(outTaskOptions.cbFunc) !== 'function') throw new Error('callback is not a function');
|
|
1766
|
-
var self = this;
|
|
1767
|
-
for (var k in taskDef) {
|
|
1768
|
-
if (true) self[k] = taskDef[k]; // if to make jshint happy
|
|
1769
|
-
}
|
|
1770
|
-
this.f = outTaskOptions.cbFunc;
|
|
1771
|
-
this.tasks = outTaskOptions.tasks;
|
|
1772
|
-
this.vCon = outTaskOptions.vCon;
|
|
1773
|
-
this.retValue = outTaskOptions.retValue;
|
|
1774
|
-
this.execOptions = outTaskOptions.execOptions;
|
|
1775
|
-
this.env = outTaskOptions.env;
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
function format_error(errmsg, obj) {
|
|
1779
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
FinalCbTask.validate = function (taskDef) {
|
|
1784
|
-
var errors = [];
|
|
1785
|
-
if (! (Array.isArray(taskDef.a) &&
|
|
1786
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1787
|
-
errors.push(format_error(OUTTASK_A_REQ, taskDef));
|
|
1788
|
-
}
|
|
1789
|
-
return errors;
|
|
1790
|
-
};
|
|
1791
|
-
|
|
1792
|
-
FinalCbTask.prototype.isReady = function () {
|
|
1793
|
-
return (this.tasks.every(function (t) { return (t.status === STATUS.COMPLETE); }));
|
|
1794
|
-
};
|
|
1795
|
-
|
|
1796
|
-
FinalCbTask.prototype.exec = function (err) {
|
|
1797
|
-
if (!this.f) return; //must have already been called
|
|
1798
|
-
if (err) {
|
|
1799
|
-
this.env.error = err;
|
|
1800
|
-
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_ERRORED, this.env);
|
|
1801
|
-
this.f.call(null, err); //call the final callback with the first error hit
|
|
1802
|
-
} else { // no error, call with args
|
|
1803
|
-
var vCon = this.vCon;
|
|
1804
|
-
var finalArgs = this.a.map(function (k) { return vCon.getVar(k); });
|
|
1805
|
-
finalArgs.unshift(null); //unshift err=null to front
|
|
1806
|
-
this.env.results = finalArgs;
|
|
1807
|
-
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_COMPLETE, this.env);
|
|
1808
|
-
this.f.apply(null, finalArgs);
|
|
1809
|
-
}
|
|
1810
|
-
this.f = null; // prevent multiple calls
|
|
1811
|
-
};
|
|
1812
|
-
|
|
1813
|
-
return FinalCbTask;
|
|
1814
|
-
|
|
1815
|
-
});
|
|
1816
|
-
/*global define:true */
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
define('react/vcon',[], function () {
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
var LAST_RESULTS_KEY = ':LAST_RESULTS';
|
|
1824
|
-
|
|
1825
|
-
function VContext() {
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
VContext.prototype.getLastResults = function () { return this.getVar(LAST_RESULTS_KEY); };
|
|
1829
|
-
VContext.prototype.setLastResults = function (args) { this.setVar(LAST_RESULTS_KEY, args); };
|
|
1830
|
-
|
|
1831
|
-
VContext.prototype.getVar = function (name) { //name might be simple or obj.prop, also literals
|
|
1832
|
-
/*jshint regexp: false */
|
|
1833
|
-
var vConValues = this.values;
|
|
1834
|
-
if (typeof(name) !== 'string') return name; // literal boolean or number
|
|
1835
|
-
name = name.trim();
|
|
1836
|
-
// literal checks need to match what is in validate.js
|
|
1837
|
-
if (name === 'true') return true;
|
|
1838
|
-
if (name === 'false') return false;
|
|
1839
|
-
if (name === 'null') return null;
|
|
1840
|
-
if (/^-?[0-9]+$/.test(name)) return parseInt(name, 10); //int
|
|
1841
|
-
if (/^-?[0-9.]+$/.test(name)) return parseFloat(name); //float
|
|
1842
|
-
var m = /^("|')([^\1]*)\1$/.exec(name); //check for quoted string " or '
|
|
1843
|
-
if (m) return m[2]; // if is quoted str, return inside of the quotes
|
|
1844
|
-
var nameAndProps = name.split('.');
|
|
1845
|
-
var result = this.resolveNameArr(nameAndProps);
|
|
1846
|
-
return result;
|
|
1847
|
-
};
|
|
1848
|
-
|
|
1849
|
-
VContext.prototype.resolveNameArr = function (nameAndProps) {
|
|
1850
|
-
var vConValues = this.values;
|
|
1851
|
-
var result = nameAndProps.reduce(function (accObj, prop) {
|
|
1852
|
-
if (accObj === undefined || accObj === null) return undefined; // prevent exception
|
|
1853
|
-
return accObj[prop];
|
|
1854
|
-
}, vConValues); // vCon['foo']['bar']
|
|
1855
|
-
if (result === undefined && this.global !== undefined) { // see if matches any global
|
|
1856
|
-
result = nameAndProps.reduce(function (accObj, prop) {
|
|
1857
|
-
if (accObj === undefined || accObj === null) return undefined; // prevent exception
|
|
1858
|
-
return accObj[prop];
|
|
1859
|
-
}, this.global); // global['foo']['bar']
|
|
1860
|
-
}
|
|
1861
|
-
return result;
|
|
1862
|
-
};
|
|
1863
|
-
|
|
1864
|
-
/**
|
|
1865
|
-
Saves all the results from a task as a unit, also sets special
|
|
1866
|
-
variable :LAST_RESULTS which keeps an array of the last values
|
|
1867
|
-
which can be used for chaining and testing last results, etc.
|
|
1868
|
-
*/
|
|
1869
|
-
VContext.prototype.saveResults = function (paramArr, valuesArr) { // set values for params
|
|
1870
|
-
var self = this;
|
|
1871
|
-
paramArr.forEach(function (k, idx) { //save values to v context
|
|
1872
|
-
self.setVar(k, (valuesArr[idx] !== undefined) ? valuesArr[idx] : null); //upgrade any undefined to null
|
|
1873
|
-
});
|
|
1874
|
-
this.setLastResults(valuesArr);
|
|
1875
|
-
};
|
|
1876
|
-
|
|
1877
|
-
VContext.prototype.setVar = function (name, value) { //name might be simple or obj.prop
|
|
1878
|
-
if (!name) return; // if name is undefined or null, then discard
|
|
1879
|
-
var vConValues = this.values;
|
|
1880
|
-
var nameAndProps = name.split('.');
|
|
1881
|
-
var lastProp = nameAndProps.pop();
|
|
1882
|
-
var obj = nameAndProps.reduce(function (accObj, prop) {
|
|
1883
|
-
var o = accObj[prop];
|
|
1884
|
-
if (o === undefined || o === null) { // if doesn't exist create it
|
|
1885
|
-
o = accObj[prop] = { };
|
|
1886
|
-
}
|
|
1887
|
-
return o;
|
|
1888
|
-
}, vConValues); // vCon['foo']['bar']
|
|
1889
|
-
obj[lastProp] = value;
|
|
1890
|
-
};
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
/**
|
|
1894
|
-
Create Variable Context using arguments passed in.
|
|
1895
|
-
Ignore extra arguments passed in. Locals can be
|
|
1896
|
-
passed into seed the VContext otherwise empty {}
|
|
1897
|
-
will be used
|
|
1898
|
-
@param self used to pass 'this' context in
|
|
1899
|
-
*/
|
|
1900
|
-
VContext.create = function (args, inParams, locals, self) {
|
|
1901
|
-
/*jshint validthis:true, evil:true */
|
|
1902
|
-
var initValues = {};
|
|
1903
|
-
if (self) initValues['this'] = self;
|
|
1904
|
-
if (locals) Object.keys(locals).forEach(function (k) { initValues[k] = locals[k]; }); // copy over keys
|
|
1905
|
-
var vContext = new VContext();
|
|
1906
|
-
vContext.values = args.reduce(function (vcon, x, idx) { // create vCon start with input args
|
|
1907
|
-
var param = inParams[idx];
|
|
1908
|
-
if (param) vcon[param] = (x !== undefined) ? x : null; // upgrade undefined to null
|
|
1909
|
-
return vcon;
|
|
1910
|
-
}, initValues);
|
|
1911
|
-
|
|
1912
|
-
// add in global
|
|
1913
|
-
if (typeof global === 'object') { // node.js and modern browsers expose global
|
|
1914
|
-
vContext.global = global;
|
|
1915
|
-
} else { // try to access this using Function eval of this
|
|
1916
|
-
// http://stackoverflow.com/questions/3277182/how-to-get-the-global-object-in-javascript
|
|
1917
|
-
vContext.global = new Function('return this')();
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
return vContext;
|
|
1921
|
-
};
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
return VContext;
|
|
1925
|
-
|
|
1926
|
-
});
|
|
1927
|
-
|
|
1928
|
-
/*global define:true */
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
define('react/finalcb-first-task',['./sprintf', 'util', './status', './vcon', './event-manager'],
|
|
1933
|
-
function (sprintf, util, STATUS, VContext, EventManager) {
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
var OUTTASK_A_REQ = 'ast.outTask.a should be an array of string param names';
|
|
1937
|
-
|
|
1938
|
-
function FinalCbFirstSuccTask(outTaskOptions) {
|
|
1939
|
-
var taskDef = outTaskOptions.taskDef;
|
|
1940
|
-
if (typeof(outTaskOptions.cbFunc) !== 'function') throw new Error('callback is not a function');
|
|
1941
|
-
var self = this;
|
|
1942
|
-
for (var k in taskDef) {
|
|
1943
|
-
if (true) self[k] = taskDef[k]; // if to make jshint happy
|
|
1944
|
-
}
|
|
1945
|
-
this.f = outTaskOptions.cbFunc;
|
|
1946
|
-
this.tasks = outTaskOptions.tasks;
|
|
1947
|
-
this.vCon = outTaskOptions.vCon;
|
|
1948
|
-
this.retValue = outTaskOptions.retValue;
|
|
1949
|
-
this.env = outTaskOptions.env;
|
|
1950
|
-
}
|
|
1951
|
-
|
|
1952
|
-
function format_error(errmsg, obj) {
|
|
1953
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
1954
|
-
}
|
|
1955
|
-
|
|
1956
|
-
FinalCbFirstSuccTask.validate = function (taskDef) {
|
|
1957
|
-
var errors = [];
|
|
1958
|
-
if (! (Array.isArray(taskDef.a) &&
|
|
1959
|
-
taskDef.a.every(function (x) { return (typeof(x) === 'string'); }))) {
|
|
1960
|
-
errors.push(format_error(OUTTASK_A_REQ, taskDef));
|
|
1961
|
-
}
|
|
1962
|
-
return errors;
|
|
1963
|
-
};
|
|
1964
|
-
|
|
1965
|
-
/**
|
|
1966
|
-
is ready to exit when any task comes back with non-null defined value
|
|
1967
|
-
*/
|
|
1968
|
-
FinalCbFirstSuccTask.prototype.isReady = function () {
|
|
1969
|
-
var lastres = this.vCon.getLastResults();
|
|
1970
|
-
if (!lastres) return false; // no results yet
|
|
1971
|
-
return (lastres.some(function (v) { return (v !== undefined && v !== null); }));
|
|
1972
|
-
};
|
|
1973
|
-
|
|
1974
|
-
FinalCbFirstSuccTask.prototype.exec = function (err) {
|
|
1975
|
-
if (!this.f) return; //must have already been called
|
|
1976
|
-
if (err) {
|
|
1977
|
-
this.env.error = err;
|
|
1978
|
-
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_ERRORED, this.env);
|
|
1979
|
-
this.f.call(null, err); //call the final callback with the first error hit
|
|
1980
|
-
} else { // no error, call with args
|
|
1981
|
-
var vCon = this.vCon;
|
|
1982
|
-
var finalArgs = this.a.map(function (k) { return vCon.getVar(k); });
|
|
1983
|
-
finalArgs.unshift(null); //unshift err=null to front
|
|
1984
|
-
this.env.results = finalArgs;
|
|
1985
|
-
this.env.flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_COMPLETE, this.env);
|
|
1986
|
-
this.f.apply(null, finalArgs);
|
|
1987
|
-
}
|
|
1988
|
-
this.f = null; // prevent multiple calls
|
|
1989
|
-
};
|
|
1990
|
-
|
|
1991
|
-
return FinalCbFirstSuccTask;
|
|
1992
|
-
|
|
1993
|
-
});
|
|
1994
|
-
/*global define:true */
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
define('react/task',['util', './sprintf', 'ensure-array', './cb-task', './promise-task',
|
|
1999
|
-
'./ret-task', './when-task', './finalcb-task', './finalcb-first-task',
|
|
2000
|
-
'./status', './error', './vcon', './event-manager'],
|
|
2001
|
-
function (util, sprintf, array, CbTask, PromiseTask,
|
|
2002
|
-
RetTask, WhenTask, FinalCbTask, FinalCbFirstSuccTask,
|
|
2003
|
-
STATUS, error, VContext, EventManager) {
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
var TASK_TYPES = {
|
|
2007
|
-
cb: CbTask,
|
|
2008
|
-
ret: RetTask,
|
|
2009
|
-
promise: PromiseTask,
|
|
2010
|
-
when: WhenTask
|
|
2011
|
-
};
|
|
2012
|
-
|
|
2013
|
-
var DEFAULT_TASK_NAME = 'task_%s'; // for unnamed tasks use task_idx, like task_0
|
|
2014
|
-
|
|
2015
|
-
function taskTypeKeys() { return Object.keys(TASK_TYPES); }
|
|
2016
|
-
|
|
2017
|
-
var OUT_TASK_TYPES = {
|
|
2018
|
-
finalcb: FinalCbTask, //first task is the default if no type specified in taskDef
|
|
2019
|
-
finalcbFirst: FinalCbFirstSuccTask
|
|
2020
|
-
};
|
|
2021
|
-
function outTaskTypeKeys() { return Object.keys(OUT_TASK_TYPES); }
|
|
2022
|
-
|
|
2023
|
-
var LOCAL_FN_MISSING = 'function: %s not found in locals or input params - task[%s]';
|
|
2024
|
-
var TASKDEF_IS_OBJECT = 'task must be an object';
|
|
2025
|
-
var NO_TASKS_RUNNING_WONT_COMPLETE = 'no tasks running, flow will not complete, remaining tasks: %s';
|
|
2026
|
-
var TASK_TYPE_SHOULD_MATCH = 'task.type should match one of ' +
|
|
2027
|
-
Object.keys(TASK_TYPES).join(', ');
|
|
2028
|
-
|
|
2029
|
-
function format_error(errmsg, obj) {
|
|
2030
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
/**
|
|
2034
|
-
guess the missing types from params.
|
|
2035
|
-
Augments in place but also returns taskDef.
|
|
2036
|
-
If not specified then is 'cb'
|
|
2037
|
-
*/
|
|
2038
|
-
function setMissingType(taskDef) {
|
|
2039
|
-
if (taskDef.type) return taskDef; //already set, return
|
|
2040
|
-
taskDef.type = 'cb';
|
|
2041
|
-
return taskDef;
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
function setMissingOutTaskType(taskDef) {
|
|
2045
|
-
if (!taskDef.type) taskDef.type = Object.keys(OUT_TASK_TYPES)[0]; //use first outTask type as default
|
|
2046
|
-
}
|
|
2047
|
-
|
|
2048
|
-
function ensureAfterArrStrings(taskDef) { // convert any fn to str, and make sure is array
|
|
2049
|
-
if (!taskDef.after) return;
|
|
2050
|
-
var afterArr = array(taskDef.after); // ensure is array, null becomes []
|
|
2051
|
-
afterArr = afterArr.map(function (a) { return (typeof(a) === 'function') ? a.name : a; });
|
|
2052
|
-
taskDef.after = afterArr;
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
/**
|
|
2056
|
-
@returns array of errors for taskDef, could be empty
|
|
2057
|
-
*/
|
|
2058
|
-
function validate(taskDef) {
|
|
2059
|
-
if (!taskDef || typeof(taskDef) !== 'object') {
|
|
2060
|
-
return [format_error(TASKDEF_IS_OBJECT, taskDef)];
|
|
2061
|
-
}
|
|
2062
|
-
setMissingType(taskDef);
|
|
2063
|
-
ensureAfterArrStrings(taskDef);
|
|
2064
|
-
var errors = [];
|
|
2065
|
-
errors = errors.concat(validateTaskType(taskDef));
|
|
2066
|
-
errors = errors.concat(validateTask(taskDef));
|
|
2067
|
-
return errors;
|
|
2068
|
-
}
|
|
2069
|
-
|
|
2070
|
-
function validateTaskType(taskDef) {
|
|
2071
|
-
var errors = [];
|
|
2072
|
-
if (!Object.keys(TASK_TYPES).some(
|
|
2073
|
-
function (type) { return (taskDef.type === type); })) {
|
|
2074
|
-
errors.push(format_error(TASK_TYPE_SHOULD_MATCH, taskDef));
|
|
2075
|
-
}
|
|
2076
|
-
return errors;
|
|
2077
|
-
}
|
|
2078
|
-
|
|
2079
|
-
function validateTask(taskDef) {
|
|
2080
|
-
var errors = [];
|
|
2081
|
-
var taskCons = TASK_TYPES[taskDef.type];
|
|
2082
|
-
if (taskCons) {
|
|
2083
|
-
errors = errors.concat(taskCons.validate(taskDef));
|
|
2084
|
-
}
|
|
2085
|
-
return errors;
|
|
2086
|
-
}
|
|
2087
|
-
|
|
2088
|
-
function validateOutTask(taskDef) {
|
|
2089
|
-
var errors = [];
|
|
2090
|
-
setMissingOutTaskType(taskDef);
|
|
2091
|
-
var taskCons = OUT_TASK_TYPES[taskDef.type];
|
|
2092
|
-
errors = errors.concat(taskCons.validate(taskDef));
|
|
2093
|
-
return errors;
|
|
2094
|
-
}
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
function validateLocalFunctions(inParams, taskDefs, locals) {
|
|
2098
|
-
var errors = [];
|
|
2099
|
-
function foo() { } //used to mock args as fns for validation check
|
|
2100
|
-
var mock_args = inParams.map(function (p) { return foo; }); //mock args with fns
|
|
2101
|
-
var vCon = VContext.create(mock_args, inParams, locals);
|
|
2102
|
-
var tasks = taskDefs.map(create);
|
|
2103
|
-
var tasksWFunctions = tasks.filter(function (t) { return (t.type !== 'when'); }); // non-when tasks need f
|
|
2104
|
-
tasksWFunctions.forEach(function (t, idx) {
|
|
2105
|
-
if (!t.functionExists(vCon)) { // error if function doesnt exist AND
|
|
2106
|
-
if (!t.isMethodCall()) errors.push(sprintf(LOCAL_FN_MISSING, t.f, idx)); // not method OR
|
|
2107
|
-
else {
|
|
2108
|
-
var obj = t.getMethodObj(vCon);
|
|
2109
|
-
if (obj && obj !== foo) { // (has parent but not our mock)
|
|
2110
|
-
errors.push(sprintf(LOCAL_FN_MISSING, t.f, idx));
|
|
2111
|
-
}
|
|
2112
|
-
}
|
|
2113
|
-
}
|
|
2114
|
-
});
|
|
2115
|
-
return errors;
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
function fName(fn) {
|
|
2119
|
-
if (typeof(fn) === 'function') {
|
|
2120
|
-
return fn.name;
|
|
2121
|
-
}
|
|
2122
|
-
return (fn) ? fn : '';
|
|
2123
|
-
}
|
|
2124
|
-
|
|
2125
|
-
/**
|
|
2126
|
-
Name tasks that are not already named. Prenamed task uniquness validation
|
|
2127
|
-
will be done in validate.
|
|
2128
|
-
|
|
2129
|
-
This modifies the tasks with the new names.
|
|
2130
|
-
|
|
2131
|
-
@returns map of names to tasks
|
|
2132
|
-
*/
|
|
2133
|
-
function nameTasks(tasks) { //name tasks that are not already named, validation done elsewhere, ret map
|
|
2134
|
-
var namesMap = tasks.reduce(function (map, t) {
|
|
2135
|
-
if (t.name) { map[t.name] = t; }
|
|
2136
|
-
return map;
|
|
2137
|
-
}, {});
|
|
2138
|
-
tasks.forEach(function (t, idx) {
|
|
2139
|
-
if (!t.name) { //not already named
|
|
2140
|
-
var name = fName(t.f);
|
|
2141
|
-
if (!name) name = sprintf(DEFAULT_TASK_NAME, idx);
|
|
2142
|
-
if (!name || namesMap[name]) {
|
|
2143
|
-
name = sprintf('%s_%s', name, idx); //if empty or already used, postfix with _idx
|
|
2144
|
-
}
|
|
2145
|
-
t.name = name;
|
|
2146
|
-
namesMap[name] = t;
|
|
2147
|
-
}
|
|
2148
|
-
});
|
|
2149
|
-
return namesMap;
|
|
2150
|
-
}
|
|
2151
|
-
|
|
2152
|
-
function create(taskDef) {
|
|
2153
|
-
var TaskConstructor = TASK_TYPES[taskDef.type];
|
|
2154
|
-
return new TaskConstructor(taskDef);
|
|
2155
|
-
}
|
|
2156
|
-
|
|
2157
|
-
function createOutTask(taskDef, cbFunc, tasks, vCon, execOptions, env) {
|
|
2158
|
-
setMissingOutTaskType(taskDef);
|
|
2159
|
-
var outTaskOptions = {
|
|
2160
|
-
taskDef: taskDef,
|
|
2161
|
-
cbFunc: cbFunc,
|
|
2162
|
-
tasks: tasks,
|
|
2163
|
-
vCon: vCon,
|
|
2164
|
-
execOptions: execOptions,
|
|
2165
|
-
env: env,
|
|
2166
|
-
TaskConstructor: OUT_TASK_TYPES[taskDef.type]
|
|
2167
|
-
};
|
|
2168
|
-
EventManager.global.emit(EventManager.TYPES.EXEC_OUTTASK_CREATE, outTaskOptions); // hook
|
|
2169
|
-
var TaskConstructor = outTaskOptions.TaskConstructor; // hook could have changed
|
|
2170
|
-
return new TaskConstructor(outTaskOptions);
|
|
2171
|
-
}
|
|
2172
|
-
|
|
2173
|
-
function createErrorHandler(vCon, outTask) {
|
|
2174
|
-
return function handleError(task, err) {
|
|
2175
|
-
task.status = STATUS.ERRORED;
|
|
2176
|
-
task.error = err;
|
|
2177
|
-
outTask.env.currentTask = task;
|
|
2178
|
-
outTask.env.flowEmitter.emit(EventManager.TYPES.EXEC_TASK_ERRORED, task);
|
|
2179
|
-
var errWithMeta = error.augmentError(err, {task: task, vcon: vCon});
|
|
2180
|
-
outTask.exec(errWithMeta); //call the final callback with the first error hit
|
|
2181
|
-
};
|
|
2182
|
-
}
|
|
2183
|
-
|
|
2184
|
-
function findTasksReady(vCon, tasks, tasksByName) {
|
|
2185
|
-
return tasks.filter(function (t) { return t.isReady(vCon, tasksByName); });
|
|
2186
|
-
}
|
|
2187
|
-
|
|
2188
|
-
function execTasks(tasksReady, vCon, handleError, contExec) {
|
|
2189
|
-
tasksReady.forEach(function (t) { t.status = STATUS.READY; }); //set ready first, no double exec
|
|
2190
|
-
tasksReady.forEach(function (t) { t.exec(vCon, handleError, contExec); });
|
|
2191
|
-
}
|
|
2192
|
-
|
|
2193
|
-
/**
|
|
2194
|
-
this will be called if there are no tasks found to run,
|
|
2195
|
-
and it will check if there are still tasks running or ready
|
|
2196
|
-
(which means they will be running shortly), in which
|
|
2197
|
-
case everything is fine. If no tasks are running then
|
|
2198
|
-
call handleError since this will never complete.
|
|
2199
|
-
*/
|
|
2200
|
-
function checkIfTasksRunning(vCon, tasks, handleError, env) {
|
|
2201
|
-
var tasksRunning = tasks.filter(function (t) {
|
|
2202
|
-
return (t.status === STATUS.RUNNING || t.status === STATUS.READY);
|
|
2203
|
-
});
|
|
2204
|
-
if (!tasksRunning.length) {
|
|
2205
|
-
var remainingTasks = tasks.filter(function (t) { return (!t.status); });
|
|
2206
|
-
var remainingTNames = remainingTasks.map(function (t) { return t.name; });
|
|
2207
|
-
var errMsg = sprintf(NO_TASKS_RUNNING_WONT_COMPLETE, remainingTNames.join(', '));
|
|
2208
|
-
var emptyTask = { env: env };
|
|
2209
|
-
handleError(emptyTask, new Error(errMsg));
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
|
|
2213
|
-
function findReadyAndExec(vCon, tasks, tasksByName, handleError, contExec, env) {
|
|
2214
|
-
var tasksReady = findTasksReady(vCon, tasks, tasksByName);
|
|
2215
|
-
if (!tasksReady.length) checkIfTasksRunning(vCon, tasks, handleError, env); // no tasks to run, check if ok
|
|
2216
|
-
execTasks(tasksReady, vCon, handleError, contExec);
|
|
2217
|
-
}
|
|
2218
|
-
|
|
2219
|
-
function serializeTasks(tasks) { // conveniently set after for each task idx > 0
|
|
2220
|
-
nameTasks(tasks);
|
|
2221
|
-
tasks.forEach(function (t, idx, arr) { if (idx !== 0) t.after = [arr[idx - 1].name]; });
|
|
2222
|
-
return tasks;
|
|
2223
|
-
}
|
|
2224
|
-
|
|
2225
|
-
return {
|
|
2226
|
-
serializeTasks: serializeTasks,
|
|
2227
|
-
TASK_TYPES: TASK_TYPES,
|
|
2228
|
-
taskTypeKeys: taskTypeKeys,
|
|
2229
|
-
OUT_TASK_TYPES: OUT_TASK_TYPES,
|
|
2230
|
-
outTaskTypeKeys: outTaskTypeKeys,
|
|
2231
|
-
setMissingType: setMissingType,
|
|
2232
|
-
validate: validate,
|
|
2233
|
-
validateOutTask: validateOutTask,
|
|
2234
|
-
validateLocalFunctions: validateLocalFunctions,
|
|
2235
|
-
nameTasks: nameTasks,
|
|
2236
|
-
create: create,
|
|
2237
|
-
createOutTask: createOutTask,
|
|
2238
|
-
createErrorHandler: createErrorHandler,
|
|
2239
|
-
findReadyAndExec: findReadyAndExec
|
|
2240
|
-
};
|
|
2241
|
-
|
|
2242
|
-
});
|
|
2243
|
-
/*global define:true */
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
define('react/validate',['util', './sprintf', 'ensure-array', './task'], function (util, sprintf, array, taskUtil) {
|
|
2248
|
-
|
|
2249
|
-
/*jshint latedef:false */
|
|
2250
|
-
|
|
2251
|
-
var AST_IS_OBJECT = 'ast must be an object with inParams, tasks, and outTask';
|
|
2252
|
-
var INPARAMS_ARR_STR = 'ast.inParams must be an array of strings';
|
|
2253
|
-
var TASKS_ARR = 'ast.tasks must be an array of tasks';
|
|
2254
|
-
var NAMES_UNIQUE = 'ast.tasks that specify name need to be unique, duplicate:';
|
|
2255
|
-
var LOCALS_NOTNULL = 'ast.locals should not be null';
|
|
2256
|
-
var DUP_OUTPUTS = 'multiple tasks output the same param, must be unique. param';
|
|
2257
|
-
var MISSING_INPUTS = 'missing or mispelled variable referenced in flow definition: %s';
|
|
2258
|
-
|
|
2259
|
-
// match any of our literals true, false, int, float, quoted strings, or is property (has dot), match vcon.js
|
|
2260
|
-
var LITERAL_OR_PROP_RE = /^(true|false|this|null|\-?[0-9\.]+)$|'|"|\./i;
|
|
2261
|
-
|
|
2262
|
-
function format_error(errmsg, obj) {
|
|
2263
|
-
return sprintf('%s - %s', errmsg, util.inspect(obj));
|
|
2264
|
-
}
|
|
2265
|
-
|
|
2266
|
-
/**
|
|
2267
|
-
true if is a literal name
|
|
2268
|
-
*/
|
|
2269
|
-
function isLiteralOrProp(name) { // need to match what is in vcon.js, TODO consolidate?
|
|
2270
|
-
return LITERAL_OR_PROP_RE.test(name);
|
|
2271
|
-
}
|
|
2272
|
-
|
|
2273
|
-
/**
|
|
2274
|
-
validate the AST return Errors
|
|
2275
|
-
@example
|
|
2276
|
-
var validate = require('./validate');
|
|
2277
|
-
var errors = validate(ast);
|
|
2278
|
-
@returns array of errors, could be empty
|
|
2279
|
-
*/
|
|
2280
|
-
function validate(ast) {
|
|
2281
|
-
if (!ast || !ast.inParams || !ast.tasks || !ast.outTask) return [AST_IS_OBJECT];
|
|
2282
|
-
var errors = [];
|
|
2283
|
-
errors = errors.concat(validateInParams(ast.inParams));
|
|
2284
|
-
errors = errors.concat(validateTasks(ast.tasks));
|
|
2285
|
-
errors = errors.concat(validateTaskNamesUnique(ast.tasks));
|
|
2286
|
-
errors = errors.concat(taskUtil.validateOutTask(ast.outTask));
|
|
2287
|
-
errors = errors.concat(validateLocals(ast.locals));
|
|
2288
|
-
if (errors.length === 0) { // if no errors do additional validation
|
|
2289
|
-
if (ast.outTask.type !== 'finalcbFirst') errors = errors.concat(validateOuputsUnique(ast.tasks));
|
|
2290
|
-
errors = errors.concat(taskUtil.validateLocalFunctions(ast.inParams, ast.tasks, ast.locals));
|
|
2291
|
-
errors = errors.concat(validateNoMissingNames(ast));
|
|
2292
|
-
}
|
|
2293
|
-
return errors;
|
|
2294
|
-
}
|
|
2295
|
-
|
|
2296
|
-
/**
|
|
2297
|
-
@returns array of errors, could be empty
|
|
2298
|
-
*/
|
|
2299
|
-
function validateInParams(inParams) {
|
|
2300
|
-
if (!Array.isArray(inParams) ||
|
|
2301
|
-
!inParams.every(function (x) { return (typeof(x) === 'string'); })) {
|
|
2302
|
-
return [INPARAMS_ARR_STR];
|
|
2303
|
-
}
|
|
2304
|
-
return [];
|
|
2305
|
-
}
|
|
2306
|
-
|
|
2307
|
-
/**
|
|
2308
|
-
@returns array of errors, could be empty
|
|
2309
|
-
*/
|
|
2310
|
-
function validateTasks(tasks) {
|
|
2311
|
-
if (!Array.isArray(tasks)) return [TASKS_ARR];
|
|
2312
|
-
var errors = [];
|
|
2313
|
-
tasks.forEach(function (t) {
|
|
2314
|
-
errors = errors.concat(taskUtil.validate(t));
|
|
2315
|
-
});
|
|
2316
|
-
return errors;
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
function validateTaskNamesUnique(tasks) {
|
|
2320
|
-
if (!Array.isArray(tasks)) return [];
|
|
2321
|
-
var errors = [];
|
|
2322
|
-
var namedTasks = tasks.filter(function (t) { return (t.name); });
|
|
2323
|
-
var names = namedTasks.map(function (t) { return t.name; });
|
|
2324
|
-
names.reduce(function (accum, name) {
|
|
2325
|
-
if (accum[name]) errors.push(sprintf('%s %s', NAMES_UNIQUE, name));
|
|
2326
|
-
else accum[name] = true;
|
|
2327
|
-
return accum;
|
|
2328
|
-
}, {});
|
|
2329
|
-
return errors;
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
function validateLocals(locals) {
|
|
2333
|
-
var errors = [];
|
|
2334
|
-
if (locals === null) errors.push(LOCALS_NOTNULL);
|
|
2335
|
-
return errors;
|
|
2336
|
-
}
|
|
2337
|
-
|
|
2338
|
-
function getOutputParams(taskDef) {
|
|
2339
|
-
return array(taskDef.out); //ensure array
|
|
2340
|
-
}
|
|
2341
|
-
|
|
2342
|
-
function validateOuputsUnique(taskDefs) {
|
|
2343
|
-
var errors = [];
|
|
2344
|
-
taskDefs.reduce(function (accum, t) {
|
|
2345
|
-
getOutputParams(t).forEach(function (param) {
|
|
2346
|
-
if (accum[param] !== undefined) errors.push(sprintf('%s: %s', DUP_OUTPUTS, param));
|
|
2347
|
-
else accum[param] = true;
|
|
2348
|
-
});
|
|
2349
|
-
return accum;
|
|
2350
|
-
}, {});
|
|
2351
|
-
return errors;
|
|
2352
|
-
}
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
/**
|
|
2356
|
-
validate there are no missing or mispelled param names in any task inputs
|
|
2357
|
-
or the final task output
|
|
2358
|
-
|
|
2359
|
-
@return array of errors, or empty array if none
|
|
2360
|
-
*/
|
|
2361
|
-
function validateNoMissingNames(ast) {
|
|
2362
|
-
var errors = [];
|
|
2363
|
-
var names = {};
|
|
2364
|
-
if (ast.locals) {
|
|
2365
|
-
names = Object.keys(ast.locals).reduce(function (accum, k) { // start with locals
|
|
2366
|
-
accum[k] = true;
|
|
2367
|
-
return accum;
|
|
2368
|
-
}, names);
|
|
2369
|
-
}
|
|
2370
|
-
ast.inParams.reduce(function (accum, p) { // add input params
|
|
2371
|
-
accum[p] = true;
|
|
2372
|
-
return accum;
|
|
2373
|
-
}, names);
|
|
2374
|
-
ast.tasks.reduce(function (accum, t) { // add task outputs
|
|
2375
|
-
return t.out.reduce(function (innerAccum, p) {
|
|
2376
|
-
innerAccum[p] = true;
|
|
2377
|
-
return innerAccum;
|
|
2378
|
-
}, accum);
|
|
2379
|
-
}, names);
|
|
2380
|
-
|
|
2381
|
-
// now we have all possible provided vars, check task inputs are accounted for
|
|
2382
|
-
ast.tasks.reduce(function (accum, t) { // for all tasks
|
|
2383
|
-
return t.a.reduce(function (innerAccum, p) { // for all in params, except property
|
|
2384
|
-
if (!isLiteralOrProp(p) && !names[p]) innerAccum.push(sprintf(MISSING_INPUTS, p)); // add error if missing
|
|
2385
|
-
return innerAccum;
|
|
2386
|
-
}, accum);
|
|
2387
|
-
}, errors);
|
|
2388
|
-
|
|
2389
|
-
// now check the final task outputs
|
|
2390
|
-
ast.outTask.a.reduce(function (accum, p) { // for final task out params
|
|
2391
|
-
if (!isLiteralOrProp(p) && !names[p]) accum.push(sprintf(MISSING_INPUTS, p)); // add error if missing
|
|
2392
|
-
return accum;
|
|
2393
|
-
}, errors);
|
|
2394
|
-
return errors;
|
|
2395
|
-
}
|
|
2396
|
-
|
|
2397
|
-
return validate;
|
|
2398
|
-
|
|
2399
|
-
});
|
|
2400
|
-
/*global define:true */
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
define('react/input-parser',['./event-manager'], function (EventManager) {
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
var defaultExecOptions = {
|
|
2408
|
-
reactExecOptions: true,
|
|
2409
|
-
outputStyle: 'cb',
|
|
2410
|
-
};
|
|
2411
|
-
|
|
2412
|
-
var OUTPUT_STYLES = {
|
|
2413
|
-
CALLBACK: 'cb',
|
|
2414
|
-
NONE: 'none'
|
|
2415
|
-
};
|
|
2416
|
-
|
|
2417
|
-
function isExecOptions(x) { return (x && x.reactExecOptions); }
|
|
2418
|
-
function execOptionsFilter(x) { return isExecOptions(x); }
|
|
2419
|
-
function nonExecOptionsFilter(x) { return !isExecOptions(x); }
|
|
2420
|
-
function mergeExecOptions(accum, options) {
|
|
2421
|
-
Object.keys(options).forEach(function (k) { accum[k] = options[k]; });
|
|
2422
|
-
return accum;
|
|
2423
|
-
}
|
|
2424
|
-
|
|
2425
|
-
function splitArgs(args, inParams, style) {
|
|
2426
|
-
var result = { };
|
|
2427
|
-
result.args = inParams.map(function (p) { return args.shift(); }); // take args for input params first
|
|
2428
|
-
if (style === OUTPUT_STYLES.CALLBACK && args.length) result.cb = args.shift(); // next take the cb
|
|
2429
|
-
result.extra = args; // these remaining were after the callback
|
|
2430
|
-
return result;
|
|
2431
|
-
}
|
|
2432
|
-
|
|
2433
|
-
function inputParser(inputArgs, ast) {
|
|
2434
|
-
var parsedInput = { };
|
|
2435
|
-
var execOptionsArr = inputArgs.filter(execOptionsFilter);
|
|
2436
|
-
execOptionsArr.unshift(defaultExecOptions);
|
|
2437
|
-
parsedInput.options = execOptionsArr.reduce(mergeExecOptions, {});
|
|
2438
|
-
|
|
2439
|
-
var args = inputArgs.filter(nonExecOptionsFilter);
|
|
2440
|
-
var splitResult = splitArgs(args, ast.inParams, parsedInput.options.outputStyle);
|
|
2441
|
-
parsedInput.args = splitResult.args;
|
|
2442
|
-
parsedInput.cb = splitResult.cb;
|
|
2443
|
-
if (splitResult.outputStyle) parsedInput.options.outputStyle = splitResult.outputStyle;
|
|
2444
|
-
if (splitResult.extra) parsedInput.extraArgs = splitResult.extra;
|
|
2445
|
-
EventManager.global.emit(EventManager.TYPES.EXEC_INPUT_PREPROCESS, parsedInput); // hook
|
|
2446
|
-
return parsedInput;
|
|
2447
|
-
}
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
inputParser.defaultExecOptions = defaultExecOptions;
|
|
2451
|
-
return inputParser;
|
|
2452
|
-
|
|
2453
|
-
});
|
|
2454
|
-
/*global define:true */
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
define('react/id',[], function () {
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
var startingId = 0;
|
|
2462
|
-
|
|
2463
|
-
function createUniqueId() {
|
|
2464
|
-
startingId += 1;
|
|
2465
|
-
if (startingId === Number.MAX_VALUE) startingId = 0; // if hits this start over //TODO need something better?
|
|
2466
|
-
return startingId;
|
|
2467
|
-
}
|
|
2468
|
-
|
|
2469
|
-
return {
|
|
2470
|
-
createUniqueId: createUniqueId
|
|
2471
|
-
};
|
|
2472
|
-
|
|
2473
|
-
});
|
|
2474
|
-
/*global define:true */
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
define('react/core',['./eventemitter', './error', './validate', './task', './status',
|
|
2479
|
-
'./vcon', './event-manager', './input-parser', './id', './sprintf'],
|
|
2480
|
-
function (EventEmitter, error, validate, taskUtil, STATUS,
|
|
2481
|
-
VContext, EventManager, inputParser, idGenerator, sprintf) {
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
var reactOptions = {
|
|
2485
|
-
stackTraceLimitMin: 30
|
|
2486
|
-
};
|
|
2487
|
-
|
|
2488
|
-
var reactEmitter = EventManager.global; // the top emitter
|
|
2489
|
-
|
|
2490
|
-
/**
|
|
2491
|
-
merge global react options with parsed options
|
|
2492
|
-
*/
|
|
2493
|
-
function mergeOptions(parsedOptions) {
|
|
2494
|
-
return Object.keys(reactOptions).reduce(function (accum, k) {
|
|
2495
|
-
if (!accum[k]) accum[k] = reactOptions[k];
|
|
2496
|
-
return accum;
|
|
2497
|
-
}, parsedOptions);
|
|
2498
|
-
}
|
|
2499
|
-
|
|
2500
|
-
/**
|
|
2501
|
-
generate a flow name when one is not provided
|
|
2502
|
-
*/
|
|
2503
|
-
function generateFlowName() {
|
|
2504
|
-
return sprintf('flow_%s', idGenerator.createUniqueId());
|
|
2505
|
-
}
|
|
2506
|
-
|
|
2507
|
-
/**
|
|
2508
|
-
Creates react function which the AST can be manipulated and then
|
|
2509
|
-
is ready to be executed. Can be used directly or a DSL can wrap this
|
|
2510
|
-
to provide the AST.
|
|
2511
|
-
|
|
2512
|
-
@example
|
|
2513
|
-
var react = require('react');
|
|
2514
|
-
var fn = react();
|
|
2515
|
-
var valid2 = fn.setAndValidateAST({
|
|
2516
|
-
name: 'optionalName',
|
|
2517
|
-
inParams: ['a', 'b'],
|
|
2518
|
-
tasks: [
|
|
2519
|
-
{ type: 'cb', f: multiply, a: ['a', 'b'], out: ['c'] }
|
|
2520
|
-
],
|
|
2521
|
-
outTask: { a: ['c'] }
|
|
2522
|
-
});
|
|
2523
|
-
console.log(fn.ast); // view
|
|
2524
|
-
fn(123, 456, cb);
|
|
2525
|
-
*/
|
|
2526
|
-
function reactFactory() {
|
|
2527
|
-
if (arguments.length) throw new Error('react() takes no args, check API');
|
|
2528
|
-
|
|
2529
|
-
error.ensureStackTraceLimitSet(reactOptions.stackTraceLimitMin);
|
|
2530
|
-
var flowEmitter = EventManager.create();
|
|
2531
|
-
flowEmitter.parent = reactEmitter;
|
|
2532
|
-
|
|
2533
|
-
var ast = {
|
|
2534
|
-
name: undefined,
|
|
2535
|
-
inParams: [],
|
|
2536
|
-
tasks: [],
|
|
2537
|
-
outTask: {},
|
|
2538
|
-
locals: {}
|
|
2539
|
-
};
|
|
2540
|
-
|
|
2541
|
-
function setAndValidateAST(newAST) { //set AST then validate, ret error[]
|
|
2542
|
-
Object.keys(newAST).forEach(function (k) { ast[k] = newAST[k]; }); // copy all properties
|
|
2543
|
-
var errors = validate(ast);
|
|
2544
|
-
if (!errors.length) {
|
|
2545
|
-
if (!ast.name) ast.name = generateFlowName();
|
|
2546
|
-
taskUtil.nameTasks(ast.tasks); //run this so names can be checked in ast
|
|
2547
|
-
}
|
|
2548
|
-
if (Object.freeze) { //lets freeze the AST so plugin writers don't accidentally manip the ast
|
|
2549
|
-
Object.keys(newAST).forEach(function (k) {
|
|
2550
|
-
if (typeof(newAST[k]) === 'object') Object.freeze(newAST[k]);
|
|
2551
|
-
});
|
|
2552
|
-
Object.freeze(newAST);
|
|
2553
|
-
}
|
|
2554
|
-
flowEmitter.emit(EventManager.TYPES.AST_DEFINED, ast);
|
|
2555
|
-
return errors;
|
|
2556
|
-
}
|
|
2557
|
-
|
|
2558
|
-
function exec(arg1, arg2, argN, cb) { // called to execute the flow
|
|
2559
|
-
/*jshint validthis: true */
|
|
2560
|
-
var args = Array.prototype.slice.call(arguments);
|
|
2561
|
-
var env = {
|
|
2562
|
-
execId: idGenerator.createUniqueId(),
|
|
2563
|
-
args: args,
|
|
2564
|
-
ast: ast,
|
|
2565
|
-
flowEmitter: flowEmitter
|
|
2566
|
-
};
|
|
2567
|
-
env.name = ast.name || env.execId;
|
|
2568
|
-
flowEmitter.emit(EventManager.TYPES.EXEC_FLOW_START, env); // hook
|
|
2569
|
-
var parsedInput = inputParser(args, ast);
|
|
2570
|
-
var vCon = VContext.create(parsedInput.args, ast.inParams, ast.locals, this); // create var ctx with in args & locals
|
|
2571
|
-
|
|
2572
|
-
env.parsedInput = parsedInput;
|
|
2573
|
-
env.options = mergeOptions(parsedInput.options);
|
|
2574
|
-
env.vCon = vCon;
|
|
2575
|
-
env.taskDefs = ast.tasks.slice(); // create copy
|
|
2576
|
-
env.outTaskDef = Object.create(ast.outTask); // create copy
|
|
2577
|
-
reactEmitter.emit(EventManager.TYPES.EXEC_TASKS_PRECREATE, env); // hook
|
|
2578
|
-
|
|
2579
|
-
var tasks = env.taskDefs.map(taskUtil.create);
|
|
2580
|
-
var tasksByName = taskUtil.nameTasks(tasks); // map names to working tasks
|
|
2581
|
-
var outTask = taskUtil.createOutTask(env.outTaskDef, parsedInput.cb, tasks, vCon, env.options, env);
|
|
2582
|
-
var handleError = taskUtil.createErrorHandler(vCon, outTask);
|
|
2583
|
-
|
|
2584
|
-
function contExec() {
|
|
2585
|
-
if (!outTask.f) { return; } //stop execution, we already hit an error, f was cleared
|
|
2586
|
-
if (outTask.isReady()) return outTask.exec(); // all tasks done, exec cb, return
|
|
2587
|
-
taskUtil.findReadyAndExec(vCon, tasks, tasksByName, handleError, contExec, env); //exec tasks that ready to run
|
|
2588
|
-
}
|
|
2589
|
-
|
|
2590
|
-
tasks.forEach(function (t) {
|
|
2591
|
-
t.id = idGenerator.createUniqueId();
|
|
2592
|
-
t.env = env;
|
|
2593
|
-
if (t.prepare) t.prepare(handleError, vCon, contExec, flowEmitter);
|
|
2594
|
-
}); // create callbacks
|
|
2595
|
-
contExec(); // start things off
|
|
2596
|
-
return outTask.retValue; // could return promise
|
|
2597
|
-
}
|
|
2598
|
-
|
|
2599
|
-
var reactFn = exec; // make the exec() the function returned
|
|
2600
|
-
reactFn.ast = ast; // put AST hanging off the fn so it can be inspected
|
|
2601
|
-
reactFn.setAndValidateAST = setAndValidateAST; // call to set AST and then validate
|
|
2602
|
-
reactFn.events = flowEmitter; // used to listen to execution events for this flow
|
|
2603
|
-
return reactFn;
|
|
2604
|
-
}
|
|
2605
|
-
|
|
2606
|
-
reactFactory.options = reactOptions; // global react options
|
|
2607
|
-
reactFactory.events = reactEmitter; // global react emitter
|
|
2608
|
-
return reactFactory; // module returns reactFactory to create a react fn
|
|
2609
|
-
});
|
|
2610
|
-
/*global define:true */
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
define('react/parse',['./sprintf'], function (sprintf) {
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
function splitTrimFilterArgs(commaSepArgs) { //parse 'one, two' into ['one', 'two']
|
|
2618
|
-
if (!commaSepArgs) return [];
|
|
2619
|
-
return commaSepArgs.split(',') //split on commas
|
|
2620
|
-
.map(function (s) { return s.trim(); }) //trim
|
|
2621
|
-
.filter(function (s) { return (s); }); //filter out empty strings
|
|
2622
|
-
}
|
|
2623
|
-
|
|
2624
|
-
/**
|
|
2625
|
-
@param patternFn regex + fn or splitStr + fn
|
|
2626
|
-
*/
|
|
2627
|
-
function parseReduce(accum, patternFn) {
|
|
2628
|
-
if (typeof(accum) !== 'string') return accum; // already matched
|
|
2629
|
-
var m = (patternFn.regex) ? patternFn.regex.exec(accum) : accum.split(patternFn.splitStr);
|
|
2630
|
-
if (m) return patternFn.fn(m, accum); // pass in matches and origStr, return result obj
|
|
2631
|
-
return accum; // no match, return str, will try next matcher
|
|
2632
|
-
}
|
|
2633
|
-
|
|
2634
|
-
function parseStr(str, parseMatchers, errStr) {
|
|
2635
|
-
var result = parseMatchers.reduce(parseReduce, str);
|
|
2636
|
-
if (typeof(result) !== 'string') { // matched
|
|
2637
|
-
return result;
|
|
2638
|
-
} else { // no match
|
|
2639
|
-
throw new Error(sprintf(errStr, str));
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
|
|
2643
|
-
return {
|
|
2644
|
-
splitTrimFilterArgs: splitTrimFilterArgs,
|
|
2645
|
-
parseStr: parseStr
|
|
2646
|
-
};
|
|
2647
|
-
|
|
2648
|
-
});
|
|
2649
|
-
|
|
2650
|
-
/*global define:true */
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
define('react/dsl',['./sprintf', './core', './parse', './task'],
|
|
2655
|
-
function (sprintf, core, parse, taskUtil) {
|
|
2656
|
-
|
|
2657
|
-
/*jshint regexp: false */
|
|
2658
|
-
|
|
2659
|
-
var MISSING_NAME = 'first flow parameter should be the flow name, but found in/out def: %s';
|
|
2660
|
-
var INOUT_PARAMS_NO_MATCH = 'params in wrong format, wanted "foo, bar, cb -> err, baz" - found: %s';
|
|
2661
|
-
var MISSING_ERR = 'callback specified, but first out param was not "err", use for clarity. Found in/out def: %s';
|
|
2662
|
-
var MISSING_CB = 'found err param, but cb/callback is not specified, is this cb-style async or sync function? Found in/out def: %s';
|
|
2663
|
-
var EXTRA_TASKARG = 'extra unmatched task arg: %s';
|
|
2664
|
-
|
|
2665
|
-
var INOUT_RE = /\->/; // used to detect missing name, in/out as first arg
|
|
2666
|
-
var CB_NAMES_RE = /^cb|callback$/i; //cb, Cb, CB, callback, Callback
|
|
2667
|
-
var ERR_NAMES_RE = /^err$/i; // err, ERR, Err, ...
|
|
2668
|
-
|
|
2669
|
-
function filterOutTrailingCbParam(args) { // if has trailing cb | callback param, filter it out
|
|
2670
|
-
if (args.length && args[args.length - 1].match(CB_NAMES_RE)) args.pop();
|
|
2671
|
-
return args;
|
|
2672
|
-
}
|
|
2673
|
-
|
|
2674
|
-
function filterOutLeadingErrParam(args) { // if leading err param, filter it out
|
|
2675
|
-
if (args.length && args[0].match(ERR_NAMES_RE)) args.shift();
|
|
2676
|
-
return args;
|
|
2677
|
-
}
|
|
2678
|
-
|
|
2679
|
-
var inOutDefParse = {
|
|
2680
|
-
splitStr: '->',
|
|
2681
|
-
fn: function (m, origStr) {
|
|
2682
|
-
var inParams = parse.splitTrimFilterArgs(m[0]);
|
|
2683
|
-
var lastParam = inParams[inParams.length - 1];
|
|
2684
|
-
var type = (lastParam && CB_NAMES_RE.test(lastParam)) ? 'cb' : 'ret';
|
|
2685
|
-
var outParams = parse.splitTrimFilterArgs(m[1]);
|
|
2686
|
-
var firstOutParam = outParams[0];
|
|
2687
|
-
if (type === 'cb' && (!firstOutParam || !ERR_NAMES_RE.test(firstOutParam))) {
|
|
2688
|
-
throw new Error(sprintf(MISSING_ERR, origStr)); // found cb, but no err param
|
|
2689
|
-
} else if (type === 'ret' && firstOutParam && ERR_NAMES_RE.test(firstOutParam)) {
|
|
2690
|
-
throw new Error(sprintf(MISSING_CB, origStr)); // found err but not cb param
|
|
2691
|
-
}
|
|
2692
|
-
return {
|
|
2693
|
-
type: type,
|
|
2694
|
-
inDef: filterOutTrailingCbParam(inParams),
|
|
2695
|
-
outDef: filterOutLeadingErrParam(outParams)
|
|
2696
|
-
};
|
|
2697
|
-
}
|
|
2698
|
-
};
|
|
2699
|
-
|
|
2700
|
-
function parseInOutParams(str) {
|
|
2701
|
-
var objDef = parse.parseStr(str, [inOutDefParse], INOUT_PARAMS_NO_MATCH);
|
|
2702
|
-
objDef.inDef = filterOutTrailingCbParam(objDef.inDef);
|
|
2703
|
-
return objDef;
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
function parseTasks(arr) {
|
|
2707
|
-
var tasks = [];
|
|
2708
|
-
var fn, obj, result;
|
|
2709
|
-
while (arr.length >= 2) {
|
|
2710
|
-
obj = {};
|
|
2711
|
-
fn = arr.shift();
|
|
2712
|
-
result = parseInOutParams(arr.shift());
|
|
2713
|
-
if (typeof(arr[0]) === 'object') obj = arr.shift(); // has options, use as obj
|
|
2714
|
-
obj.f = fn;
|
|
2715
|
-
obj.a = result.inDef;
|
|
2716
|
-
var type = result.type;
|
|
2717
|
-
obj.out = result.outDef;
|
|
2718
|
-
obj.type = type;
|
|
2719
|
-
tasks.push(obj);
|
|
2720
|
-
}
|
|
2721
|
-
if (arr.length) throw new Error(sprintf(EXTRA_TASKARG, arr[0]));
|
|
2722
|
-
return tasks;
|
|
2723
|
-
}
|
|
2724
|
-
|
|
2725
|
-
/**
|
|
2726
|
-
Parse the variable arguments into in/out params, options, tasks
|
|
2727
|
-
*/
|
|
2728
|
-
function parseVargs(vargs) {
|
|
2729
|
-
var inOutParamStr = vargs.shift() || '';
|
|
2730
|
-
// if next arg is object, shift it off as options
|
|
2731
|
-
var options = (vargs.length && typeof(vargs[0]) === 'object') ? vargs.shift() : { };
|
|
2732
|
-
var taskDefArr = vargs; // rest are for the tasks
|
|
2733
|
-
var defObj = {
|
|
2734
|
-
inOutParamStr: inOutParamStr,
|
|
2735
|
-
taskDefArr: taskDefArr,
|
|
2736
|
-
options: options
|
|
2737
|
-
};
|
|
2738
|
-
return defObj;
|
|
2739
|
-
}
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
function dslDefine(name, arg1, arg2, argN) {
|
|
2743
|
-
var reactFn = core();
|
|
2744
|
-
if (name && INOUT_RE.test(name)) throw new Error(sprintf(MISSING_NAME, name));
|
|
2745
|
-
var defObj = parseVargs(Array.prototype.slice.call(arguments, 1)); // name, already used
|
|
2746
|
-
var inOutDef = parseInOutParams(defObj.inOutParamStr);
|
|
2747
|
-
var ast = {
|
|
2748
|
-
name: name,
|
|
2749
|
-
inParams: inOutDef.inDef,
|
|
2750
|
-
tasks: parseTasks(defObj.taskDefArr),
|
|
2751
|
-
outTask: { a: inOutDef.outDef }
|
|
2752
|
-
};
|
|
2753
|
-
if (defObj.options) Object.keys(defObj.options).forEach(function (k) { ast[k] = defObj.options[k]; });
|
|
2754
|
-
var errors = reactFn.setAndValidateAST(ast);
|
|
2755
|
-
if (errors.length) {
|
|
2756
|
-
var errorStr = errors.join('\n');
|
|
2757
|
-
throw new Error(errorStr);
|
|
2758
|
-
}
|
|
2759
|
-
return reactFn;
|
|
2760
|
-
}
|
|
2761
|
-
|
|
2762
|
-
function selectFirst(name, arg1, arg2, argN) {
|
|
2763
|
-
var reactFn = core();
|
|
2764
|
-
var defObj = parseVargs(Array.prototype.slice.call(arguments, 1)); // name, already used
|
|
2765
|
-
var inOutDef = parseInOutParams(defObj.inOutParamStr);
|
|
2766
|
-
var tasks = taskUtil.serializeTasks(parseTasks(defObj.taskDefArr));
|
|
2767
|
-
var ast = {
|
|
2768
|
-
name: name,
|
|
2769
|
-
inParams: inOutDef.inDef,
|
|
2770
|
-
tasks: tasks,
|
|
2771
|
-
outTask: { type: 'finalcbFirst', a: inOutDef.outDef },
|
|
2772
|
-
};
|
|
2773
|
-
if (defObj.options) Object.keys(defObj.options).forEach(function (k) { ast[k] = defObj.options[k]; });
|
|
2774
|
-
var errors = reactFn.setAndValidateAST(ast);
|
|
2775
|
-
if (errors.length) {
|
|
2776
|
-
var errorStr = errors.join('\n');
|
|
2777
|
-
throw new Error(errorStr);
|
|
2778
|
-
}
|
|
2779
|
-
return reactFn;
|
|
2780
|
-
}
|
|
2781
|
-
|
|
2782
|
-
dslDefine.selectFirst = selectFirst;
|
|
2783
|
-
return dslDefine;
|
|
2784
|
-
|
|
2785
|
-
});
|
|
2786
|
-
/*global define:true */
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
define('react/track-tasks',[], function () {
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
/**
|
|
2794
|
-
Track the tasks, start, complete, args, results, elapsed time
|
|
2795
|
-
Emits events that can be monitored
|
|
2796
|
-
|
|
2797
|
-
- track start and complete
|
|
2798
|
-
- record args each task was called with
|
|
2799
|
-
- record results at completion
|
|
2800
|
-
- record start, end, and calc elapsed time
|
|
2801
|
-
- emits flow.begin with flowEnv
|
|
2802
|
-
- emits task.begin with task
|
|
2803
|
-
- emits task.complete with task
|
|
2804
|
-
- emits flow complete with flowEnv
|
|
2805
|
-
- emits flow errored with flowEnv
|
|
2806
|
-
|
|
2807
|
-
@example
|
|
2808
|
-
var react = require('react');
|
|
2809
|
-
react.trackTasks(); // enable task and flow tracking
|
|
2810
|
-
*/
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
var trackingTasks = false;
|
|
2814
|
-
|
|
2815
|
-
function trackTasks(react) {
|
|
2816
|
-
if (trackingTasks) return; // already tracking
|
|
2817
|
-
trackingTasks = true;
|
|
2818
|
-
|
|
2819
|
-
react.events.on(react.events.TYPES.EXEC_FLOW_START, function (env) {
|
|
2820
|
-
env.startTime = Date.now();
|
|
2821
|
-
env.flowEmitter.emit(react.events.TYPES.FLOW_BEGIN, env); //fire public ev
|
|
2822
|
-
});
|
|
2823
|
-
|
|
2824
|
-
react.events.on(react.events.TYPES.EXEC_TASK_START, function (task) {
|
|
2825
|
-
task.startTime = Date.now();
|
|
2826
|
-
task.env.flowEmitter.emit(react.events.TYPES.TASK_BEGIN, task); //fire public ev
|
|
2827
|
-
});
|
|
2828
|
-
|
|
2829
|
-
react.events.on(react.events.TYPES.EXEC_TASK_COMPLETE, function (task) {
|
|
2830
|
-
task.endTime = Date.now();
|
|
2831
|
-
task.elapsedTime = task.endTime - task.startTime;
|
|
2832
|
-
task.env.flowEmitter.emit(react.events.TYPES.TASK_COMPLETE, task); // fire public ev
|
|
2833
|
-
});
|
|
2834
|
-
|
|
2835
|
-
react.events.on(react.events.TYPES.EXEC_TASK_ERRORED, function (task) {
|
|
2836
|
-
task.endTime = Date.now();
|
|
2837
|
-
task.elapsedTime = task.endTime - task.startTime;
|
|
2838
|
-
task.env.flowEmitter.emit(react.events.TYPES.TASK_ERRORED, task); // fire public ev
|
|
2839
|
-
});
|
|
2840
|
-
|
|
2841
|
-
react.events.on(react.events.TYPES.EXEC_FLOW_COMPLETE, function (env) {
|
|
2842
|
-
env.endTime = Date.now();
|
|
2843
|
-
env.elapsedTime = env.endTime - env.startTime;
|
|
2844
|
-
env.flowEmitter.emit(react.events.TYPES.FLOW_COMPLETE, env); //fire public ev
|
|
2845
|
-
});
|
|
2846
|
-
|
|
2847
|
-
react.events.on(react.events.TYPES.EXEC_FLOW_ERRORED, function (env) {
|
|
2848
|
-
env.endTime = Date.now();
|
|
2849
|
-
env.elapsedTime = env.endTime - env.startTime;
|
|
2850
|
-
env.flowEmitter.emit(react.events.TYPES.FLOW_ERRORED, env); //fire public ev
|
|
2851
|
-
});
|
|
2852
|
-
|
|
2853
|
-
}
|
|
2854
|
-
|
|
2855
|
-
return trackTasks;
|
|
2856
|
-
|
|
2857
|
-
});
|
|
2858
|
-
/*global define:true */
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
define('react/log-events',['util'], function (util) { // TODO replace util.inspect with something portable to browser
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
var logEventsMod = { };
|
|
2866
|
-
|
|
2867
|
-
/**
|
|
2868
|
-
Log events to console.error
|
|
2869
|
-
|
|
2870
|
-
@example
|
|
2871
|
-
var react = require('react');
|
|
2872
|
-
react.logEvents(); // log all task and flow events on all react functions
|
|
2873
|
-
react.logEvents('task.*'); // log all task events on all react functions
|
|
2874
|
-
react.logEvents(flowFn); // log all task and flow events on flowFn only
|
|
2875
|
-
react.logEvents(flowFn, 'flow.*'); // log all flow events on flowFn only
|
|
2876
|
-
*/
|
|
2877
|
-
|
|
2878
|
-
var ALL_FLOW_EVENTS = 'flow.*';
|
|
2879
|
-
var ALL_TASK_EVENTS = 'task.*';
|
|
2880
|
-
var FLOW_RE = /^flow\./;
|
|
2881
|
-
|
|
2882
|
-
function flowLog(obj) {
|
|
2883
|
-
/*jshint validthis: true */
|
|
2884
|
-
var time = new Date();
|
|
2885
|
-
time.setTime(obj.startTime);
|
|
2886
|
-
var argsNoCb = obj.args.filter(function (a) { return (typeof(a) !== 'function'); });
|
|
2887
|
-
var eventTimeStr = time.toISOString();
|
|
2888
|
-
if (this.event === 'flow.complete') {
|
|
2889
|
-
var env = obj;
|
|
2890
|
-
console.error('%s: %s \tmsecs: %s \n\targs: %s \n\tresults: %s\n',
|
|
2891
|
-
this.event, env.name, env.elapsedTime, util.inspect(argsNoCb), util.inspect(env.results));
|
|
2892
|
-
} else {
|
|
2893
|
-
var name = obj.name;
|
|
2894
|
-
var args = obj.args;
|
|
2895
|
-
console.error('%s: %s \n\targs: %s\n', this.event, name, util.inspect(argsNoCb));
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
|
|
2899
|
-
function taskLog(obj) {
|
|
2900
|
-
/*jshint validthis: true */
|
|
2901
|
-
var time = new Date();
|
|
2902
|
-
time.setTime(obj.startTime);
|
|
2903
|
-
var argsNoCb = obj.args.filter(function (a) { return (typeof(a) !== 'function'); });
|
|
2904
|
-
var eventTimeStr = time.toISOString();
|
|
2905
|
-
if (this.event === 'task.complete') {
|
|
2906
|
-
var task = obj;
|
|
2907
|
-
console.error('%s: %s:%s \tmsecs: %s \n\targs: %s \n\tresults: %s\n',
|
|
2908
|
-
this.event, task.env.name, task.name, task.elapsedTime, util.inspect(argsNoCb), util.inspect(task.results));
|
|
2909
|
-
} else {
|
|
2910
|
-
var name = obj.name;
|
|
2911
|
-
var args = obj.args;
|
|
2912
|
-
console.error('%s: %s:%s \n\targs: %s\n', this.event, obj.env.name, obj.name, util.inspect(argsNoCb));
|
|
2913
|
-
}
|
|
2914
|
-
|
|
2915
|
-
}
|
|
2916
|
-
|
|
2917
|
-
/**
|
|
2918
|
-
Log flow and task events for a flowFn or all of react.
|
|
2919
|
-
If called multiple times, remove previous listener (if any) before
|
|
2920
|
-
adding.
|
|
2921
|
-
|
|
2922
|
-
@example
|
|
2923
|
-
var react = require('react');
|
|
2924
|
-
react.logEvents(flowFn, eventWildcard); //log events on flowfn matching wildcard
|
|
2925
|
-
|
|
2926
|
-
@param flowFn Flow function or global react object
|
|
2927
|
-
@param eventWildcard wildcarded event type, if not provided use flow.* and task.*
|
|
2928
|
-
*/
|
|
2929
|
-
function logEvents(flowFn, eventWildcard) {
|
|
2930
|
-
if (!flowFn) throw new Error('flowFn is required');
|
|
2931
|
-
if (!flowFn.events._loggingEvents) flowFn.events._loggingEvents = [];
|
|
2932
|
-
if (eventWildcard === false) { // turn off logging
|
|
2933
|
-
flowFn.events._loggingEvents.forEach(function (evt) {
|
|
2934
|
-
flowFn.events.removeAllListeners(evt);
|
|
2935
|
-
});
|
|
2936
|
-
flowFn.events._loggingEvents.length = 0; // clear
|
|
2937
|
-
} else if (eventWildcard && eventWildcard !== '*') {
|
|
2938
|
-
var logFn = (FLOW_RE.test(eventWildcard)) ? flowLog : taskLog;
|
|
2939
|
-
flowFn.events.removeListener(eventWildcard, logFn);
|
|
2940
|
-
flowFn.events.on(eventWildcard, logFn);
|
|
2941
|
-
flowFn.events._loggingEvents.push(eventWildcard);
|
|
2942
|
-
} else { // none provided, use flow.* and task.*
|
|
2943
|
-
//output events as tasks start and complete
|
|
2944
|
-
flowFn.events.removeListener(ALL_FLOW_EVENTS, flowLog);
|
|
2945
|
-
flowFn.events.on(ALL_FLOW_EVENTS, flowLog);
|
|
2946
|
-
flowFn.events._loggingEvents.push(ALL_FLOW_EVENTS);
|
|
2947
|
-
flowFn.events.removeListener(ALL_TASK_EVENTS, taskLog);
|
|
2948
|
-
flowFn.events.on(ALL_TASK_EVENTS, taskLog);
|
|
2949
|
-
flowFn.events._loggingEvents.push(ALL_TASK_EVENTS);
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
|
|
2953
|
-
logEventsMod.logEvents = logEvents;
|
|
2954
|
-
return logEventsMod;
|
|
2955
|
-
|
|
2956
|
-
});
|
|
2957
|
-
/*global define:true */
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
define('react/promise-resolve',[], function () {
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
/**
|
|
2965
|
-
Auto resolve promises passed in as arguments to the flow
|
|
2966
|
-
|
|
2967
|
-
- Detects promises by checking for .then()
|
|
2968
|
-
- Create promise name for param (param__promise)
|
|
2969
|
-
- moves existing vCon promise into the param__promise
|
|
2970
|
-
- creates WhenTask which resolves param__promise into param
|
|
2971
|
-
*/
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
var PROMISE_SUFFIX = '__promise'; // added to param names that are promises
|
|
2975
|
-
|
|
2976
|
-
var resolvingPromises = false;
|
|
2977
|
-
|
|
2978
|
-
function resolvePromises(react) {
|
|
2979
|
-
if (resolvingPromises) return; // already resolving
|
|
2980
|
-
resolvingPromises = true;
|
|
2981
|
-
|
|
2982
|
-
react.events.on(react.events.TYPES.EXEC_TASKS_PRECREATE, function (env) {
|
|
2983
|
-
var vConValues = env.vCon.values;
|
|
2984
|
-
var promiseParams = env.ast.inParams.filter(function (p) {
|
|
2985
|
-
var value = vConValues[p];
|
|
2986
|
-
return (value && typeof(value.then) === 'function');
|
|
2987
|
-
});
|
|
2988
|
-
promiseParams.forEach(function (p) {
|
|
2989
|
-
var promiseName = p + PROMISE_SUFFIX;
|
|
2990
|
-
vConValues[promiseName] = vConValues[p];
|
|
2991
|
-
vConValues[p] = undefined;
|
|
2992
|
-
env.taskDefs.push({
|
|
2993
|
-
type: 'when',
|
|
2994
|
-
a: [promiseName],
|
|
2995
|
-
out: [p]
|
|
2996
|
-
});
|
|
2997
|
-
});
|
|
2998
|
-
});
|
|
2999
|
-
|
|
3000
|
-
}
|
|
3001
|
-
|
|
3002
|
-
return resolvePromises;
|
|
3003
|
-
|
|
3004
|
-
});
|
|
3005
|
-
/*global define:true */
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
define('react/event-collector',[], function () {
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
/**
|
|
3013
|
-
create an instance of the event collector
|
|
3014
|
-
*/
|
|
3015
|
-
function instantiate(react) {
|
|
3016
|
-
react.trackTasks(); // enable task tracking
|
|
3017
|
-
|
|
3018
|
-
var AST_EVENTS_RE = /^ast\./;
|
|
3019
|
-
var TASK_EVENTS_RE = /^task\./;
|
|
3020
|
-
var FLOW_EVENTS_RE = /^flow\./;
|
|
3021
|
-
|
|
3022
|
-
/**
|
|
3023
|
-
Accumulator to make it easy to capture events
|
|
3024
|
-
|
|
3025
|
-
@example
|
|
3026
|
-
var react = require('react');
|
|
3027
|
-
var collector = react.createEventCollector();
|
|
3028
|
-
collector.capture(); // capture all flow and task events for all react flows
|
|
3029
|
-
collector.capture('flow.*'); // capture all flow events for all react flows
|
|
3030
|
-
collector.capture(flowFn, 'task.*'); // capture task events on a flow
|
|
3031
|
-
collector.capture(flowFn, 'flow.*'); // add capture flow events on a flow
|
|
3032
|
-
var events = collector.list(); // retrieve the list of events
|
|
3033
|
-
collector.clear(); // clear the list of events;
|
|
3034
|
-
*/
|
|
3035
|
-
function EventCollector() {
|
|
3036
|
-
this.events = [];
|
|
3037
|
-
}
|
|
3038
|
-
|
|
3039
|
-
/**
|
|
3040
|
-
register listener to capture events for a specific flow
|
|
3041
|
-
@param flowFn the react flow function or can pass global react
|
|
3042
|
-
@param eventId event id or wildcarded id
|
|
3043
|
-
*/
|
|
3044
|
-
EventCollector.prototype.capture = function (flowFn, eventId) {
|
|
3045
|
-
/*jshint validthis: true */
|
|
3046
|
-
if (!eventId && typeof(flowFn) === 'string') { // only eventId provided
|
|
3047
|
-
eventId = flowFn;
|
|
3048
|
-
flowFn = react; // global react
|
|
3049
|
-
} else if (!flowFn) flowFn = react; // global react
|
|
3050
|
-
if (!eventId) eventId = '*'; // default to all
|
|
3051
|
-
var emitter = flowFn.events;
|
|
3052
|
-
var self = this;
|
|
3053
|
-
function accumEvents(obj) {
|
|
3054
|
-
var eventObject = {
|
|
3055
|
-
event: this.event,
|
|
3056
|
-
time: Date.now()
|
|
3057
|
-
};
|
|
3058
|
-
if (FLOW_EVENTS_RE.test(this.event)) {
|
|
3059
|
-
eventObject.env = obj;
|
|
3060
|
-
} else if (TASK_EVENTS_RE.test(this.event)) {
|
|
3061
|
-
eventObject.task = obj;
|
|
3062
|
-
} else if (AST_EVENTS_RE.test(this.event)) {
|
|
3063
|
-
eventObject.ast = obj;
|
|
3064
|
-
}
|
|
3065
|
-
self.events.push(eventObject);
|
|
3066
|
-
}
|
|
3067
|
-
emitter.on(eventId, accumEvents);
|
|
3068
|
-
};
|
|
3069
|
-
|
|
3070
|
-
EventCollector.prototype.list = function () {
|
|
3071
|
-
return this.events;
|
|
3072
|
-
};
|
|
3073
|
-
|
|
3074
|
-
EventCollector.prototype.clear = function () {
|
|
3075
|
-
this.events = []; // clear
|
|
3076
|
-
};
|
|
3077
|
-
|
|
3078
|
-
return new EventCollector();
|
|
3079
|
-
}
|
|
3080
|
-
|
|
3081
|
-
return instantiate; // return the factory for creating EventCollector
|
|
3082
|
-
|
|
3083
|
-
});
|
|
3084
|
-
/*global define:true */
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
define('react/react',['./core', './dsl', './track-tasks', './log-events', './promise-resolve', './event-collector'],
|
|
3089
|
-
function (core, dsl, trackTasksFn, logEventsMod, resolvePromisesFn, eventCollectorFactory) {
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
var react = dsl; // core + default dsl
|
|
3093
|
-
|
|
3094
|
-
/**
|
|
3095
|
-
Enable detection of promises and resolution
|
|
3096
|
-
*/
|
|
3097
|
-
function resolvePromises() {
|
|
3098
|
-
resolvePromisesFn(react);
|
|
3099
|
-
}
|
|
3100
|
-
|
|
3101
|
-
/**
|
|
3102
|
-
Enable tracking of tasks and flow execution, emitting events and
|
|
3103
|
-
tracking start, end, elapsed time
|
|
3104
|
-
*/
|
|
3105
|
-
function trackTasks() {
|
|
3106
|
-
trackTasksFn(react);
|
|
3107
|
-
}
|
|
3108
|
-
|
|
3109
|
-
/**
|
|
3110
|
-
If called, load the built-in plugin for log events and invoke
|
|
3111
|
-
|
|
3112
|
-
@param flowFn [function] if not provided uses global react
|
|
3113
|
-
@param eventWildcard [string] pattern to log events for
|
|
3114
|
-
*/
|
|
3115
|
-
function logEvents(flowFn, eventWildcard) {
|
|
3116
|
-
if (typeof(flowFn) !== 'function') { // only wildcard provided
|
|
3117
|
-
eventWildcard = flowFn;
|
|
3118
|
-
flowFn = undefined;
|
|
3119
|
-
}
|
|
3120
|
-
if (!flowFn) flowFn = react; // use global
|
|
3121
|
-
trackTasks();
|
|
3122
|
-
return logEventsMod.logEvents(flowFn, eventWildcard);
|
|
3123
|
-
}
|
|
3124
|
-
|
|
3125
|
-
/**
|
|
3126
|
-
Instantiate an event collector
|
|
3127
|
-
*/
|
|
3128
|
-
function createEventCollector() {
|
|
3129
|
-
return eventCollectorFactory(react);
|
|
3130
|
-
}
|
|
3131
|
-
|
|
3132
|
-
react.options = core.options; // global react options
|
|
3133
|
-
react.events = core.events; // global react event emitter
|
|
3134
|
-
react.logEvents = logEvents; // enable event logging
|
|
3135
|
-
react.resolvePromises = resolvePromises; // enable promise resolution
|
|
3136
|
-
react.trackTasks = trackTasks; // enable tracking of tasks
|
|
3137
|
-
react.createEventCollector = createEventCollector; // create instance of EventCollector
|
|
3138
|
-
return react;
|
|
3139
|
-
|
|
3140
|
-
});
|
|
3141
|
-
define('react', ['react/react'], function (main) { return main; });
|