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,515 @@
|
|
|
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 ReactComponent
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
"use strict";
|
|
20
|
+
|
|
21
|
+
var ReactComponentEnvironment = require("./ReactComponentEnvironment");
|
|
22
|
+
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
23
|
+
var ReactOwner = require("./ReactOwner");
|
|
24
|
+
var ReactUpdates = require("./ReactUpdates");
|
|
25
|
+
|
|
26
|
+
var invariant = require("./invariant");
|
|
27
|
+
var keyMirror = require("./keyMirror");
|
|
28
|
+
var merge = require("./merge");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Every React component is in one of these life cycles.
|
|
32
|
+
*/
|
|
33
|
+
var ComponentLifeCycle = keyMirror({
|
|
34
|
+
/**
|
|
35
|
+
* Mounted components have a DOM node representation and are capable of
|
|
36
|
+
* receiving new props.
|
|
37
|
+
*/
|
|
38
|
+
MOUNTED: null,
|
|
39
|
+
/**
|
|
40
|
+
* Unmounted components are inactive and cannot receive new props.
|
|
41
|
+
*/
|
|
42
|
+
UNMOUNTED: null
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Warn if there's no key explicitly set on dynamic arrays of children.
|
|
47
|
+
* This allows us to keep track of children between updates.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
var ownerHasWarned = {};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Warn if the component doesn't have an explicit key assigned to it.
|
|
54
|
+
* This component is in an array. The array could grow and shrink or be
|
|
55
|
+
* reordered. All children, that hasn't already been validated, are required to
|
|
56
|
+
* have a "key" property assigned to it.
|
|
57
|
+
*
|
|
58
|
+
* @internal
|
|
59
|
+
* @param {ReactComponent} component Component that requires a key.
|
|
60
|
+
*/
|
|
61
|
+
function validateExplicitKey(component) {
|
|
62
|
+
if (component.__keyValidated__ || component.props.key != null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
component.__keyValidated__ = true;
|
|
66
|
+
|
|
67
|
+
// We can't provide friendly warnings for top level components.
|
|
68
|
+
if (!ReactCurrentOwner.current) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Name of the component whose render method tried to pass children.
|
|
73
|
+
var currentName = ReactCurrentOwner.current.constructor.displayName;
|
|
74
|
+
if (ownerHasWarned.hasOwnProperty(currentName)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
ownerHasWarned[currentName] = true;
|
|
78
|
+
|
|
79
|
+
var message = 'Each child in an array should have a unique "key" prop. ' +
|
|
80
|
+
'Check the render method of ' + currentName + '.';
|
|
81
|
+
if (!component.isOwnedBy(ReactCurrentOwner.current)) {
|
|
82
|
+
// Name of the component that originally created this child.
|
|
83
|
+
var childOwnerName =
|
|
84
|
+
component.props.__owner__ &&
|
|
85
|
+
component.props.__owner__.constructor.displayName;
|
|
86
|
+
|
|
87
|
+
// Usually the current owner is the offender, but if it accepts
|
|
88
|
+
// children as a property, it may be the creator of the child that's
|
|
89
|
+
// responsible for assigning it a key.
|
|
90
|
+
message += ' It was passed a child from ' + childOwnerName + '.';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
console.warn(message);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Ensure that every component either is passed in a static location or, if
|
|
98
|
+
* if it's passed in an array, has an explicit key property defined.
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
* @param {*} component Statically passed child of any type.
|
|
102
|
+
* @return {boolean}
|
|
103
|
+
*/
|
|
104
|
+
function validateChildKeys(component) {
|
|
105
|
+
if (Array.isArray(component)) {
|
|
106
|
+
for (var i = 0; i < component.length; i++) {
|
|
107
|
+
var child = component[i];
|
|
108
|
+
if (ReactComponent.isValidComponent(child)) {
|
|
109
|
+
validateExplicitKey(child);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else if (ReactComponent.isValidComponent(component)) {
|
|
113
|
+
// This component was passed in a valid location.
|
|
114
|
+
component.__keyValidated__ = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Components are the basic units of composition in React.
|
|
120
|
+
*
|
|
121
|
+
* Every component accepts a set of keyed input parameters known as "props" that
|
|
122
|
+
* are initialized by the constructor. Once a component is mounted, the props
|
|
123
|
+
* can be mutated using `setProps` or `replaceProps`.
|
|
124
|
+
*
|
|
125
|
+
* Every component is capable of the following operations:
|
|
126
|
+
*
|
|
127
|
+
* `mountComponent`
|
|
128
|
+
* Initializes the component, renders markup, and registers event listeners.
|
|
129
|
+
*
|
|
130
|
+
* `receiveComponent`
|
|
131
|
+
* Updates the rendered DOM nodes to match the given component.
|
|
132
|
+
*
|
|
133
|
+
* `unmountComponent`
|
|
134
|
+
* Releases any resources allocated by this component.
|
|
135
|
+
*
|
|
136
|
+
* Components can also be "owned" by other components. Being owned by another
|
|
137
|
+
* component means being constructed by that component. This is different from
|
|
138
|
+
* being the child of a component, which means having a DOM representation that
|
|
139
|
+
* is a child of the DOM representation of that component.
|
|
140
|
+
*
|
|
141
|
+
* @class ReactComponent
|
|
142
|
+
*/
|
|
143
|
+
var ReactComponent = {
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {?object} object
|
|
147
|
+
* @return {boolean} True if `object` is a valid component.
|
|
148
|
+
* @final
|
|
149
|
+
*/
|
|
150
|
+
isValidComponent: function(object) {
|
|
151
|
+
return !!(
|
|
152
|
+
object &&
|
|
153
|
+
typeof object.mountComponentIntoNode === 'function' &&
|
|
154
|
+
typeof object.receiveComponent === 'function'
|
|
155
|
+
);
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Generate a key string that identifies a component within a set.
|
|
160
|
+
*
|
|
161
|
+
* @param {*} component A component that could contain a manual key.
|
|
162
|
+
* @param {number} index Index that is used if a manual key is not provided.
|
|
163
|
+
* @return {string}
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
getKey: function(component, index) {
|
|
167
|
+
if (component && component.props && component.props.key != null) {
|
|
168
|
+
// Explicit key
|
|
169
|
+
return '{' + component.props.key + '}';
|
|
170
|
+
}
|
|
171
|
+
// Implicit key determined by the index in the set
|
|
172
|
+
return '[' + index + ']';
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @internal
|
|
177
|
+
*/
|
|
178
|
+
LifeCycle: ComponentLifeCycle,
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Injected module that provides ability to mutate individual properties.
|
|
182
|
+
* Injected into the base class because many different subclasses need access
|
|
183
|
+
* to this.
|
|
184
|
+
*
|
|
185
|
+
* @internal
|
|
186
|
+
*/
|
|
187
|
+
DOMIDOperations: ReactComponentEnvironment.DOMIDOperations,
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Optionally injectable environment dependent cleanup hook. (server vs.
|
|
191
|
+
* browser etc). Example: A browser system caches DOM nodes based on component
|
|
192
|
+
* ID and must remove that cache entry when this instance is unmounted.
|
|
193
|
+
*
|
|
194
|
+
* @private
|
|
195
|
+
*/
|
|
196
|
+
unmountIDFromEnvironment: ReactComponentEnvironment.unmountIDFromEnvironment,
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* The "image" of a component tree, is the platform specific (typically
|
|
200
|
+
* serialized) data that represents a tree of lower level UI building blocks.
|
|
201
|
+
* On the web, this "image" is HTML markup which describes a construction of
|
|
202
|
+
* low level `div` and `span` nodes. Other platforms may have different
|
|
203
|
+
* encoding of this "image". This must be injected.
|
|
204
|
+
*
|
|
205
|
+
* @private
|
|
206
|
+
*/
|
|
207
|
+
mountImageIntoNode: ReactComponentEnvironment.mountImageIntoNode,
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* React references `ReactReconcileTransaction` using this property in order
|
|
211
|
+
* to allow dependency injection.
|
|
212
|
+
*
|
|
213
|
+
* @internal
|
|
214
|
+
*/
|
|
215
|
+
ReactReconcileTransaction:
|
|
216
|
+
ReactComponentEnvironment.ReactReconcileTransaction,
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Base functionality for every ReactComponent constructor. Mixed into the
|
|
220
|
+
* `ReactComponent` prototype, but exposed statically for easy access.
|
|
221
|
+
*
|
|
222
|
+
* @lends {ReactComponent.prototype}
|
|
223
|
+
*/
|
|
224
|
+
Mixin: merge(ReactComponentEnvironment.Mixin, {
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Checks whether or not this component is mounted.
|
|
228
|
+
*
|
|
229
|
+
* @return {boolean} True if mounted, false otherwise.
|
|
230
|
+
* @final
|
|
231
|
+
* @protected
|
|
232
|
+
*/
|
|
233
|
+
isMounted: function() {
|
|
234
|
+
return this._lifeCycleState === ComponentLifeCycle.MOUNTED;
|
|
235
|
+
},
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Sets a subset of the props.
|
|
239
|
+
*
|
|
240
|
+
* @param {object} partialProps Subset of the next props.
|
|
241
|
+
* @param {?function} callback Called after props are updated.
|
|
242
|
+
* @final
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
setProps: function(partialProps, callback) {
|
|
246
|
+
// Merge with `_pendingProps` if it exists, otherwise with existing props.
|
|
247
|
+
this.replaceProps(
|
|
248
|
+
merge(this._pendingProps || this.props, partialProps),
|
|
249
|
+
callback
|
|
250
|
+
);
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Replaces all of the props.
|
|
255
|
+
*
|
|
256
|
+
* @param {object} props New props.
|
|
257
|
+
* @param {?function} callback Called after props are updated.
|
|
258
|
+
* @final
|
|
259
|
+
* @public
|
|
260
|
+
*/
|
|
261
|
+
replaceProps: function(props, callback) {
|
|
262
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
263
|
+
!this.props.__owner__,
|
|
264
|
+
'replaceProps(...): You called `setProps` or `replaceProps` on a ' +
|
|
265
|
+
'component with an owner. This is an anti-pattern since props will ' +
|
|
266
|
+
'get reactively updated when rendered. Instead, change the owner\'s ' +
|
|
267
|
+
'`render` method to pass the correct value as props to the component ' +
|
|
268
|
+
'where it is created.'
|
|
269
|
+
) : invariant(!this.props.__owner__));
|
|
270
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
271
|
+
this.isMounted(),
|
|
272
|
+
'replaceProps(...): Can only update a mounted component.'
|
|
273
|
+
) : invariant(this.isMounted()));
|
|
274
|
+
this._pendingProps = props;
|
|
275
|
+
ReactUpdates.enqueueUpdate(this, callback);
|
|
276
|
+
},
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Base constructor for all React component.
|
|
280
|
+
*
|
|
281
|
+
* Subclasses that override this method should make sure to invoke
|
|
282
|
+
* `ReactComponent.Mixin.construct.call(this, ...)`.
|
|
283
|
+
*
|
|
284
|
+
* @param {?object} initialProps
|
|
285
|
+
* @param {*} children
|
|
286
|
+
* @internal
|
|
287
|
+
*/
|
|
288
|
+
construct: function(initialProps, children) {
|
|
289
|
+
this.props = initialProps || {};
|
|
290
|
+
// Record the component responsible for creating this component.
|
|
291
|
+
this.props.__owner__ = ReactCurrentOwner.current;
|
|
292
|
+
// All components start unmounted.
|
|
293
|
+
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
294
|
+
|
|
295
|
+
this._pendingProps = null;
|
|
296
|
+
this._pendingCallbacks = null;
|
|
297
|
+
|
|
298
|
+
// Children can be more than one argument
|
|
299
|
+
var childrenLength = arguments.length - 1;
|
|
300
|
+
if (childrenLength === 1) {
|
|
301
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
302
|
+
validateChildKeys(children);
|
|
303
|
+
}
|
|
304
|
+
this.props.children = children;
|
|
305
|
+
} else if (childrenLength > 1) {
|
|
306
|
+
var childArray = Array(childrenLength);
|
|
307
|
+
for (var i = 0; i < childrenLength; i++) {
|
|
308
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
309
|
+
validateChildKeys(arguments[i + 1]);
|
|
310
|
+
}
|
|
311
|
+
childArray[i] = arguments[i + 1];
|
|
312
|
+
}
|
|
313
|
+
this.props.children = childArray;
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Initializes the component, renders markup, and registers event listeners.
|
|
319
|
+
*
|
|
320
|
+
* NOTE: This does not insert any nodes into the DOM.
|
|
321
|
+
*
|
|
322
|
+
* Subclasses that override this method should make sure to invoke
|
|
323
|
+
* `ReactComponent.Mixin.mountComponent.call(this, ...)`.
|
|
324
|
+
*
|
|
325
|
+
* @param {string} rootID DOM ID of the root node.
|
|
326
|
+
* @param {ReactReconcileTransaction} transaction
|
|
327
|
+
* @param {number} mountDepth number of components in the owner hierarchy.
|
|
328
|
+
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
329
|
+
* @internal
|
|
330
|
+
*/
|
|
331
|
+
mountComponent: function(rootID, transaction, mountDepth) {
|
|
332
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
333
|
+
!this.isMounted(),
|
|
334
|
+
'mountComponent(%s, ...): Can only mount an unmounted component.',
|
|
335
|
+
rootID
|
|
336
|
+
) : invariant(!this.isMounted()));
|
|
337
|
+
var props = this.props;
|
|
338
|
+
if (props.ref != null) {
|
|
339
|
+
ReactOwner.addComponentAsRefTo(this, props.ref, props.__owner__);
|
|
340
|
+
}
|
|
341
|
+
this._rootNodeID = rootID;
|
|
342
|
+
this._lifeCycleState = ComponentLifeCycle.MOUNTED;
|
|
343
|
+
this._mountDepth = mountDepth;
|
|
344
|
+
// Effectively: return '';
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Releases any resources allocated by `mountComponent`.
|
|
349
|
+
*
|
|
350
|
+
* NOTE: This does not remove any nodes from the DOM.
|
|
351
|
+
*
|
|
352
|
+
* Subclasses that override this method should make sure to invoke
|
|
353
|
+
* `ReactComponent.Mixin.unmountComponent.call(this)`.
|
|
354
|
+
*
|
|
355
|
+
* @internal
|
|
356
|
+
*/
|
|
357
|
+
unmountComponent: function() {
|
|
358
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
359
|
+
this.isMounted(),
|
|
360
|
+
'unmountComponent(): Can only unmount a mounted component.'
|
|
361
|
+
) : invariant(this.isMounted()));
|
|
362
|
+
var props = this.props;
|
|
363
|
+
if (props.ref != null) {
|
|
364
|
+
ReactOwner.removeComponentAsRefFrom(this, props.ref, props.__owner__);
|
|
365
|
+
}
|
|
366
|
+
ReactComponent.unmountIDFromEnvironment(this._rootNodeID);
|
|
367
|
+
this._rootNodeID = null;
|
|
368
|
+
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Given a new instance of this component, updates the rendered DOM nodes
|
|
373
|
+
* as if that instance was rendered instead.
|
|
374
|
+
*
|
|
375
|
+
* Subclasses that override this method should make sure to invoke
|
|
376
|
+
* `ReactComponent.Mixin.receiveComponent.call(this, ...)`.
|
|
377
|
+
*
|
|
378
|
+
* @param {object} nextComponent Next set of properties.
|
|
379
|
+
* @param {ReactReconcileTransaction} transaction
|
|
380
|
+
* @internal
|
|
381
|
+
*/
|
|
382
|
+
receiveComponent: function(nextComponent, transaction) {
|
|
383
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
384
|
+
this.isMounted(),
|
|
385
|
+
'receiveComponent(...): Can only update a mounted component.'
|
|
386
|
+
) : invariant(this.isMounted()));
|
|
387
|
+
this._pendingProps = nextComponent.props;
|
|
388
|
+
this._performUpdateIfNecessary(transaction);
|
|
389
|
+
},
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Call `_performUpdateIfNecessary` within a new transaction.
|
|
393
|
+
*
|
|
394
|
+
* @param {ReactReconcileTransaction} transaction
|
|
395
|
+
* @internal
|
|
396
|
+
*/
|
|
397
|
+
performUpdateIfNecessary: function() {
|
|
398
|
+
var transaction = ReactComponent.ReactReconcileTransaction.getPooled();
|
|
399
|
+
transaction.perform(this._performUpdateIfNecessary, this, transaction);
|
|
400
|
+
ReactComponent.ReactReconcileTransaction.release(transaction);
|
|
401
|
+
},
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* If `_pendingProps` is set, update the component.
|
|
405
|
+
*
|
|
406
|
+
* @param {ReactReconcileTransaction} transaction
|
|
407
|
+
* @internal
|
|
408
|
+
*/
|
|
409
|
+
_performUpdateIfNecessary: function(transaction) {
|
|
410
|
+
if (this._pendingProps == null) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
var prevProps = this.props;
|
|
414
|
+
this.props = this._pendingProps;
|
|
415
|
+
this._pendingProps = null;
|
|
416
|
+
this.updateComponent(transaction, prevProps);
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Updates the component's currently mounted representation.
|
|
421
|
+
*
|
|
422
|
+
* @param {ReactReconcileTransaction} transaction
|
|
423
|
+
* @param {object} prevProps
|
|
424
|
+
* @internal
|
|
425
|
+
*/
|
|
426
|
+
updateComponent: function(transaction, prevProps) {
|
|
427
|
+
var props = this.props;
|
|
428
|
+
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
429
|
+
// has stored a reference to `this`, and the previous owner (if different)
|
|
430
|
+
// has forgotten the reference to `this`.
|
|
431
|
+
if (props.__owner__ !== prevProps.__owner__ ||
|
|
432
|
+
props.ref !== prevProps.ref) {
|
|
433
|
+
if (prevProps.ref != null) {
|
|
434
|
+
ReactOwner.removeComponentAsRefFrom(
|
|
435
|
+
this, prevProps.ref, prevProps.__owner__
|
|
436
|
+
);
|
|
437
|
+
}
|
|
438
|
+
// Correct, even if the owner is the same, and only the ref has changed.
|
|
439
|
+
if (props.ref != null) {
|
|
440
|
+
ReactOwner.addComponentAsRefTo(this, props.ref, props.__owner__);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Mounts this component and inserts it into the DOM.
|
|
447
|
+
*
|
|
448
|
+
* @param {string} rootID DOM ID of the root node.
|
|
449
|
+
* @param {DOMElement} container DOM element to mount into.
|
|
450
|
+
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
451
|
+
* @final
|
|
452
|
+
* @internal
|
|
453
|
+
* @see {ReactMount.renderComponent}
|
|
454
|
+
*/
|
|
455
|
+
mountComponentIntoNode: function(rootID, container, shouldReuseMarkup) {
|
|
456
|
+
var transaction = ReactComponent.ReactReconcileTransaction.getPooled();
|
|
457
|
+
transaction.perform(
|
|
458
|
+
this._mountComponentIntoNode,
|
|
459
|
+
this,
|
|
460
|
+
rootID,
|
|
461
|
+
container,
|
|
462
|
+
transaction,
|
|
463
|
+
shouldReuseMarkup
|
|
464
|
+
);
|
|
465
|
+
ReactComponent.ReactReconcileTransaction.release(transaction);
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @param {string} rootID DOM ID of the root node.
|
|
470
|
+
* @param {DOMElement} container DOM element to mount into.
|
|
471
|
+
* @param {ReactReconcileTransaction} transaction
|
|
472
|
+
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
473
|
+
* @final
|
|
474
|
+
* @private
|
|
475
|
+
*/
|
|
476
|
+
_mountComponentIntoNode: function(
|
|
477
|
+
rootID,
|
|
478
|
+
container,
|
|
479
|
+
transaction,
|
|
480
|
+
shouldReuseMarkup) {
|
|
481
|
+
var markup = this.mountComponent(rootID, transaction, 0);
|
|
482
|
+
ReactComponent.mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Checks if this component is owned by the supplied `owner` component.
|
|
487
|
+
*
|
|
488
|
+
* @param {ReactComponent} owner Component to check.
|
|
489
|
+
* @return {boolean} True if `owners` owns this component.
|
|
490
|
+
* @final
|
|
491
|
+
* @internal
|
|
492
|
+
*/
|
|
493
|
+
isOwnedBy: function(owner) {
|
|
494
|
+
return this.props.__owner__ === owner;
|
|
495
|
+
},
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Gets another component, that shares the same owner as this one, by ref.
|
|
499
|
+
*
|
|
500
|
+
* @param {string} ref of a sibling Component.
|
|
501
|
+
* @return {?ReactComponent} the actual sibling Component.
|
|
502
|
+
* @final
|
|
503
|
+
* @internal
|
|
504
|
+
*/
|
|
505
|
+
getSiblingByRef: function(ref) {
|
|
506
|
+
var owner = this.props.__owner__;
|
|
507
|
+
if (!owner || !owner.refs) {
|
|
508
|
+
return null;
|
|
509
|
+
}
|
|
510
|
+
return owner.refs[ref];
|
|
511
|
+
}
|
|
512
|
+
})
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
module.exports = ReactComponent;
|