react 0.12.0 → 0.13.0-alpha.2
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/dist/JSXTransformer.js +2345 -910
- package/dist/react-with-addons.js +5273 -4111
- package/dist/react-with-addons.min.js +5 -6
- package/dist/react.js +4840 -3940
- package/dist/react.min.js +5 -6
- package/lib/AutoFocusMixin.js +1 -1
- package/lib/BeforeInputEventPlugin.js +389 -112
- package/lib/CSSProperty.js +6 -3
- package/lib/CSSPropertyOperations.js +21 -1
- package/lib/CallbackQueue.js +2 -2
- package/lib/ChangeEventPlugin.js +3 -3
- package/lib/ClientReactRootIndex.js +1 -1
- package/lib/DOMChildrenOperations.js +6 -4
- package/lib/DOMProperty.js +1 -1
- package/lib/DOMPropertyOperations.js +1 -1
- package/lib/Danger.js +7 -6
- package/lib/DefaultEventPluginOrder.js +1 -2
- package/lib/EnterLeaveEventPlugin.js +1 -1
- package/lib/EventConstants.js +1 -1
- package/lib/EventPluginHub.js +9 -7
- package/lib/EventPluginRegistry.js +1 -1
- package/lib/EventPluginUtils.js +1 -1
- package/lib/EventPropagators.js +1 -1
- package/lib/ExecutionEnvironment.js +2 -3
- package/lib/FallbackCompositionState.js +89 -0
- package/lib/HTMLDOMPropertyConfig.js +19 -7
- package/lib/LinkedStateMixin.js +1 -1
- package/lib/LinkedValueUtils.js +3 -3
- package/lib/LocalEventTrapMixin.js +1 -1
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +3 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +17 -50
- package/lib/ReactBrowserComponentMixin.js +3 -13
- package/lib/ReactBrowserEventEmitter.js +4 -6
- package/lib/ReactCSSTransitionGroup.js +4 -1
- package/lib/ReactCSSTransitionGroupChild.js +12 -2
- package/lib/ReactChildReconciler.js +121 -0
- package/lib/ReactChildren.js +10 -8
- package/lib/ReactClass.js +874 -0
- package/lib/ReactComponent.js +45 -286
- package/lib/ReactComponentBase.js +126 -0
- package/lib/ReactComponentBrowserEnvironment.js +10 -83
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +700 -1045
- package/lib/ReactContext.js +6 -2
- package/lib/ReactCurrentOwner.js +1 -1
- package/lib/ReactDOM.js +3 -8
- package/lib/ReactDOMButton.js +5 -6
- package/lib/ReactDOMComponent.js +120 -77
- package/lib/ReactDOMForm.js +5 -6
- package/lib/ReactDOMIDOperations.js +56 -74
- package/lib/ReactDOMImg.js +4 -6
- package/lib/ReactDOMInput.js +5 -6
- package/lib/ReactDOMOption.js +5 -6
- package/lib/ReactDOMSelect.js +57 -65
- package/lib/ReactDOMSelection.js +6 -2
- package/lib/ReactDOMTextComponent.js +124 -0
- package/lib/ReactDOMTextarea.js +5 -6
- package/lib/ReactDefaultBatchingStrategy.js +1 -1
- package/lib/ReactDefaultInjection.js +14 -8
- package/lib/ReactDefaultPerf.js +8 -7
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +22 -15
- package/lib/ReactElementValidator.js +192 -53
- package/lib/ReactEmptyComponent.js +29 -11
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +3 -3
- package/lib/ReactInjection.js +7 -5
- package/lib/ReactInputSelection.js +3 -4
- package/lib/ReactInstanceHandles.js +3 -2
- package/lib/ReactInstanceMap.js +47 -0
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +202 -66
- package/lib/ReactMultiChild.js +44 -45
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +47 -10
- package/lib/ReactOwner.js +4 -48
- package/lib/ReactPerf.js +21 -1
- package/lib/ReactPropTransferer.js +2 -57
- package/lib/ReactPropTypeLocationNames.js +1 -1
- package/lib/ReactPropTypeLocations.js +1 -1
- package/lib/ReactPropTypes.js +14 -22
- package/lib/ReactPutListenerQueue.js +1 -1
- package/lib/ReactReconcileTransaction.js +1 -1
- package/lib/ReactRef.js +96 -0
- package/lib/ReactRootIndex.js +1 -1
- package/lib/ReactServerRendering.js +5 -3
- package/lib/ReactServerRenderingTransaction.js +1 -1
- package/lib/ReactStateSetters.js +1 -1
- package/lib/ReactTestUtils.js +83 -26
- package/lib/ReactTransitionChildMapping.js +1 -1
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +48 -7
- package/lib/ReactUpdates.js +46 -45
- package/lib/ReactWithAddons.js +1 -1
- package/lib/SVGDOMPropertyConfig.js +1 -1
- package/lib/SelectEventPlugin.js +3 -3
- package/lib/ServerReactRootIndex.js +1 -1
- package/lib/SimpleEventPlugin.js +1 -1
- package/lib/SyntheticClipboardEvent.js +1 -2
- package/lib/SyntheticCompositionEvent.js +1 -2
- package/lib/SyntheticDragEvent.js +1 -1
- package/lib/SyntheticEvent.js +11 -3
- package/lib/SyntheticFocusEvent.js +1 -1
- package/lib/SyntheticInputEvent.js +1 -2
- package/lib/SyntheticKeyboardEvent.js +1 -1
- package/lib/SyntheticMouseEvent.js +2 -4
- package/lib/SyntheticTouchEvent.js +1 -1
- package/lib/SyntheticUIEvent.js +1 -1
- package/lib/SyntheticWheelEvent.js +1 -1
- package/lib/Transaction.js +3 -3
- package/lib/ViewportMetrics.js +2 -5
- package/lib/accumulate.js +47 -0
- package/lib/accumulateInto.js +1 -1
- package/lib/adler32.js +1 -1
- package/lib/cloneWithProps.js +3 -3
- package/lib/copyProperties.js +2 -0
- package/lib/createFullPageComponent.js +3 -3
- package/lib/dangerousStyleValue.js +1 -1
- package/lib/escapeTextForBrowser.js +6 -6
- package/lib/findDOMNode.js +51 -0
- package/lib/flattenChildren.js +11 -22
- package/lib/forEachAccumulated.js +1 -1
- package/lib/getEventCharCode.js +1 -1
- package/lib/getEventKey.js +1 -1
- package/lib/getEventModifierState.js +1 -1
- package/lib/getEventTarget.js +1 -1
- package/lib/getIteratorFn.js +42 -0
- package/lib/getNodeForCharacterOffset.js +2 -2
- package/lib/getReactRootElementInContainer.js +1 -1
- package/lib/getTextContentAccessor.js +1 -1
- package/lib/instantiateReactComponent.js +89 -66
- package/lib/isEventSupported.js +1 -1
- package/lib/isNode.js +3 -4
- package/lib/isTextInputElement.js +2 -3
- package/lib/joinClasses.js +1 -1
- package/lib/keyMirror.js +1 -1
- package/lib/memoizeStringOnly.js +4 -5
- package/lib/onlyChild.js +1 -1
- package/lib/setInnerHTML.js +12 -1
- package/lib/shallowEqual.js +1 -1
- package/lib/shouldUpdateReactComponent.js +48 -6
- package/lib/traverseAllChildren.js +111 -55
- package/lib/update.js +1 -1
- package/lib/warning.js +9 -2
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/ReactTextComponent.js +0 -104
- package/lib/deprecated.js +0 -47
package/lib/ReactComponent.js
CHANGED
|
@@ -9,52 +9,29 @@
|
|
|
9
9
|
* @providesModule ReactComponent
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var ReactElementValidator = require("./ReactElementValidator");
|
|
15
15
|
var ReactOwner = require("./ReactOwner");
|
|
16
|
-
var
|
|
16
|
+
var ReactRef = require("./ReactRef");
|
|
17
17
|
|
|
18
|
-
var assign = require("./Object.assign");
|
|
19
18
|
var invariant = require("./invariant");
|
|
20
|
-
var keyMirror = require("./keyMirror");
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*/
|
|
30
|
-
MOUNTED: null,
|
|
31
|
-
/**
|
|
32
|
-
* Unmounted components are inactive and cannot receive new props.
|
|
33
|
-
*/
|
|
34
|
-
UNMOUNTED: null
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
var injected = false;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Optionally injectable environment dependent cleanup hook. (server vs.
|
|
41
|
-
* browser etc). Example: A browser system caches DOM nodes based on component
|
|
42
|
-
* ID and must remove that cache entry when this instance is unmounted.
|
|
43
|
-
*
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
var unmountIDFromEnvironment = null;
|
|
20
|
+
function attachRef(ref, component, owner) {
|
|
21
|
+
if (ref instanceof ReactRef) {
|
|
22
|
+
ReactRef.attachRef(ref, component);
|
|
23
|
+
} else {
|
|
24
|
+
ReactOwner.addComponentAsRefTo(component, ref, owner);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
47
27
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @private
|
|
56
|
-
*/
|
|
57
|
-
var mountImageIntoNode = null;
|
|
28
|
+
function detachRef(ref, component, owner) {
|
|
29
|
+
if (ref instanceof ReactRef) {
|
|
30
|
+
ReactRef.detachRef(ref, component);
|
|
31
|
+
} else {
|
|
32
|
+
ReactOwner.removeComponentAsRefFrom(component, ref, owner);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
58
35
|
|
|
59
36
|
/**
|
|
60
37
|
* Components are the basic units of composition in React.
|
|
@@ -83,26 +60,6 @@ var mountImageIntoNode = null;
|
|
|
83
60
|
*/
|
|
84
61
|
var ReactComponent = {
|
|
85
62
|
|
|
86
|
-
injection: {
|
|
87
|
-
injectEnvironment: function(ReactComponentEnvironment) {
|
|
88
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
89
|
-
!injected,
|
|
90
|
-
'ReactComponent: injectEnvironment() can only be called once.'
|
|
91
|
-
) : invariant(!injected));
|
|
92
|
-
mountImageIntoNode = ReactComponentEnvironment.mountImageIntoNode;
|
|
93
|
-
unmountIDFromEnvironment =
|
|
94
|
-
ReactComponentEnvironment.unmountIDFromEnvironment;
|
|
95
|
-
ReactComponent.BackendIDOperations =
|
|
96
|
-
ReactComponentEnvironment.BackendIDOperations;
|
|
97
|
-
injected = true;
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
LifeCycle: ComponentLifeCycle,
|
|
105
|
-
|
|
106
63
|
/**
|
|
107
64
|
* Injected module that provides ability to mutate individual properties.
|
|
108
65
|
* Injected into the base class because many different subclasses need access
|
|
@@ -120,84 +77,6 @@ var ReactComponent = {
|
|
|
120
77
|
*/
|
|
121
78
|
Mixin: {
|
|
122
79
|
|
|
123
|
-
/**
|
|
124
|
-
* Checks whether or not this component is mounted.
|
|
125
|
-
*
|
|
126
|
-
* @return {boolean} True if mounted, false otherwise.
|
|
127
|
-
* @final
|
|
128
|
-
* @protected
|
|
129
|
-
*/
|
|
130
|
-
isMounted: function() {
|
|
131
|
-
return this._lifeCycleState === ComponentLifeCycle.MOUNTED;
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Sets a subset of the props.
|
|
136
|
-
*
|
|
137
|
-
* @param {object} partialProps Subset of the next props.
|
|
138
|
-
* @param {?function} callback Called after props are updated.
|
|
139
|
-
* @final
|
|
140
|
-
* @public
|
|
141
|
-
*/
|
|
142
|
-
setProps: function(partialProps, callback) {
|
|
143
|
-
// Merge with the pending element if it exists, otherwise with existing
|
|
144
|
-
// element props.
|
|
145
|
-
var element = this._pendingElement || this._currentElement;
|
|
146
|
-
this.replaceProps(
|
|
147
|
-
assign({}, element.props, partialProps),
|
|
148
|
-
callback
|
|
149
|
-
);
|
|
150
|
-
},
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Replaces all of the props.
|
|
154
|
-
*
|
|
155
|
-
* @param {object} props New props.
|
|
156
|
-
* @param {?function} callback Called after props are updated.
|
|
157
|
-
* @final
|
|
158
|
-
* @public
|
|
159
|
-
*/
|
|
160
|
-
replaceProps: function(props, callback) {
|
|
161
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
162
|
-
this.isMounted(),
|
|
163
|
-
'replaceProps(...): Can only update a mounted component.'
|
|
164
|
-
) : invariant(this.isMounted()));
|
|
165
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
166
|
-
this._mountDepth === 0,
|
|
167
|
-
'replaceProps(...): You called `setProps` or `replaceProps` on a ' +
|
|
168
|
-
'component with a parent. This is an anti-pattern since props will ' +
|
|
169
|
-
'get reactively updated when rendered. Instead, change the owner\'s ' +
|
|
170
|
-
'`render` method to pass the correct value as props to the component ' +
|
|
171
|
-
'where it is created.'
|
|
172
|
-
) : invariant(this._mountDepth === 0));
|
|
173
|
-
// This is a deoptimized path. We optimize for always having a element.
|
|
174
|
-
// This creates an extra internal element.
|
|
175
|
-
this._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
176
|
-
this._pendingElement || this._currentElement,
|
|
177
|
-
props
|
|
178
|
-
);
|
|
179
|
-
ReactUpdates.enqueueUpdate(this, callback);
|
|
180
|
-
},
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Schedule a partial update to the props. Only used for internal testing.
|
|
184
|
-
*
|
|
185
|
-
* @param {object} partialProps Subset of the next props.
|
|
186
|
-
* @param {?function} callback Called after props are updated.
|
|
187
|
-
* @final
|
|
188
|
-
* @internal
|
|
189
|
-
*/
|
|
190
|
-
_setPropsInternal: function(partialProps, callback) {
|
|
191
|
-
// This is a deoptimized path. We optimize for always having a element.
|
|
192
|
-
// This creates an extra internal element.
|
|
193
|
-
var element = this._pendingElement || this._currentElement;
|
|
194
|
-
this._pendingElement = ReactElement.cloneAndReplaceProps(
|
|
195
|
-
element,
|
|
196
|
-
assign({}, element.props, partialProps)
|
|
197
|
-
);
|
|
198
|
-
ReactUpdates.enqueueUpdate(this, callback);
|
|
199
|
-
},
|
|
200
|
-
|
|
201
80
|
/**
|
|
202
81
|
* Base constructor for all React components.
|
|
203
82
|
*
|
|
@@ -208,26 +87,14 @@ var ReactComponent = {
|
|
|
208
87
|
* @internal
|
|
209
88
|
*/
|
|
210
89
|
construct: function(element) {
|
|
211
|
-
// This is the public exposed props object after it has been processed
|
|
212
|
-
// with default props. The element's props represents the true internal
|
|
213
|
-
// state of the props.
|
|
214
|
-
this.props = element.props;
|
|
215
|
-
// Record the component responsible for creating this component.
|
|
216
|
-
// This is accessible through the element but we maintain an extra
|
|
217
|
-
// field for compatibility with devtools and as a way to make an
|
|
218
|
-
// incremental update. TODO: Consider deprecating this field.
|
|
219
|
-
this._owner = element._owner;
|
|
220
|
-
|
|
221
|
-
// All components start unmounted.
|
|
222
|
-
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
223
|
-
|
|
224
|
-
// See ReactUpdates.
|
|
225
|
-
this._pendingCallbacks = null;
|
|
226
|
-
|
|
227
90
|
// We keep the old element and a reference to the pending element
|
|
228
91
|
// to track updates.
|
|
229
92
|
this._currentElement = element;
|
|
230
|
-
|
|
93
|
+
// These two fields are used by the DOM and ART diffing algorithms
|
|
94
|
+
// respectively. Instead of using expandos on components, we should be
|
|
95
|
+
// storing the state needed by the diffing algorithms elsewhere.
|
|
96
|
+
this._mountIndex = 0;
|
|
97
|
+
this._mountImage = null;
|
|
231
98
|
},
|
|
232
99
|
|
|
233
100
|
/**
|
|
@@ -240,26 +107,19 @@ var ReactComponent = {
|
|
|
240
107
|
*
|
|
241
108
|
* @param {string} rootID DOM ID of the root node.
|
|
242
109
|
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
|
243
|
-
* @param {number} mountDepth number of components in the owner hierarchy.
|
|
244
110
|
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
245
111
|
* @internal
|
|
246
112
|
*/
|
|
247
|
-
mountComponent: function(rootID, transaction,
|
|
248
|
-
("production" !== process.env.NODE_ENV
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
'single component instance in multiple places.',
|
|
253
|
-
rootID
|
|
254
|
-
) : invariant(!this.isMounted()));
|
|
113
|
+
mountComponent: function(rootID, transaction, context) {
|
|
114
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
115
|
+
ReactElementValidator.checkAndWarnForMutatedProps(this._currentElement);
|
|
116
|
+
}
|
|
117
|
+
|
|
255
118
|
var ref = this._currentElement.ref;
|
|
256
119
|
if (ref != null) {
|
|
257
120
|
var owner = this._currentElement._owner;
|
|
258
|
-
|
|
121
|
+
attachRef(ref, this, owner);
|
|
259
122
|
}
|
|
260
|
-
this._rootNodeID = rootID;
|
|
261
|
-
this._lifeCycleState = ComponentLifeCycle.MOUNTED;
|
|
262
|
-
this._mountDepth = mountDepth;
|
|
263
123
|
// Effectively: return '';
|
|
264
124
|
},
|
|
265
125
|
|
|
@@ -274,56 +134,10 @@ var ReactComponent = {
|
|
|
274
134
|
* @internal
|
|
275
135
|
*/
|
|
276
136
|
unmountComponent: function() {
|
|
277
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
278
|
-
this.isMounted(),
|
|
279
|
-
'unmountComponent(): Can only unmount a mounted component.'
|
|
280
|
-
) : invariant(this.isMounted()));
|
|
281
137
|
var ref = this._currentElement.ref;
|
|
282
138
|
if (ref != null) {
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
unmountIDFromEnvironment(this._rootNodeID);
|
|
286
|
-
this._rootNodeID = null;
|
|
287
|
-
this._lifeCycleState = ComponentLifeCycle.UNMOUNTED;
|
|
288
|
-
},
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Given a new instance of this component, updates the rendered DOM nodes
|
|
292
|
-
* as if that instance was rendered instead.
|
|
293
|
-
*
|
|
294
|
-
* Subclasses that override this method should make sure to invoke
|
|
295
|
-
* `ReactComponent.Mixin.receiveComponent.call(this, ...)`.
|
|
296
|
-
*
|
|
297
|
-
* @param {object} nextComponent Next set of properties.
|
|
298
|
-
* @param {ReactReconcileTransaction} transaction
|
|
299
|
-
* @internal
|
|
300
|
-
*/
|
|
301
|
-
receiveComponent: function(nextElement, transaction) {
|
|
302
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
303
|
-
this.isMounted(),
|
|
304
|
-
'receiveComponent(...): Can only update a mounted component.'
|
|
305
|
-
) : invariant(this.isMounted()));
|
|
306
|
-
this._pendingElement = nextElement;
|
|
307
|
-
this.performUpdateIfNecessary(transaction);
|
|
308
|
-
},
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* If `_pendingElement` is set, update the component.
|
|
312
|
-
*
|
|
313
|
-
* @param {ReactReconcileTransaction} transaction
|
|
314
|
-
* @internal
|
|
315
|
-
*/
|
|
316
|
-
performUpdateIfNecessary: function(transaction) {
|
|
317
|
-
if (this._pendingElement == null) {
|
|
318
|
-
return;
|
|
139
|
+
detachRef(ref, this, this._currentElement._owner);
|
|
319
140
|
}
|
|
320
|
-
var prevElement = this._currentElement;
|
|
321
|
-
var nextElement = this._pendingElement;
|
|
322
|
-
this._currentElement = nextElement;
|
|
323
|
-
this.props = nextElement.props;
|
|
324
|
-
this._owner = nextElement._owner;
|
|
325
|
-
this._pendingElement = null;
|
|
326
|
-
this.updateComponent(transaction, prevElement);
|
|
327
141
|
},
|
|
328
142
|
|
|
329
143
|
/**
|
|
@@ -331,10 +145,13 @@ var ReactComponent = {
|
|
|
331
145
|
*
|
|
332
146
|
* @param {ReactReconcileTransaction} transaction
|
|
333
147
|
* @param {object} prevElement
|
|
148
|
+
* @param {object} nextElement
|
|
334
149
|
* @internal
|
|
335
150
|
*/
|
|
336
|
-
updateComponent: function(transaction, prevElement) {
|
|
337
|
-
|
|
151
|
+
updateComponent: function(transaction, prevElement, nextElement, context) {
|
|
152
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
153
|
+
ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
|
|
154
|
+
}
|
|
338
155
|
|
|
339
156
|
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
340
157
|
// has stored a reference to `this`, and the previous owner (if different)
|
|
@@ -351,87 +168,29 @@ var ReactComponent = {
|
|
|
351
168
|
if (nextElement._owner !== prevElement._owner ||
|
|
352
169
|
nextElement.ref !== prevElement.ref) {
|
|
353
170
|
if (prevElement.ref != null) {
|
|
354
|
-
|
|
355
|
-
this, prevElement.ref, prevElement._owner
|
|
356
|
-
);
|
|
171
|
+
detachRef(prevElement.ref, this, prevElement._owner);
|
|
357
172
|
}
|
|
358
173
|
// Correct, even if the owner is the same, and only the ref has changed.
|
|
359
174
|
if (nextElement.ref != null) {
|
|
360
|
-
|
|
361
|
-
this,
|
|
362
|
-
nextElement.ref,
|
|
363
|
-
nextElement._owner
|
|
364
|
-
);
|
|
175
|
+
attachRef(nextElement.ref, this, nextElement._owner);
|
|
365
176
|
}
|
|
366
177
|
}
|
|
367
178
|
},
|
|
368
179
|
|
|
369
180
|
/**
|
|
370
|
-
*
|
|
181
|
+
* Get the publicly accessible representation of this component - i.e. what
|
|
182
|
+
* is exposed by refs and returned by React.render. Can be null for
|
|
183
|
+
* stateless components.
|
|
371
184
|
*
|
|
372
|
-
* @param {string} rootID DOM ID of the root node.
|
|
373
|
-
* @param {DOMElement} container DOM element to mount into.
|
|
374
|
-
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
375
|
-
* @final
|
|
376
|
-
* @internal
|
|
377
|
-
* @see {ReactMount.render}
|
|
378
|
-
*/
|
|
379
|
-
mountComponentIntoNode: function(rootID, container, shouldReuseMarkup) {
|
|
380
|
-
var transaction = ReactUpdates.ReactReconcileTransaction.getPooled();
|
|
381
|
-
transaction.perform(
|
|
382
|
-
this._mountComponentIntoNode,
|
|
383
|
-
this,
|
|
384
|
-
rootID,
|
|
385
|
-
container,
|
|
386
|
-
transaction,
|
|
387
|
-
shouldReuseMarkup
|
|
388
|
-
);
|
|
389
|
-
ReactUpdates.ReactReconcileTransaction.release(transaction);
|
|
390
|
-
},
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* @param {string} rootID DOM ID of the root node.
|
|
394
|
-
* @param {DOMElement} container DOM element to mount into.
|
|
395
|
-
* @param {ReactReconcileTransaction} transaction
|
|
396
|
-
* @param {boolean} shouldReuseMarkup If true, do not insert markup
|
|
397
|
-
* @final
|
|
398
|
-
* @private
|
|
399
|
-
*/
|
|
400
|
-
_mountComponentIntoNode: function(
|
|
401
|
-
rootID,
|
|
402
|
-
container,
|
|
403
|
-
transaction,
|
|
404
|
-
shouldReuseMarkup) {
|
|
405
|
-
var markup = this.mountComponent(rootID, transaction, 0);
|
|
406
|
-
mountImageIntoNode(markup, container, shouldReuseMarkup);
|
|
407
|
-
},
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Checks if this component is owned by the supplied `owner` component.
|
|
411
|
-
*
|
|
412
|
-
* @param {ReactComponent} owner Component to check.
|
|
413
|
-
* @return {boolean} True if `owners` owns this component.
|
|
414
|
-
* @final
|
|
415
|
-
* @internal
|
|
416
|
-
*/
|
|
417
|
-
isOwnedBy: function(owner) {
|
|
418
|
-
return this._owner === owner;
|
|
419
|
-
},
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* Gets another component, that shares the same owner as this one, by ref.
|
|
423
|
-
*
|
|
424
|
-
* @param {string} ref of a sibling Component.
|
|
425
185
|
* @return {?ReactComponent} the actual sibling Component.
|
|
426
|
-
* @final
|
|
427
186
|
* @internal
|
|
428
187
|
*/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
188
|
+
getPublicInstance: function() {
|
|
189
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
190
|
+
false,
|
|
191
|
+
'getPublicInstance should never be called on the base class. It must ' +
|
|
192
|
+
'be overridden.'
|
|
193
|
+
) : invariant(false));
|
|
435
194
|
}
|
|
436
195
|
}
|
|
437
196
|
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2013-2014, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
8
|
+
*
|
|
9
|
+
* @providesModule ReactComponentBase
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var ReactInstanceMap = require("./ReactInstanceMap");
|
|
15
|
+
|
|
16
|
+
var invariant = require("./invariant");
|
|
17
|
+
var warning = require("./warning");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Base class helpers for the updating state of a component.
|
|
21
|
+
*/
|
|
22
|
+
function ReactComponentBase(props) {
|
|
23
|
+
this.props = props;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sets a subset of the state. Always use this to mutate
|
|
28
|
+
* state. You should treat `this.state` as immutable.
|
|
29
|
+
*
|
|
30
|
+
* There is no guarantee that `this.state` will be immediately updated, so
|
|
31
|
+
* accessing `this.state` after calling this method may return the old value.
|
|
32
|
+
*
|
|
33
|
+
* There is no guarantee that calls to `setState` will run synchronously,
|
|
34
|
+
* as they may eventually be batched together. You can provide an optional
|
|
35
|
+
* callback that will be executed when the call to setState is actually
|
|
36
|
+
* completed.
|
|
37
|
+
*
|
|
38
|
+
* @param {object} partialState Next partial state to be merged with state.
|
|
39
|
+
* @param {?function} callback Called after state is updated.
|
|
40
|
+
* @final
|
|
41
|
+
* @protected
|
|
42
|
+
*/
|
|
43
|
+
ReactComponentBase.prototype.setState = function(partialState, callback) {
|
|
44
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
45
|
+
typeof partialState === 'object' || partialState == null,
|
|
46
|
+
'setState(...): takes an object of state variables to update.'
|
|
47
|
+
) : invariant(typeof partialState === 'object' || partialState == null));
|
|
48
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
49
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
50
|
+
partialState != null,
|
|
51
|
+
'setState(...): You passed an undefined or null state object; ' +
|
|
52
|
+
'instead, use forceUpdate().'
|
|
53
|
+
) : null);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
var internalInstance = ReactInstanceMap.get(this);
|
|
57
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
58
|
+
internalInstance,
|
|
59
|
+
'setState(...): Can only update a mounted or mounting component. ' +
|
|
60
|
+
'This usually means you called setState() on an unmounted ' +
|
|
61
|
+
'component.'
|
|
62
|
+
) : invariant(internalInstance));
|
|
63
|
+
internalInstance.setState(
|
|
64
|
+
partialState, callback
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Forces an update. This should only be invoked when it is known with
|
|
70
|
+
* certainty that we are **not** in a DOM transaction.
|
|
71
|
+
*
|
|
72
|
+
* You may want to call this when you know that some deeper aspect of the
|
|
73
|
+
* component's state has changed but `setState` was not called.
|
|
74
|
+
*
|
|
75
|
+
* This will not invoke `shouldUpdateComponent`, but it will invoke
|
|
76
|
+
* `componentWillUpdate` and `componentDidUpdate`.
|
|
77
|
+
*
|
|
78
|
+
* @param {?function} callback Called after update is complete.
|
|
79
|
+
* @final
|
|
80
|
+
* @protected
|
|
81
|
+
*/
|
|
82
|
+
ReactComponentBase.prototype.forceUpdate = function(callback) {
|
|
83
|
+
var internalInstance = ReactInstanceMap.get(this);
|
|
84
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
85
|
+
internalInstance,
|
|
86
|
+
'forceUpdate(...): Can only force an update on mounted or mounting ' +
|
|
87
|
+
'components. This usually means you called forceUpdate() on an ' +
|
|
88
|
+
'unmounted component.'
|
|
89
|
+
) : invariant(internalInstance));
|
|
90
|
+
internalInstance.forceUpdate(callback);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Deprecated APIs. These APIs used to exist on classic React classes but since
|
|
95
|
+
* we would like to deprecate them, we're not going to move them over to this
|
|
96
|
+
* modern base class. Instead, we define a getter that warns if it's accessed.
|
|
97
|
+
*/
|
|
98
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
99
|
+
if (Object.defineProperty) {
|
|
100
|
+
var deprecatedAPIs = {
|
|
101
|
+
getDOMNode: 'getDOMNode',
|
|
102
|
+
isMounted: 'isMounted',
|
|
103
|
+
replaceState: 'replaceState',
|
|
104
|
+
setProps: 'setProps'
|
|
105
|
+
};
|
|
106
|
+
var defineDeprecationWarning = function(methodName, displayName) {
|
|
107
|
+
Object.defineProperty(ReactComponentBase.prototype, methodName, {
|
|
108
|
+
get: function() {
|
|
109
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
110
|
+
false,
|
|
111
|
+
'%s(...) is deprecated in plain JavaScript React classes.',
|
|
112
|
+
displayName
|
|
113
|
+
) : null);
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
for (var methodName in deprecatedAPIs) {
|
|
119
|
+
if (deprecatedAPIs.hasOwnProperty(methodName)) {
|
|
120
|
+
defineDeprecationWarning(methodName, deprecatedAPIs[methodName]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = ReactComponentBase;
|