react 0.8.0 → 0.10.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 +0 -8
- package/addons.js +0 -3
- package/lib/AutoFocusMixin.js +32 -0
- package/lib/CSSCore.js +23 -22
- package/lib/CSSProperty.js +32 -1
- package/lib/CSSPropertyOperations.js +1 -1
- package/lib/ChangeEventPlugin.js +27 -5
- package/lib/ClientReactRootIndex.js +30 -0
- package/lib/CompositionEventPlugin.js +58 -10
- package/lib/DOMChildrenOperations.js +39 -3
- package/lib/DOMProperty.js +9 -5
- package/lib/DOMPropertyOperations.js +21 -8
- package/lib/Danger.js +9 -8
- package/lib/DefaultDOMPropertyConfig.js +23 -14
- package/lib/DefaultEventPluginOrder.js +1 -1
- package/lib/EnterLeaveEventPlugin.js +38 -5
- package/lib/EventConstants.js +4 -1
- package/lib/EventListener.js +42 -34
- package/lib/EventPluginHub.js +118 -13
- package/lib/EventPluginRegistry.js +62 -18
- package/lib/EventPluginUtils.js +33 -4
- package/lib/EventPropagators.js +7 -43
- package/lib/ExecutionEnvironment.js +4 -1
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +160 -0
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/PooledClass.js +7 -1
- package/lib/React.js +30 -4
- package/lib/ReactBrowserComponentMixin.js +42 -0
- package/lib/ReactCSSTransitionGroup.js +65 -0
- package/lib/{ReactTransitionableChild.js → ReactCSSTransitionGroupChild.js} +22 -36
- package/lib/ReactChildren.js +4 -4
- package/lib/ReactComponent.js +163 -83
- package/lib/ReactComponentBrowserEnvironment.js +55 -71
- package/lib/ReactCompositeComponent.js +686 -119
- package/lib/ReactContext.js +67 -0
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +19 -6
- package/lib/ReactDOMButton.js +6 -1
- package/lib/ReactDOMComponent.js +66 -24
- package/lib/ReactDOMForm.js +13 -3
- package/lib/ReactDOMIDOperations.js +106 -61
- package/lib/ReactDOMImg.js +61 -0
- package/lib/ReactDOMInput.js +28 -15
- package/lib/ReactDOMOption.js +13 -8
- package/lib/ReactDOMSelect.js +38 -18
- package/lib/ReactDOMSelection.js +1 -1
- package/lib/ReactDOMTextarea.js +19 -11
- package/lib/ReactDefaultBatchingStrategy.js +1 -1
- package/lib/ReactDefaultInjection.js +60 -26
- package/lib/ReactDefaultPerf.js +208 -371
- package/lib/ReactDefaultPerfAnalysis.js +199 -0
- package/lib/ReactErrorUtils.js +6 -15
- package/lib/ReactEventEmitter.js +144 -146
- package/lib/ReactEventEmitterMixin.js +1 -33
- package/lib/ReactEventTopLevelCallback.js +75 -15
- package/lib/ReactInjection.js +43 -0
- package/lib/ReactInputSelection.js +3 -2
- package/lib/ReactInstanceHandles.js +36 -20
- package/lib/ReactLink.js +2 -2
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +136 -104
- package/lib/ReactMountReady.js +2 -2
- package/lib/ReactMultiChild.js +40 -49
- package/lib/ReactMultiChildUpdateTypes.js +3 -1
- package/lib/ReactOwner.js +17 -4
- package/lib/ReactPerf.js +6 -9
- package/lib/ReactPropTransferer.js +41 -22
- package/lib/ReactPropTypeLocationNames.js +31 -0
- package/lib/{ReactComponentEnvironment.js → ReactPropTypeLocations.js} +11 -6
- package/lib/ReactPropTypes.js +249 -48
- package/lib/ReactPutListenerQueue.js +61 -0
- package/lib/ReactReconcileTransaction.js +28 -7
- package/lib/ReactRootIndex.js +36 -0
- package/lib/ReactServerRendering.js +46 -19
- package/lib/ReactServerRenderingTransaction.js +116 -0
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +394 -0
- package/lib/ReactTextComponent.js +33 -6
- package/lib/{ReactTransitionKeySet.js → ReactTransitionChildMapping.js} +43 -48
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +133 -58
- package/lib/ReactUpdates.js +15 -12
- package/lib/ReactWithAddons.js +15 -3
- package/lib/SelectEventPlugin.js +23 -40
- package/lib/ServerReactRootIndex.js +36 -0
- package/lib/SimpleEventPlugin.js +55 -7
- package/lib/SyntheticClipboardEvent.js +8 -2
- package/lib/SyntheticCompositionEvent.js +1 -1
- package/lib/SyntheticDragEvent.js +44 -0
- package/lib/SyntheticEvent.js +3 -2
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticKeyboardEvent.js +5 -3
- package/lib/SyntheticMouseEvent.js +1 -1
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/SyntheticWheelEvent.js +11 -8
- package/lib/Transaction.js +62 -37
- package/lib/ViewportMetrics.js +1 -1
- package/lib/accumulate.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/cloneWithProps.js +59 -0
- package/lib/containsNode.js +1 -1
- package/lib/copyProperties.js +1 -1
- package/lib/createArrayFrom.js +11 -14
- package/lib/createFullPageComponent.js +63 -0
- package/lib/createNodesFromMarkup.js +1 -1
- package/lib/createObjectFrom.js +1 -1
- package/lib/cx.js +3 -3
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/emptyFunction.js +1 -1
- package/lib/emptyObject.js +27 -0
- package/lib/escapeTextForBrowser.js +1 -1
- package/lib/flattenChildren.js +6 -3
- package/lib/focusNode.js +33 -0
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getActiveElement.js +5 -4
- package/lib/getEventKey.js +85 -0
- package/lib/getEventTarget.js +1 -1
- package/lib/getMarkupWrap.js +11 -1
- package/lib/getNodeForCharacterOffset.js +1 -1
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +6 -4
- package/lib/getUnboundedScrollPosition.js +3 -3
- package/lib/hyphenate.js +1 -1
- package/lib/instantiateReactComponent.js +70 -0
- package/lib/invariant.js +20 -12
- package/lib/isEventSupported.js +8 -12
- package/lib/isNode.js +2 -2
- package/lib/isTextInputElement.js +1 -1
- package/lib/isTextNode.js +1 -1
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/keyOf.js +1 -1
- package/lib/memoizeStringOnly.js +1 -1
- package/lib/merge.js +1 -1
- package/lib/mergeHelpers.js +6 -7
- package/lib/mergeInto.js +1 -1
- package/lib/mixInto.js +1 -1
- package/lib/monitorCodeUse.js +37 -0
- package/lib/objMap.js +1 -1
- package/lib/objMapKeyVal.js +1 -1
- package/lib/onlyChild.js +43 -0
- package/lib/performanceNow.js +1 -1
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +61 -0
- package/lib/toArray.js +75 -0
- package/lib/traverseAllChildren.js +72 -9
- package/lib/update.js +159 -0
- package/lib/warning.js +48 -0
- package/package.json +3 -3
- package/react.js +0 -3
- package/ReactJSErrors.js +0 -40
- package/lib/$.js +0 -46
- package/lib/CallbackRegistry.js +0 -91
- package/lib/LinkedValueMixin.js +0 -68
- package/lib/ex.js +0 -49
- package/lib/filterAttributes.js +0 -45
- package/lib/ge.js +0 -76
- package/lib/mutateHTMLNodeWithMarkup.js +0 -100
package/lib/ReactChildren.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013 Facebook, Inc.
|
|
2
|
+
* Copyright 2013-2014 Facebook, Inc.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -52,7 +52,7 @@ function forEachSingleChild(traverseContext, child, name, i) {
|
|
|
52
52
|
* The provided forEachFunc(child, index) will be called for each
|
|
53
53
|
* leaf child.
|
|
54
54
|
*
|
|
55
|
-
* @param {
|
|
55
|
+
* @param {?*} children Children tree container.
|
|
56
56
|
* @param {function(*, int)} forEachFunc.
|
|
57
57
|
* @param {*} forEachContext Context for forEachContext.
|
|
58
58
|
*/
|
|
@@ -107,10 +107,10 @@ function mapSingleChildIntoContext(traverseContext, child, name, i) {
|
|
|
107
107
|
* TODO: This may likely break any calls to `ReactChildren.map` that were
|
|
108
108
|
* previously relying on the fact that we guarded against null children.
|
|
109
109
|
*
|
|
110
|
-
* @param {
|
|
110
|
+
* @param {?*} children Children tree container.
|
|
111
111
|
* @param {function(*, int)} mapFunction.
|
|
112
112
|
* @param {*} mapContext Context for mapFunction.
|
|
113
|
-
* @return {
|
|
113
|
+
* @return {object} Object containing the ordered map of results.
|
|
114
114
|
*/
|
|
115
115
|
function mapChildren(children, func, context) {
|
|
116
116
|
if (children == null) {
|
package/lib/ReactComponent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2013 Facebook, Inc.
|
|
2
|
+
* Copyright 2013-2014 Facebook, Inc.
|
|
3
3
|
*
|
|
4
4
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
5
|
* you may not use this file except in compliance with the License.
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
|
|
19
19
|
"use strict";
|
|
20
20
|
|
|
21
|
-
var ReactComponentEnvironment = require("./ReactComponentEnvironment");
|
|
22
21
|
var ReactCurrentOwner = require("./ReactCurrentOwner");
|
|
23
22
|
var ReactOwner = require("./ReactOwner");
|
|
24
23
|
var ReactUpdates = require("./ReactUpdates");
|
|
@@ -26,6 +25,7 @@ var ReactUpdates = require("./ReactUpdates");
|
|
|
26
25
|
var invariant = require("./invariant");
|
|
27
26
|
var keyMirror = require("./keyMirror");
|
|
28
27
|
var merge = require("./merge");
|
|
28
|
+
var monitorCodeUse = require("./monitorCodeUse");
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
31
|
* Every React component is in one of these life cycles.
|
|
@@ -43,16 +43,43 @@ var ComponentLifeCycle = keyMirror({
|
|
|
43
43
|
});
|
|
44
44
|
|
|
45
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
|
|
46
|
+
* Warn if there's no key explicitly set on dynamic arrays of children or
|
|
47
|
+
* object keys are not valid. This allows us to keep track of children between
|
|
48
|
+
* updates.
|
|
48
49
|
*/
|
|
49
50
|
|
|
50
|
-
var
|
|
51
|
+
var ownerHasExplicitKeyWarning = {};
|
|
52
|
+
var ownerHasPropertyWarning = {};
|
|
53
|
+
var ownerHasMonitoredObjectMap = {};
|
|
54
|
+
|
|
55
|
+
var NUMERIC_PROPERTY_REGEX = /^\d+$/;
|
|
56
|
+
|
|
57
|
+
var injected = false;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Optionally injectable environment dependent cleanup hook. (server vs.
|
|
61
|
+
* browser etc). Example: A browser system caches DOM nodes based on component
|
|
62
|
+
* ID and must remove that cache entry when this instance is unmounted.
|
|
63
|
+
*
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
var unmountIDFromEnvironment = null;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The "image" of a component tree, is the platform specific (typically
|
|
70
|
+
* serialized) data that represents a tree of lower level UI building blocks.
|
|
71
|
+
* On the web, this "image" is HTML markup which describes a construction of
|
|
72
|
+
* low level `div` and `span` nodes. Other platforms may have different
|
|
73
|
+
* encoding of this "image". This must be injected.
|
|
74
|
+
*
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
var mountImageIntoNode = null;
|
|
51
78
|
|
|
52
79
|
/**
|
|
53
80
|
* Warn if the component doesn't have an explicit key assigned to it.
|
|
54
81
|
* This component is in an array. The array could grow and shrink or be
|
|
55
|
-
* reordered. All children
|
|
82
|
+
* reordered. All children that haven't already been validated are required to
|
|
56
83
|
* have a "key" property assigned to it.
|
|
57
84
|
*
|
|
58
85
|
* @internal
|
|
@@ -71,18 +98,20 @@ function validateExplicitKey(component) {
|
|
|
71
98
|
|
|
72
99
|
// Name of the component whose render method tried to pass children.
|
|
73
100
|
var currentName = ReactCurrentOwner.current.constructor.displayName;
|
|
74
|
-
if (
|
|
101
|
+
if (ownerHasExplicitKeyWarning.hasOwnProperty(currentName)) {
|
|
75
102
|
return;
|
|
76
103
|
}
|
|
77
|
-
|
|
104
|
+
ownerHasExplicitKeyWarning[currentName] = true;
|
|
78
105
|
|
|
79
106
|
var message = 'Each child in an array should have a unique "key" prop. ' +
|
|
80
107
|
'Check the render method of ' + currentName + '.';
|
|
108
|
+
|
|
109
|
+
var childOwnerName = null;
|
|
81
110
|
if (!component.isOwnedBy(ReactCurrentOwner.current)) {
|
|
82
111
|
// Name of the component that originally created this child.
|
|
83
|
-
|
|
84
|
-
component.
|
|
85
|
-
component.
|
|
112
|
+
childOwnerName =
|
|
113
|
+
component._owner &&
|
|
114
|
+
component._owner.constructor.displayName;
|
|
86
115
|
|
|
87
116
|
// Usually the current owner is the offender, but if it accepts
|
|
88
117
|
// children as a property, it may be the creator of the child that's
|
|
@@ -90,12 +119,63 @@ function validateExplicitKey(component) {
|
|
|
90
119
|
message += ' It was passed a child from ' + childOwnerName + '.';
|
|
91
120
|
}
|
|
92
121
|
|
|
122
|
+
message += ' See http://fb.me/react-warning-keys for more information.';
|
|
123
|
+
monitorCodeUse('react_key_warning', {
|
|
124
|
+
component: currentName,
|
|
125
|
+
componentOwner: childOwnerName
|
|
126
|
+
});
|
|
93
127
|
console.warn(message);
|
|
94
128
|
}
|
|
95
129
|
|
|
96
130
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
131
|
+
* Warn if the key is being defined as an object property but has an incorrect
|
|
132
|
+
* value.
|
|
133
|
+
*
|
|
134
|
+
* @internal
|
|
135
|
+
* @param {string} name Property name of the key.
|
|
136
|
+
* @param {ReactComponent} component Component that requires a key.
|
|
137
|
+
*/
|
|
138
|
+
function validatePropertyKey(name) {
|
|
139
|
+
if (NUMERIC_PROPERTY_REGEX.test(name)) {
|
|
140
|
+
// Name of the component whose render method tried to pass children.
|
|
141
|
+
var currentName = ReactCurrentOwner.current.constructor.displayName;
|
|
142
|
+
if (ownerHasPropertyWarning.hasOwnProperty(currentName)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
ownerHasPropertyWarning[currentName] = true;
|
|
146
|
+
|
|
147
|
+
monitorCodeUse('react_numeric_key_warning');
|
|
148
|
+
console.warn(
|
|
149
|
+
'Child objects should have non-numeric keys so ordering is preserved. ' +
|
|
150
|
+
'Check the render method of ' + currentName + '. ' +
|
|
151
|
+
'See http://fb.me/react-warning-keys for more information.'
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Log that we're using an object map. We're considering deprecating this
|
|
158
|
+
* feature and replace it with proper Map and ImmutableMap data structures.
|
|
159
|
+
*
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
function monitorUseOfObjectMap() {
|
|
163
|
+
// Name of the component whose render method tried to pass children.
|
|
164
|
+
// We only use this to avoid spewing the logs. We lose additional
|
|
165
|
+
// owner stacks but hopefully one level is enough to trace the source.
|
|
166
|
+
var currentName = (ReactCurrentOwner.current &&
|
|
167
|
+
ReactCurrentOwner.current.constructor.displayName) || '';
|
|
168
|
+
if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
ownerHasMonitoredObjectMap[currentName] = true;
|
|
172
|
+
monitorCodeUse('react_object_map_children');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Ensure that every component either is passed in a static location, in an
|
|
177
|
+
* array with an explicit keys property defined, or in an object literal
|
|
178
|
+
* with valid key property.
|
|
99
179
|
*
|
|
100
180
|
* @internal
|
|
101
181
|
* @param {*} component Statically passed child of any type.
|
|
@@ -112,6 +192,11 @@ function validateChildKeys(component) {
|
|
|
112
192
|
} else if (ReactComponent.isValidComponent(component)) {
|
|
113
193
|
// This component was passed in a valid location.
|
|
114
194
|
component.__keyValidated__ = true;
|
|
195
|
+
} else if (component && typeof component === 'object') {
|
|
196
|
+
monitorUseOfObjectMap();
|
|
197
|
+
for (var name in component) {
|
|
198
|
+
validatePropertyKey(name, component);
|
|
199
|
+
}
|
|
115
200
|
}
|
|
116
201
|
}
|
|
117
202
|
|
|
@@ -142,34 +227,41 @@ function validateChildKeys(component) {
|
|
|
142
227
|
*/
|
|
143
228
|
var ReactComponent = {
|
|
144
229
|
|
|
230
|
+
injection: {
|
|
231
|
+
injectEnvironment: function(ReactComponentEnvironment) {
|
|
232
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
233
|
+
!injected,
|
|
234
|
+
'ReactComponent: injectEnvironment() can only be called once.'
|
|
235
|
+
) : invariant(!injected));
|
|
236
|
+
mountImageIntoNode = ReactComponentEnvironment.mountImageIntoNode;
|
|
237
|
+
unmountIDFromEnvironment =
|
|
238
|
+
ReactComponentEnvironment.unmountIDFromEnvironment;
|
|
239
|
+
ReactComponent.BackendIDOperations =
|
|
240
|
+
ReactComponentEnvironment.BackendIDOperations;
|
|
241
|
+
ReactComponent.ReactReconcileTransaction =
|
|
242
|
+
ReactComponentEnvironment.ReactReconcileTransaction;
|
|
243
|
+
injected = true;
|
|
244
|
+
}
|
|
245
|
+
},
|
|
246
|
+
|
|
145
247
|
/**
|
|
146
248
|
* @param {?object} object
|
|
147
249
|
* @return {boolean} True if `object` is a valid component.
|
|
148
250
|
* @final
|
|
149
251
|
*/
|
|
150
252
|
isValidComponent: function(object) {
|
|
151
|
-
|
|
152
|
-
|
|
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 + '}';
|
|
253
|
+
if (!object || !object.type || !object.type.prototype) {
|
|
254
|
+
return false;
|
|
170
255
|
}
|
|
171
|
-
//
|
|
172
|
-
|
|
256
|
+
// This is the safer way of duck checking the type of instance this is.
|
|
257
|
+
// The object can be a generic descriptor but the type property refers to
|
|
258
|
+
// the constructor and it's prototype can be used to inspect the type that
|
|
259
|
+
// will actually get mounted.
|
|
260
|
+
var prototype = object.type.prototype;
|
|
261
|
+
return (
|
|
262
|
+
typeof prototype.mountComponentIntoNode === 'function' &&
|
|
263
|
+
typeof prototype.receiveComponent === 'function'
|
|
264
|
+
);
|
|
173
265
|
},
|
|
174
266
|
|
|
175
267
|
/**
|
|
@@ -184,27 +276,7 @@ var ReactComponent = {
|
|
|
184
276
|
*
|
|
185
277
|
* @internal
|
|
186
278
|
*/
|
|
187
|
-
|
|
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,
|
|
279
|
+
BackendIDOperations: null,
|
|
208
280
|
|
|
209
281
|
/**
|
|
210
282
|
* React references `ReactReconcileTransaction` using this property in order
|
|
@@ -212,8 +284,7 @@ var ReactComponent = {
|
|
|
212
284
|
*
|
|
213
285
|
* @internal
|
|
214
286
|
*/
|
|
215
|
-
ReactReconcileTransaction:
|
|
216
|
-
ReactComponentEnvironment.ReactReconcileTransaction,
|
|
287
|
+
ReactReconcileTransaction: null,
|
|
217
288
|
|
|
218
289
|
/**
|
|
219
290
|
* Base functionality for every ReactComponent constructor. Mixed into the
|
|
@@ -221,7 +292,7 @@ var ReactComponent = {
|
|
|
221
292
|
*
|
|
222
293
|
* @lends {ReactComponent.prototype}
|
|
223
294
|
*/
|
|
224
|
-
Mixin:
|
|
295
|
+
Mixin: {
|
|
225
296
|
|
|
226
297
|
/**
|
|
227
298
|
* Checks whether or not this component is mounted.
|
|
@@ -260,23 +331,23 @@ var ReactComponent = {
|
|
|
260
331
|
*/
|
|
261
332
|
replaceProps: function(props, callback) {
|
|
262
333
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
263
|
-
|
|
334
|
+
this.isMounted(),
|
|
335
|
+
'replaceProps(...): Can only update a mounted component.'
|
|
336
|
+
) : invariant(this.isMounted()));
|
|
337
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
338
|
+
this._mountDepth === 0,
|
|
264
339
|
'replaceProps(...): You called `setProps` or `replaceProps` on a ' +
|
|
265
|
-
'component with
|
|
340
|
+
'component with a parent. This is an anti-pattern since props will ' +
|
|
266
341
|
'get reactively updated when rendered. Instead, change the owner\'s ' +
|
|
267
342
|
'`render` method to pass the correct value as props to the component ' +
|
|
268
343
|
'where it is created.'
|
|
269
|
-
) : invariant(
|
|
270
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
271
|
-
this.isMounted(),
|
|
272
|
-
'replaceProps(...): Can only update a mounted component.'
|
|
273
|
-
) : invariant(this.isMounted()));
|
|
344
|
+
) : invariant(this._mountDepth === 0));
|
|
274
345
|
this._pendingProps = props;
|
|
275
346
|
ReactUpdates.enqueueUpdate(this, callback);
|
|
276
347
|
},
|
|
277
348
|
|
|
278
349
|
/**
|
|
279
|
-
* Base constructor for all React
|
|
350
|
+
* Base constructor for all React components.
|
|
280
351
|
*
|
|
281
352
|
* Subclasses that override this method should make sure to invoke
|
|
282
353
|
* `ReactComponent.Mixin.construct.call(this, ...)`.
|
|
@@ -288,13 +359,19 @@ var ReactComponent = {
|
|
|
288
359
|
construct: function(initialProps, children) {
|
|
289
360
|
this.props = initialProps || {};
|
|
290
361
|
// Record the component responsible for creating this component.
|
|
291
|
-
this.
|
|
362
|
+
this._owner = ReactCurrentOwner.current;
|
|
292
363
|
// All components start unmounted.
|
|
293
364
|
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
294
365
|
|
|
295
366
|
this._pendingProps = null;
|
|
296
367
|
this._pendingCallbacks = null;
|
|
297
368
|
|
|
369
|
+
// Unlike _pendingProps and _pendingCallbacks, we won't use null to
|
|
370
|
+
// indicate that nothing is pending because it's possible for a component
|
|
371
|
+
// to have a null owner. Instead, an owner change is pending when
|
|
372
|
+
// this._owner !== this._pendingOwner.
|
|
373
|
+
this._pendingOwner = this._owner;
|
|
374
|
+
|
|
298
375
|
// Children can be more than one argument
|
|
299
376
|
var childrenLength = arguments.length - 1;
|
|
300
377
|
if (childrenLength === 1) {
|
|
@@ -323,7 +400,7 @@ var ReactComponent = {
|
|
|
323
400
|
* `ReactComponent.Mixin.mountComponent.call(this, ...)`.
|
|
324
401
|
*
|
|
325
402
|
* @param {string} rootID DOM ID of the root node.
|
|
326
|
-
* @param {ReactReconcileTransaction} transaction
|
|
403
|
+
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
|
327
404
|
* @param {number} mountDepth number of components in the owner hierarchy.
|
|
328
405
|
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
329
406
|
* @internal
|
|
@@ -331,12 +408,14 @@ var ReactComponent = {
|
|
|
331
408
|
mountComponent: function(rootID, transaction, mountDepth) {
|
|
332
409
|
("production" !== process.env.NODE_ENV ? invariant(
|
|
333
410
|
!this.isMounted(),
|
|
334
|
-
'mountComponent(%s, ...): Can only mount an unmounted component.'
|
|
411
|
+
'mountComponent(%s, ...): Can only mount an unmounted component. ' +
|
|
412
|
+
'Make sure to avoid storing components between renders or reusing a ' +
|
|
413
|
+
'single component instance in multiple places.',
|
|
335
414
|
rootID
|
|
336
415
|
) : invariant(!this.isMounted()));
|
|
337
416
|
var props = this.props;
|
|
338
417
|
if (props.ref != null) {
|
|
339
|
-
ReactOwner.addComponentAsRefTo(this, props.ref,
|
|
418
|
+
ReactOwner.addComponentAsRefTo(this, props.ref, this._owner);
|
|
340
419
|
}
|
|
341
420
|
this._rootNodeID = rootID;
|
|
342
421
|
this._lifeCycleState = ComponentLifeCycle.MOUNTED;
|
|
@@ -361,9 +440,9 @@ var ReactComponent = {
|
|
|
361
440
|
) : invariant(this.isMounted()));
|
|
362
441
|
var props = this.props;
|
|
363
442
|
if (props.ref != null) {
|
|
364
|
-
ReactOwner.removeComponentAsRefFrom(this, props.ref,
|
|
443
|
+
ReactOwner.removeComponentAsRefFrom(this, props.ref, this._owner);
|
|
365
444
|
}
|
|
366
|
-
|
|
445
|
+
unmountIDFromEnvironment(this._rootNodeID);
|
|
367
446
|
this._rootNodeID = null;
|
|
368
447
|
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
369
448
|
},
|
|
@@ -384,6 +463,7 @@ var ReactComponent = {
|
|
|
384
463
|
this.isMounted(),
|
|
385
464
|
'receiveComponent(...): Can only update a mounted component.'
|
|
386
465
|
) : invariant(this.isMounted()));
|
|
466
|
+
this._pendingOwner = nextComponent._owner;
|
|
387
467
|
this._pendingProps = nextComponent.props;
|
|
388
468
|
this._performUpdateIfNecessary(transaction);
|
|
389
469
|
},
|
|
@@ -391,7 +471,6 @@ var ReactComponent = {
|
|
|
391
471
|
/**
|
|
392
472
|
* Call `_performUpdateIfNecessary` within a new transaction.
|
|
393
473
|
*
|
|
394
|
-
* @param {ReactReconcileTransaction} transaction
|
|
395
474
|
* @internal
|
|
396
475
|
*/
|
|
397
476
|
performUpdateIfNecessary: function() {
|
|
@@ -411,9 +490,11 @@ var ReactComponent = {
|
|
|
411
490
|
return;
|
|
412
491
|
}
|
|
413
492
|
var prevProps = this.props;
|
|
493
|
+
var prevOwner = this._owner;
|
|
414
494
|
this.props = this._pendingProps;
|
|
495
|
+
this._owner = this._pendingOwner;
|
|
415
496
|
this._pendingProps = null;
|
|
416
|
-
this.updateComponent(transaction, prevProps);
|
|
497
|
+
this.updateComponent(transaction, prevProps, prevOwner);
|
|
417
498
|
},
|
|
418
499
|
|
|
419
500
|
/**
|
|
@@ -423,21 +504,20 @@ var ReactComponent = {
|
|
|
423
504
|
* @param {object} prevProps
|
|
424
505
|
* @internal
|
|
425
506
|
*/
|
|
426
|
-
updateComponent: function(transaction, prevProps) {
|
|
507
|
+
updateComponent: function(transaction, prevProps, prevOwner) {
|
|
427
508
|
var props = this.props;
|
|
428
509
|
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
429
510
|
// has stored a reference to `this`, and the previous owner (if different)
|
|
430
511
|
// has forgotten the reference to `this`.
|
|
431
|
-
if (props.
|
|
432
|
-
props.ref !== prevProps.ref) {
|
|
512
|
+
if (this._owner !== prevOwner || props.ref !== prevProps.ref) {
|
|
433
513
|
if (prevProps.ref != null) {
|
|
434
514
|
ReactOwner.removeComponentAsRefFrom(
|
|
435
|
-
this, prevProps.ref,
|
|
515
|
+
this, prevProps.ref, prevOwner
|
|
436
516
|
);
|
|
437
517
|
}
|
|
438
518
|
// Correct, even if the owner is the same, and only the ref has changed.
|
|
439
519
|
if (props.ref != null) {
|
|
440
|
-
ReactOwner.addComponentAsRefTo(this, props.ref,
|
|
520
|
+
ReactOwner.addComponentAsRefTo(this, props.ref, this._owner);
|
|
441
521
|
}
|
|
442
522
|
}
|
|
443
523
|
},
|
|
@@ -479,7 +559,7 @@ var ReactComponent = {
|
|
|
479
559
|
transaction,
|
|
480
560
|
shouldReuseMarkup) {
|
|
481
561
|
var markup = this.mountComponent(rootID, transaction, 0);
|
|
482
|
-
|
|
562
|
+
mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
483
563
|
},
|
|
484
564
|
|
|
485
565
|
/**
|
|
@@ -491,7 +571,7 @@ var ReactComponent = {
|
|
|
491
571
|
* @internal
|
|
492
572
|
*/
|
|
493
573
|
isOwnedBy: function(owner) {
|
|
494
|
-
return this.
|
|
574
|
+
return this._owner === owner;
|
|
495
575
|
},
|
|
496
576
|
|
|
497
577
|
/**
|
|
@@ -503,13 +583,13 @@ var ReactComponent = {
|
|
|
503
583
|
* @internal
|
|
504
584
|
*/
|
|
505
585
|
getSiblingByRef: function(ref) {
|
|
506
|
-
var owner = this.
|
|
586
|
+
var owner = this._owner;
|
|
507
587
|
if (!owner || !owner.refs) {
|
|
508
588
|
return null;
|
|
509
589
|
}
|
|
510
590
|
return owner.refs[ref];
|
|
511
591
|
}
|
|
512
|
-
}
|
|
592
|
+
}
|
|
513
593
|
};
|
|
514
594
|
|
|
515
595
|
module.exports = ReactComponent;
|