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