react 0.12.1 → 0.13.0-beta.1
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 +352 -251
- package/dist/react-with-addons.js +5409 -4242
- package/dist/react-with-addons.min.js +5 -6
- package/dist/react.js +5012 -4136
- 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 +57 -10
- 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 +4 -2
- 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 +9 -2
- package/lib/MobileSafariClickEventPlugin.js +1 -1
- package/lib/Object.assign.js +3 -1
- package/lib/PooledClass.js +1 -1
- package/lib/React.js +17 -51
- 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 +125 -0
- package/lib/ReactChildren.js +10 -8
- package/lib/ReactClass.js +916 -0
- package/lib/ReactComponent.js +81 -404
- package/lib/ReactComponentBrowserEnvironment.js +10 -83
- package/lib/ReactComponentEnvironment.js +57 -0
- package/lib/ReactComponentWithPureRenderMixin.js +1 -1
- package/lib/ReactCompositeComponent.js +533 -1132
- 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 +110 -92
- 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/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -35
- package/lib/ReactDOMTextarea.js +5 -6
- package/lib/ReactDefaultBatchingStrategy.js +4 -4
- package/lib/ReactDefaultInjection.js +14 -8
- package/lib/ReactDefaultPerf.js +16 -7
- package/lib/ReactDefaultPerfAnalysis.js +1 -1
- package/lib/ReactElement.js +23 -15
- package/lib/ReactElementValidator.js +209 -57
- package/lib/ReactEmptyComponent.js +29 -11
- package/lib/ReactEventEmitterMixin.js +1 -1
- package/lib/ReactEventListener.js +3 -4
- 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/ReactLifeCycle.js +35 -0
- package/lib/ReactLink.js +1 -1
- package/lib/ReactMarkupChecksum.js +1 -1
- package/lib/ReactMount.js +239 -68
- package/lib/ReactMultiChild.js +49 -47
- package/lib/ReactMultiChildUpdateTypes.js +1 -1
- package/lib/ReactNativeComponent.js +72 -25
- 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/ReactReconciler.js +107 -0
- package/lib/ReactRef.js +70 -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 +112 -26
- package/lib/ReactTransitionChildMapping.js +1 -1
- package/lib/ReactTransitionEvents.js +1 -1
- package/lib/ReactTransitionGroup.js +48 -7
- package/lib/ReactUpdateQueue.js +264 -0
- package/lib/ReactUpdates.js +48 -61
- 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/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 +85 -67
- 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 +12 -1
- package/package.json +1 -1
- package/lib/CompositionEventPlugin.js +0 -257
- package/lib/ReactLegacyElement.js +0 -243
- package/lib/deprecated.js +0 -47
package/lib/ReactComponent.js
CHANGED
|
@@ -9,431 +9,108 @@
|
|
|
9
9
|
* @providesModule ReactComponent
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
'use strict';
|
|
13
13
|
|
|
14
|
-
var
|
|
15
|
-
var ReactOwner = require("./ReactOwner");
|
|
16
|
-
var ReactUpdates = require("./ReactUpdates");
|
|
14
|
+
var ReactUpdateQueue = require("./ReactUpdateQueue");
|
|
17
15
|
|
|
18
|
-
var assign = require("./Object.assign");
|
|
19
16
|
var invariant = require("./invariant");
|
|
20
|
-
var
|
|
17
|
+
var warning = require("./warning");
|
|
21
18
|
|
|
22
19
|
/**
|
|
23
|
-
*
|
|
20
|
+
* Base class helpers for the updating state of a component.
|
|
24
21
|
*/
|
|
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;
|
|
22
|
+
function ReactComponent(props, context) {
|
|
23
|
+
this.props = props;
|
|
24
|
+
this.context = context;
|
|
25
|
+
}
|
|
38
26
|
|
|
39
27
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* ID and must remove that cache entry when this instance is unmounted.
|
|
28
|
+
* Sets a subset of the state. Always use this to mutate
|
|
29
|
+
* state. You should treat `this.state` as immutable.
|
|
43
30
|
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* On the web, this "image" is HTML markup which describes a construction of
|
|
52
|
-
* low level `div` and `span` nodes. Other platforms may have different
|
|
53
|
-
* encoding of this "image". This must be injected.
|
|
31
|
+
* There is no guarantee that `this.state` will be immediately updated, so
|
|
32
|
+
* accessing `this.state` after calling this method may return the old value.
|
|
33
|
+
*
|
|
34
|
+
* There is no guarantee that calls to `setState` will run synchronously,
|
|
35
|
+
* as they may eventually be batched together. You can provide an optional
|
|
36
|
+
* callback that will be executed when the call to setState is actually
|
|
37
|
+
* completed.
|
|
54
38
|
*
|
|
55
|
-
* @
|
|
39
|
+
* @param {object} partialState Next partial state to be merged with state.
|
|
40
|
+
* @param {?function} callback Called after state is updated.
|
|
41
|
+
* @final
|
|
42
|
+
* @protected
|
|
56
43
|
*/
|
|
57
|
-
|
|
44
|
+
ReactComponent.prototype.setState = function(partialState, callback) {
|
|
45
|
+
("production" !== process.env.NODE_ENV ? invariant(
|
|
46
|
+
typeof partialState === 'object' || partialState == null,
|
|
47
|
+
'setState(...): takes an object of state variables to update.'
|
|
48
|
+
) : invariant(typeof partialState === 'object' || partialState == null));
|
|
49
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
50
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
51
|
+
partialState != null,
|
|
52
|
+
'setState(...): You passed an undefined or null state object; ' +
|
|
53
|
+
'instead, use forceUpdate().'
|
|
54
|
+
) : null);
|
|
55
|
+
}
|
|
56
|
+
ReactUpdateQueue.enqueueSetState(this, partialState);
|
|
57
|
+
if (callback) {
|
|
58
|
+
ReactUpdateQueue.enqueueCallback(this, callback);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* Every component accepts a set of keyed input parameters known as "props" that
|
|
63
|
-
* are initialized by the constructor. Once a component is mounted, the props
|
|
64
|
-
* can be mutated using `setProps` or `replaceProps`.
|
|
65
|
-
*
|
|
66
|
-
* Every component is capable of the following operations:
|
|
67
|
-
*
|
|
68
|
-
* `mountComponent`
|
|
69
|
-
* Initializes the component, renders markup, and registers event listeners.
|
|
70
|
-
*
|
|
71
|
-
* `receiveComponent`
|
|
72
|
-
* Updates the rendered DOM nodes to match the given component.
|
|
63
|
+
* Forces an update. This should only be invoked when it is known with
|
|
64
|
+
* certainty that we are **not** in a DOM transaction.
|
|
73
65
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
66
|
+
* You may want to call this when you know that some deeper aspect of the
|
|
67
|
+
* component's state has changed but `setState` was not called.
|
|
76
68
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* being the child of a component, which means having a DOM representation that
|
|
80
|
-
* is a child of the DOM representation of that component.
|
|
69
|
+
* This will not invoke `shouldUpdateComponent`, but it will invoke
|
|
70
|
+
* `componentWillUpdate` and `componentDidUpdate`.
|
|
81
71
|
*
|
|
82
|
-
* @
|
|
72
|
+
* @param {?function} callback Called after update is complete.
|
|
73
|
+
* @final
|
|
74
|
+
* @protected
|
|
83
75
|
*/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
/**
|
|
107
|
-
* Injected module that provides ability to mutate individual properties.
|
|
108
|
-
* Injected into the base class because many different subclasses need access
|
|
109
|
-
* to this.
|
|
110
|
-
*
|
|
111
|
-
* @internal
|
|
112
|
-
*/
|
|
113
|
-
BackendIDOperations: null,
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Base functionality for every ReactComponent constructor. Mixed into the
|
|
117
|
-
* `ReactComponent` prototype, but exposed statically for easy access.
|
|
118
|
-
*
|
|
119
|
-
* @lends {ReactComponent.prototype}
|
|
120
|
-
*/
|
|
121
|
-
Mixin: {
|
|
122
|
-
|
|
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
|
-
/**
|
|
202
|
-
* Base constructor for all React components.
|
|
203
|
-
*
|
|
204
|
-
* Subclasses that override this method should make sure to invoke
|
|
205
|
-
* `ReactComponent.Mixin.construct.call(this, ...)`.
|
|
206
|
-
*
|
|
207
|
-
* @param {ReactElement} element
|
|
208
|
-
* @internal
|
|
209
|
-
*/
|
|
210
|
-
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
|
-
// We keep the old element and a reference to the pending element
|
|
228
|
-
// to track updates.
|
|
229
|
-
this._currentElement = element;
|
|
230
|
-
this._pendingElement = null;
|
|
231
|
-
},
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Initializes the component, renders markup, and registers event listeners.
|
|
235
|
-
*
|
|
236
|
-
* NOTE: This does not insert any nodes into the DOM.
|
|
237
|
-
*
|
|
238
|
-
* Subclasses that override this method should make sure to invoke
|
|
239
|
-
* `ReactComponent.Mixin.mountComponent.call(this, ...)`.
|
|
240
|
-
*
|
|
241
|
-
* @param {string} rootID DOM ID of the root node.
|
|
242
|
-
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
|
|
243
|
-
* @param {number} mountDepth number of components in the owner hierarchy.
|
|
244
|
-
* @return {?string} Rendered markup to be inserted into the DOM.
|
|
245
|
-
* @internal
|
|
246
|
-
*/
|
|
247
|
-
mountComponent: function(rootID, transaction, mountDepth) {
|
|
248
|
-
("production" !== process.env.NODE_ENV ? invariant(
|
|
249
|
-
!this.isMounted(),
|
|
250
|
-
'mountComponent(%s, ...): Can only mount an unmounted component. ' +
|
|
251
|
-
'Make sure to avoid storing components between renders or reusing a ' +
|
|
252
|
-
'single component instance in multiple places.',
|
|
253
|
-
rootID
|
|
254
|
-
) : invariant(!this.isMounted()));
|
|
255
|
-
var ref = this._currentElement.ref;
|
|
256
|
-
if (ref != null) {
|
|
257
|
-
var owner = this._currentElement._owner;
|
|
258
|
-
ReactOwner.addComponentAsRefTo(this, ref, owner);
|
|
259
|
-
}
|
|
260
|
-
this._rootNodeID = rootID;
|
|
261
|
-
this._lifeCycleState = ComponentLifeCycle.MOUNTED;
|
|
262
|
-
this._mountDepth = mountDepth;
|
|
263
|
-
// Effectively: return '';
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Releases any resources allocated by `mountComponent`.
|
|
268
|
-
*
|
|
269
|
-
* NOTE: This does not remove any nodes from the DOM.
|
|
270
|
-
*
|
|
271
|
-
* Subclasses that override this method should make sure to invoke
|
|
272
|
-
* `ReactComponent.Mixin.unmountComponent.call(this)`.
|
|
273
|
-
*
|
|
274
|
-
* @internal
|
|
275
|
-
*/
|
|
276
|
-
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
|
-
var ref = this._currentElement.ref;
|
|
282
|
-
if (ref != null) {
|
|
283
|
-
ReactOwner.removeComponentAsRefFrom(this, ref, this._owner);
|
|
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;
|
|
319
|
-
}
|
|
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
|
-
},
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Updates the component's currently mounted representation.
|
|
331
|
-
*
|
|
332
|
-
* @param {ReactReconcileTransaction} transaction
|
|
333
|
-
* @param {object} prevElement
|
|
334
|
-
* @internal
|
|
335
|
-
*/
|
|
336
|
-
updateComponent: function(transaction, prevElement) {
|
|
337
|
-
var nextElement = this._currentElement;
|
|
338
|
-
|
|
339
|
-
// If either the owner or a `ref` has changed, make sure the newest owner
|
|
340
|
-
// has stored a reference to `this`, and the previous owner (if different)
|
|
341
|
-
// has forgotten the reference to `this`. We use the element instead
|
|
342
|
-
// of the public this.props because the post processing cannot determine
|
|
343
|
-
// a ref. The ref conceptually lives on the element.
|
|
344
|
-
|
|
345
|
-
// TODO: Should this even be possible? The owner cannot change because
|
|
346
|
-
// it's forbidden by shouldUpdateReactComponent. The ref can change
|
|
347
|
-
// if you swap the keys of but not the refs. Reconsider where this check
|
|
348
|
-
// is made. It probably belongs where the key checking and
|
|
349
|
-
// instantiateReactComponent is done.
|
|
76
|
+
ReactComponent.prototype.forceUpdate = function(callback) {
|
|
77
|
+
ReactUpdateQueue.enqueueForceUpdate(this);
|
|
78
|
+
if (callback) {
|
|
79
|
+
ReactUpdateQueue.enqueueCallback(this, callback);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
350
82
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Deprecated APIs. These APIs used to exist on classic React classes but since
|
|
85
|
+
* we would like to deprecate them, we're not going to move them over to this
|
|
86
|
+
* modern base class. Instead, we define a getter that warns if it's accessed.
|
|
87
|
+
*/
|
|
88
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
89
|
+
if (Object.defineProperty) {
|
|
90
|
+
var deprecatedAPIs = {
|
|
91
|
+
getDOMNode: 'getDOMNode',
|
|
92
|
+
isMounted: 'isMounted',
|
|
93
|
+
replaceState: 'replaceState',
|
|
94
|
+
setProps: 'setProps'
|
|
95
|
+
};
|
|
96
|
+
var defineDeprecationWarning = function(methodName, displayName) {
|
|
97
|
+
Object.defineProperty(ReactComponent.prototype, methodName, {
|
|
98
|
+
get: function() {
|
|
99
|
+
("production" !== process.env.NODE_ENV ? warning(
|
|
100
|
+
false,
|
|
101
|
+
'%s(...) is deprecated in plain JavaScript React classes.',
|
|
102
|
+
displayName
|
|
103
|
+
) : null);
|
|
104
|
+
return undefined;
|
|
365
105
|
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
for (var methodName in deprecatedAPIs) {
|
|
109
|
+
if (deprecatedAPIs.hasOwnProperty(methodName)) {
|
|
110
|
+
defineDeprecationWarning(methodName, deprecatedAPIs[methodName]);
|
|
366
111
|
}
|
|
367
|
-
},
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Mounts this component and inserts it into the DOM.
|
|
371
|
-
*
|
|
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
|
-
* @return {?ReactComponent} the actual sibling Component.
|
|
426
|
-
* @final
|
|
427
|
-
* @internal
|
|
428
|
-
*/
|
|
429
|
-
getSiblingByRef: function(ref) {
|
|
430
|
-
var owner = this._owner;
|
|
431
|
-
if (!owner || !owner.refs) {
|
|
432
|
-
return null;
|
|
433
|
-
}
|
|
434
|
-
return owner.refs[ref];
|
|
435
112
|
}
|
|
436
113
|
}
|
|
437
|
-
}
|
|
114
|
+
}
|
|
438
115
|
|
|
439
116
|
module.exports = ReactComponent;
|