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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule ExecutionEnvironment
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/*jslint evil: true */
|
|
20
|
+
|
|
21
|
+
"use strict";
|
|
22
|
+
|
|
23
|
+
var canUseDOM = typeof window !== 'undefined';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Simple, lightweight module assisting with the detection and context of
|
|
27
|
+
* Worker. Helps avoid circular dependencies and allows code to reason about
|
|
28
|
+
* whether or not they are in a Worker, even if they never include the main
|
|
29
|
+
* `ReactWorker` dependency.
|
|
30
|
+
*/
|
|
31
|
+
var ExecutionEnvironment = {
|
|
32
|
+
|
|
33
|
+
canUseDOM: canUseDOM,
|
|
34
|
+
|
|
35
|
+
canUseWorkers: typeof Worker !== 'undefined',
|
|
36
|
+
|
|
37
|
+
isInWorker: !canUseDOM // For now, this is true - might change in the future.
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = ExecutionEnvironment;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule LinkedStateMixin
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var ReactLink = require("./ReactLink");
|
|
23
|
+
var ReactStateSetters = require("./ReactStateSetters");
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A simple mixin around ReactLink.forState().
|
|
27
|
+
*/
|
|
28
|
+
var LinkedStateMixin = {
|
|
29
|
+
/**
|
|
30
|
+
* Create a ReactLink that's linked to part of this component's state. The
|
|
31
|
+
* ReactLink will have the current value of this.state[key] and will call
|
|
32
|
+
* setState() when a change is requested.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} key state key to update. Note: you may want to use keyOf()
|
|
35
|
+
* if you're using Google Closure Compiler advanced mode.
|
|
36
|
+
* @return {ReactLink} ReactLink instance linking to the state.
|
|
37
|
+
*/
|
|
38
|
+
linkState: function(key) {
|
|
39
|
+
return new ReactLink(
|
|
40
|
+
this.state[key],
|
|
41
|
+
ReactStateSetters.createStateKeySetter(this, key)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports = LinkedStateMixin;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule LinkedValueMixin
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var invariant = require("./invariant");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Provide a linked `value` attribute for controlled forms. You should not use
|
|
26
|
+
* this outside of the ReactDOM controlled form components.
|
|
27
|
+
*/
|
|
28
|
+
var LinkedValueMixin = {
|
|
29
|
+
_assertLink: function() {
|
|
30
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
31
|
+
this.props.value == null && this.props.onChange == null,
|
|
32
|
+
'Cannot provide a valueLink and a value or onChange event. If you ' +
|
|
33
|
+
'want to use value or onChange, you probably don\'t want to use ' +
|
|
34
|
+
'valueLink'
|
|
35
|
+
) : invariant(this.props.value == null && this.props.onChange == null));
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @return {*} current value of the input either from value prop or link.
|
|
40
|
+
*/
|
|
41
|
+
getValue: function() {
|
|
42
|
+
if (this.props.valueLink) {
|
|
43
|
+
this._assertLink();
|
|
44
|
+
return this.props.valueLink.value;
|
|
45
|
+
}
|
|
46
|
+
return this.props.value;
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @return {function} change callback either from onChange prop or link.
|
|
51
|
+
*/
|
|
52
|
+
getOnChange: function() {
|
|
53
|
+
if (this.props.valueLink) {
|
|
54
|
+
this._assertLink();
|
|
55
|
+
return this._handleLinkedValueChange;
|
|
56
|
+
}
|
|
57
|
+
return this.props.onChange;
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {SyntheticEvent} e change event to handle
|
|
62
|
+
*/
|
|
63
|
+
_handleLinkedValueChange: function(e) {
|
|
64
|
+
this.props.valueLink.requestChange(e.target.value);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
module.exports = LinkedValueMixin;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule MobileSafariClickEventPlugin
|
|
17
|
+
* @typechecks static-only
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
var EventConstants = require("./EventConstants");
|
|
23
|
+
|
|
24
|
+
var emptyFunction = require("./emptyFunction");
|
|
25
|
+
|
|
26
|
+
var topLevelTypes = EventConstants.topLevelTypes;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Mobile Safari does not fire properly bubble click events on non-interactive
|
|
30
|
+
* elements, which means delegated click listeners do not fire. The workaround
|
|
31
|
+
* for this bug involves attaching an empty click listener on the target node.
|
|
32
|
+
*
|
|
33
|
+
* This particular plugin works around the bug by attaching an empty click
|
|
34
|
+
* listener on `touchstart` (which does fire on every element).
|
|
35
|
+
*/
|
|
36
|
+
var MobileSafariClickEventPlugin = {
|
|
37
|
+
|
|
38
|
+
eventTypes: null,
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {string} topLevelType Record from `EventConstants`.
|
|
42
|
+
* @param {DOMEventTarget} topLevelTarget The listening component root node.
|
|
43
|
+
* @param {string} topLevelTargetID ID of `topLevelTarget`.
|
|
44
|
+
* @param {object} nativeEvent Native browser event.
|
|
45
|
+
* @return {*} An accumulation of synthetic events.
|
|
46
|
+
* @see {EventPluginHub.extractEvents}
|
|
47
|
+
*/
|
|
48
|
+
extractEvents: function(
|
|
49
|
+
topLevelType,
|
|
50
|
+
topLevelTarget,
|
|
51
|
+
topLevelTargetID,
|
|
52
|
+
nativeEvent) {
|
|
53
|
+
if (topLevelType === topLevelTypes.topTouchStart) {
|
|
54
|
+
var target = nativeEvent.target;
|
|
55
|
+
if (target && !target.onclick) {
|
|
56
|
+
target.onclick = emptyFunction;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = MobileSafariClickEventPlugin;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule PooledClass
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Static poolers. Several custom versions for each potential number of
|
|
23
|
+
* arguments. A completely generic pooler is easy to implement, but would
|
|
24
|
+
* require accessing the `arguments` object. In each of these, `this` refers to
|
|
25
|
+
* the Class itself, not an instance. If any others are needed, simply add them
|
|
26
|
+
* here, or in their own files.
|
|
27
|
+
*/
|
|
28
|
+
var oneArgumentPooler = function(copyFieldsFrom) {
|
|
29
|
+
var Klass = this;
|
|
30
|
+
if (Klass.instancePool.length) {
|
|
31
|
+
var instance = Klass.instancePool.pop();
|
|
32
|
+
Klass.call(instance, copyFieldsFrom);
|
|
33
|
+
return instance;
|
|
34
|
+
} else {
|
|
35
|
+
return new Klass(copyFieldsFrom);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var twoArgumentPooler = function(a1, a2) {
|
|
40
|
+
var Klass = this;
|
|
41
|
+
if (Klass.instancePool.length) {
|
|
42
|
+
var instance = Klass.instancePool.pop();
|
|
43
|
+
Klass.call(instance, a1, a2);
|
|
44
|
+
return instance;
|
|
45
|
+
} else {
|
|
46
|
+
return new Klass(a1, a2);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var threeArgumentPooler = function(a1, a2, a3) {
|
|
51
|
+
var Klass = this;
|
|
52
|
+
if (Klass.instancePool.length) {
|
|
53
|
+
var instance = Klass.instancePool.pop();
|
|
54
|
+
Klass.call(instance, a1, a2, a3);
|
|
55
|
+
return instance;
|
|
56
|
+
} else {
|
|
57
|
+
return new Klass(a1, a2, a3);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
var fiveArgumentPooler = function(a1, a2, a3, a4, a5) {
|
|
62
|
+
var Klass = this;
|
|
63
|
+
if (Klass.instancePool.length) {
|
|
64
|
+
var instance = Klass.instancePool.pop();
|
|
65
|
+
Klass.call(instance, a1, a2, a3, a4, a5);
|
|
66
|
+
return instance;
|
|
67
|
+
} else {
|
|
68
|
+
return new Klass(a1, a2, a3, a4, a5);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
var standardReleaser = function(instance) {
|
|
73
|
+
var Klass = this;
|
|
74
|
+
if (instance.destructor) {
|
|
75
|
+
instance.destructor();
|
|
76
|
+
}
|
|
77
|
+
if (Klass.instancePool.length < Klass.poolSize) {
|
|
78
|
+
Klass.instancePool.push(instance);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var DEFAULT_POOL_SIZE = 10;
|
|
83
|
+
var DEFAULT_POOLER = oneArgumentPooler;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Augments `CopyConstructor` to be a poolable class, augmenting only the class
|
|
87
|
+
* itself (statically) not adding any prototypical fields. Any CopyConstructor
|
|
88
|
+
* you give this may have a `poolSize` property, and will look for a
|
|
89
|
+
* prototypical `destructor` on instances (optional).
|
|
90
|
+
*
|
|
91
|
+
* @param {Function} CopyConstructor Constructor that can be used to reset.
|
|
92
|
+
* @param {Function} pooler Customizable pooler.
|
|
93
|
+
*/
|
|
94
|
+
var addPoolingTo = function(CopyConstructor, pooler) {
|
|
95
|
+
var NewKlass = CopyConstructor;
|
|
96
|
+
NewKlass.instancePool = [];
|
|
97
|
+
NewKlass.getPooled = pooler || DEFAULT_POOLER;
|
|
98
|
+
if (!NewKlass.poolSize) {
|
|
99
|
+
NewKlass.poolSize = DEFAULT_POOL_SIZE;
|
|
100
|
+
}
|
|
101
|
+
NewKlass.release = standardReleaser;
|
|
102
|
+
return NewKlass;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var PooledClass = {
|
|
106
|
+
addPoolingTo: addPoolingTo,
|
|
107
|
+
oneArgumentPooler: oneArgumentPooler,
|
|
108
|
+
twoArgumentPooler: twoArgumentPooler,
|
|
109
|
+
threeArgumentPooler: threeArgumentPooler,
|
|
110
|
+
fiveArgumentPooler: fiveArgumentPooler
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
module.exports = PooledClass;
|
package/lib/React.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule React
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var ReactComponent = require("./ReactComponent");
|
|
22
|
+
var ReactCompositeComponent = require("./ReactCompositeComponent");
|
|
23
|
+
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
24
|
+
var ReactDOM = require("./ReactDOM");
|
|
25
|
+
var ReactDOMComponent = require("./ReactDOMComponent");
|
|
26
|
+
var ReactDefaultInjection = require("./ReactDefaultInjection");
|
|
27
|
+
var ReactInstanceHandles = require("./ReactInstanceHandles");
|
|
28
|
+
var ReactMount = require("./ReactMount");
|
|
29
|
+
var ReactMultiChild = require("./ReactMultiChild");
|
|
30
|
+
var ReactPerf = require("./ReactPerf");
|
|
31
|
+
var ReactPropTypes = require("./ReactPropTypes");
|
|
32
|
+
var ReactServerRendering = require("./ReactServerRendering");
|
|
33
|
+
var ReactTextComponent = require("./ReactTextComponent");
|
|
34
|
+
|
|
35
|
+
ReactDefaultInjection.inject();
|
|
36
|
+
|
|
37
|
+
var React = {
|
|
38
|
+
DOM: ReactDOM,
|
|
39
|
+
PropTypes: ReactPropTypes,
|
|
40
|
+
initializeTouchEvents: function(shouldUseTouch) {
|
|
41
|
+
ReactMount.useTouchEvents = shouldUseTouch;
|
|
42
|
+
},
|
|
43
|
+
createClass: ReactCompositeComponent.createClass,
|
|
44
|
+
constructAndRenderComponent: ReactMount.constructAndRenderComponent,
|
|
45
|
+
constructAndRenderComponentByID: ReactMount.constructAndRenderComponentByID,
|
|
46
|
+
renderComponent: ReactPerf.measure(
|
|
47
|
+
'React',
|
|
48
|
+
'renderComponent',
|
|
49
|
+
ReactMount.renderComponent
|
|
50
|
+
),
|
|
51
|
+
renderComponentToString: ReactServerRendering.renderComponentToString,
|
|
52
|
+
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
|
|
53
|
+
unmountAndReleaseReactRootNode: ReactMount.unmountAndReleaseReactRootNode,
|
|
54
|
+
isValidClass: ReactCompositeComponent.isValidClass,
|
|
55
|
+
isValidComponent: ReactComponent.isValidComponent,
|
|
56
|
+
__internals: {
|
|
57
|
+
Component: ReactComponent,
|
|
58
|
+
CurrentOwner: ReactCurrentOwner,
|
|
59
|
+
DOMComponent: ReactDOMComponent,
|
|
60
|
+
InstanceHandles: ReactInstanceHandles,
|
|
61
|
+
Mount: ReactMount,
|
|
62
|
+
MultiChild: ReactMultiChild,
|
|
63
|
+
TextComponent: ReactTextComponent
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Version exists only in the open-source version of React, not in Facebook's
|
|
68
|
+
// internal version.
|
|
69
|
+
React.version = '0.8.0';
|
|
70
|
+
|
|
71
|
+
module.exports = React;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013 Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
* @providesModule ReactChildren
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var PooledClass = require("./PooledClass");
|
|
22
|
+
|
|
23
|
+
var invariant = require("./invariant");
|
|
24
|
+
var traverseAllChildren = require("./traverseAllChildren");
|
|
25
|
+
|
|
26
|
+
var twoArgumentPooler = PooledClass.twoArgumentPooler;
|
|
27
|
+
var threeArgumentPooler = PooledClass.threeArgumentPooler;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* PooledClass representing the bookkeeping associated with performing a child
|
|
31
|
+
* traversal. Allows avoiding binding callbacks.
|
|
32
|
+
*
|
|
33
|
+
* @constructor ForEachBookKeeping
|
|
34
|
+
* @param {!function} forEachFunction Function to perform traversal with.
|
|
35
|
+
* @param {?*} forEachContext Context to perform context with.
|
|
36
|
+
*/
|
|
37
|
+
function ForEachBookKeeping(forEachFunction, forEachContext) {
|
|
38
|
+
this.forEachFunction = forEachFunction;
|
|
39
|
+
this.forEachContext = forEachContext;
|
|
40
|
+
}
|
|
41
|
+
PooledClass.addPoolingTo(ForEachBookKeeping, twoArgumentPooler);
|
|
42
|
+
|
|
43
|
+
function forEachSingleChild(traverseContext, child, name, i) {
|
|
44
|
+
var forEachBookKeeping = traverseContext;
|
|
45
|
+
forEachBookKeeping.forEachFunction.call(
|
|
46
|
+
forEachBookKeeping.forEachContext, child, i);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Iterates through children that are typically specified as `props.children`.
|
|
51
|
+
*
|
|
52
|
+
* The provided forEachFunc(child, index) will be called for each
|
|
53
|
+
* leaf child.
|
|
54
|
+
*
|
|
55
|
+
* @param {array} children
|
|
56
|
+
* @param {function(*, int)} forEachFunc.
|
|
57
|
+
* @param {*} forEachContext Context for forEachContext.
|
|
58
|
+
*/
|
|
59
|
+
function forEachChildren(children, forEachFunc, forEachContext) {
|
|
60
|
+
if (children == null) {
|
|
61
|
+
return children;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var traverseContext =
|
|
65
|
+
ForEachBookKeeping.getPooled(forEachFunc, forEachContext);
|
|
66
|
+
traverseAllChildren(children, forEachSingleChild, traverseContext);
|
|
67
|
+
ForEachBookKeeping.release(traverseContext);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* PooledClass representing the bookkeeping associated with performing a child
|
|
72
|
+
* mapping. Allows avoiding binding callbacks.
|
|
73
|
+
*
|
|
74
|
+
* @constructor MapBookKeeping
|
|
75
|
+
* @param {!*} mapResult Object containing the ordered map of results.
|
|
76
|
+
* @param {!function} mapFunction Function to perform mapping with.
|
|
77
|
+
* @param {?*} mapContext Context to perform mapping with.
|
|
78
|
+
*/
|
|
79
|
+
function MapBookKeeping(mapResult, mapFunction, mapContext) {
|
|
80
|
+
this.mapResult = mapResult;
|
|
81
|
+
this.mapFunction = mapFunction;
|
|
82
|
+
this.mapContext = mapContext;
|
|
83
|
+
}
|
|
84
|
+
PooledClass.addPoolingTo(MapBookKeeping, threeArgumentPooler);
|
|
85
|
+
|
|
86
|
+
function mapSingleChildIntoContext(traverseContext, child, name, i) {
|
|
87
|
+
var mapBookKeeping = traverseContext;
|
|
88
|
+
var mapResult = mapBookKeeping.mapResult;
|
|
89
|
+
var mappedChild =
|
|
90
|
+
mapBookKeeping.mapFunction.call(mapBookKeeping.mapContext, child, i);
|
|
91
|
+
// We found a component instance
|
|
92
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
93
|
+
!mapResult.hasOwnProperty(name),
|
|
94
|
+
'ReactChildren.map(...): Encountered two children with the same key, ' +
|
|
95
|
+
'`%s`. Children keys must be unique.',
|
|
96
|
+
name
|
|
97
|
+
) : invariant(!mapResult.hasOwnProperty(name)));
|
|
98
|
+
mapResult[name] = mappedChild;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Maps children that are typically specified as `props.children`.
|
|
103
|
+
*
|
|
104
|
+
* The provided mapFunction(child, key, index) will be called for each
|
|
105
|
+
* leaf child.
|
|
106
|
+
*
|
|
107
|
+
* TODO: This may likely break any calls to `ReactChildren.map` that were
|
|
108
|
+
* previously relying on the fact that we guarded against null children.
|
|
109
|
+
*
|
|
110
|
+
* @param {array} children
|
|
111
|
+
* @param {function(*, int)} mapFunction.
|
|
112
|
+
* @param {*} mapContext Context for mapFunction.
|
|
113
|
+
* @return {array} mirrored array with mapped children.
|
|
114
|
+
*/
|
|
115
|
+
function mapChildren(children, func, context) {
|
|
116
|
+
if (children == null) {
|
|
117
|
+
return children;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
var mapResult = {};
|
|
121
|
+
var traverseContext = MapBookKeeping.getPooled(mapResult, func, context);
|
|
122
|
+
traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
|
|
123
|
+
MapBookKeeping.release(traverseContext);
|
|
124
|
+
return mapResult;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
var ReactChildren = {
|
|
128
|
+
forEach: forEachChildren,
|
|
129
|
+
map: mapChildren
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
module.exports = ReactChildren;
|