react 0.12.2 → 0.13.0-beta.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.
Files changed (184) hide show
  1. package/dist/JSXTransformer.js +986 -511
  2. package/dist/react-with-addons.js +6076 -4560
  3. package/dist/react-with-addons.min.js +6 -7
  4. package/dist/react.js +5386 -4170
  5. package/dist/react.min.js +6 -7
  6. package/lib/AutoFocusMixin.js +2 -2
  7. package/lib/BeforeInputEventPlugin.js +388 -115
  8. package/lib/CSSCore.js +1 -1
  9. package/lib/CSSProperty.js +2 -2
  10. package/lib/CSSPropertyOperations.js +58 -11
  11. package/lib/CallbackQueue.js +3 -3
  12. package/lib/ChangeEventPlugin.js +4 -4
  13. package/lib/ClientReactRootIndex.js +2 -2
  14. package/lib/DOMChildrenOperations.js +10 -47
  15. package/lib/DOMProperty.js +2 -2
  16. package/lib/DOMPropertyOperations.js +11 -16
  17. package/lib/Danger.js +8 -7
  18. package/lib/DefaultEventPluginOrder.js +3 -4
  19. package/lib/EnterLeaveEventPlugin.js +2 -2
  20. package/lib/EventConstants.js +2 -2
  21. package/lib/EventListener.js +1 -1
  22. package/lib/EventPluginHub.js +10 -8
  23. package/lib/EventPluginRegistry.js +2 -2
  24. package/lib/EventPluginUtils.js +4 -4
  25. package/lib/EventPropagators.js +2 -2
  26. package/lib/ExecutionEnvironment.js +3 -4
  27. package/lib/FallbackCompositionState.js +89 -0
  28. package/lib/HTMLDOMPropertyConfig.js +23 -10
  29. package/lib/LinkedStateMixin.js +2 -2
  30. package/lib/LinkedValueUtils.js +4 -4
  31. package/lib/LocalEventTrapMixin.js +10 -3
  32. package/lib/MobileSafariClickEventPlugin.js +2 -2
  33. package/lib/Object.assign.js +4 -2
  34. package/lib/PooledClass.js +2 -2
  35. package/lib/React.js +19 -58
  36. package/lib/ReactBrowserComponentMixin.js +4 -14
  37. package/lib/ReactBrowserEventEmitter.js +6 -8
  38. package/lib/ReactCSSTransitionGroup.js +5 -2
  39. package/lib/ReactCSSTransitionGroupChild.js +20 -7
  40. package/lib/ReactChildReconciler.js +125 -0
  41. package/lib/ReactChildren.js +13 -10
  42. package/lib/ReactClass.js +918 -0
  43. package/lib/ReactComponent.js +98 -406
  44. package/lib/ReactComponentBrowserEnvironment.js +11 -84
  45. package/lib/ReactComponentEnvironment.js +57 -0
  46. package/lib/ReactComponentWithPureRenderMixin.js +2 -2
  47. package/lib/ReactCompositeComponent.js +574 -1140
  48. package/lib/ReactContext.js +17 -3
  49. package/lib/ReactCurrentOwner.js +2 -2
  50. package/lib/ReactDOM.js +4 -9
  51. package/lib/ReactDOMButton.js +6 -7
  52. package/lib/ReactDOMComponent.js +123 -105
  53. package/lib/ReactDOMForm.js +6 -7
  54. package/lib/ReactDOMIDOperations.js +59 -77
  55. package/lib/ReactDOMIframe.js +43 -0
  56. package/lib/ReactDOMImg.js +5 -7
  57. package/lib/ReactDOMInput.js +6 -7
  58. package/lib/ReactDOMOption.js +6 -7
  59. package/lib/ReactDOMSelect.js +58 -66
  60. package/lib/ReactDOMSelection.js +7 -3
  61. package/lib/{ReactTextComponent.js → ReactDOMTextComponent.js} +48 -37
  62. package/lib/ReactDOMTextarea.js +6 -7
  63. package/lib/ReactDefaultBatchingStrategy.js +5 -5
  64. package/lib/ReactDefaultInjection.js +39 -9
  65. package/lib/ReactDefaultPerf.js +17 -8
  66. package/lib/ReactDefaultPerfAnalysis.js +2 -2
  67. package/lib/ReactElement.js +23 -15
  68. package/lib/ReactElementValidator.js +206 -89
  69. package/lib/ReactEmptyComponent.js +33 -15
  70. package/lib/ReactErrorUtils.js +1 -1
  71. package/lib/ReactEventEmitterMixin.js +2 -2
  72. package/lib/ReactEventListener.js +4 -5
  73. package/lib/ReactFragment.js +172 -0
  74. package/lib/ReactInjection.js +8 -6
  75. package/lib/ReactInputSelection.js +4 -5
  76. package/lib/ReactInstanceHandles.js +4 -3
  77. package/lib/ReactInstanceMap.js +47 -0
  78. package/lib/ReactLifeCycle.js +35 -0
  79. package/lib/ReactLink.js +2 -2
  80. package/lib/ReactMarkupChecksum.js +2 -2
  81. package/lib/ReactMount.js +264 -71
  82. package/lib/ReactMultiChild.js +50 -48
  83. package/lib/ReactMultiChildUpdateTypes.js +2 -2
  84. package/lib/ReactNativeComponent.js +59 -25
  85. package/lib/ReactOwner.js +5 -49
  86. package/lib/ReactPerf.js +22 -2
  87. package/lib/ReactPropTransferer.js +3 -58
  88. package/lib/ReactPropTypeLocationNames.js +2 -2
  89. package/lib/ReactPropTypeLocations.js +2 -2
  90. package/lib/ReactPropTypes.js +17 -25
  91. package/lib/ReactPutListenerQueue.js +2 -2
  92. package/lib/ReactReconcileTransaction.js +2 -2
  93. package/lib/ReactReconciler.js +121 -0
  94. package/lib/ReactRef.js +69 -0
  95. package/lib/ReactRootIndex.js +2 -2
  96. package/lib/ReactServerRendering.js +6 -4
  97. package/lib/ReactServerRenderingTransaction.js +2 -2
  98. package/lib/ReactStateSetters.js +2 -2
  99. package/lib/ReactTestUtils.js +113 -27
  100. package/lib/ReactTransitionChildMapping.js +8 -4
  101. package/lib/ReactTransitionEvents.js +2 -2
  102. package/lib/ReactTransitionGroup.js +53 -12
  103. package/lib/ReactUpdateQueue.js +295 -0
  104. package/lib/ReactUpdates.js +54 -62
  105. package/lib/ReactWithAddons.js +4 -2
  106. package/lib/SVGDOMPropertyConfig.js +2 -2
  107. package/lib/SelectEventPlugin.js +4 -4
  108. package/lib/ServerReactRootIndex.js +2 -2
  109. package/lib/SimpleEventPlugin.js +4 -4
  110. package/lib/SyntheticClipboardEvent.js +2 -3
  111. package/lib/SyntheticCompositionEvent.js +2 -3
  112. package/lib/SyntheticDragEvent.js +2 -2
  113. package/lib/SyntheticEvent.js +12 -4
  114. package/lib/SyntheticFocusEvent.js +2 -2
  115. package/lib/SyntheticInputEvent.js +2 -3
  116. package/lib/SyntheticKeyboardEvent.js +2 -2
  117. package/lib/SyntheticMouseEvent.js +3 -5
  118. package/lib/SyntheticTouchEvent.js +2 -2
  119. package/lib/SyntheticUIEvent.js +2 -2
  120. package/lib/SyntheticWheelEvent.js +2 -2
  121. package/lib/Transaction.js +4 -4
  122. package/lib/ViewportMetrics.js +3 -6
  123. package/lib/accumulateInto.js +2 -2
  124. package/lib/adler32.js +2 -2
  125. package/lib/camelize.js +1 -1
  126. package/lib/camelizeStyleName.js +1 -1
  127. package/lib/cloneWithProps.js +4 -4
  128. package/lib/containsNode.js +1 -1
  129. package/lib/{createArrayFrom.js → createArrayFromMixed.js} +6 -6
  130. package/lib/createFullPageComponent.js +4 -4
  131. package/lib/createNodesFromMarkup.js +4 -4
  132. package/lib/cx.js +1 -1
  133. package/lib/dangerousStyleValue.js +2 -2
  134. package/lib/emptyFunction.js +1 -1
  135. package/lib/emptyObject.js +1 -1
  136. package/lib/{escapeTextForBrowser.js → escapeTextContentForBrowser.js} +10 -11
  137. package/lib/findDOMNode.js +51 -0
  138. package/lib/flattenChildren.js +12 -23
  139. package/lib/focusNode.js +1 -1
  140. package/lib/forEachAccumulated.js +2 -2
  141. package/lib/getActiveElement.js +1 -1
  142. package/lib/getEventCharCode.js +2 -2
  143. package/lib/getEventKey.js +2 -2
  144. package/lib/getEventModifierState.js +2 -2
  145. package/lib/getEventTarget.js +2 -2
  146. package/lib/getIteratorFn.js +42 -0
  147. package/lib/getMarkupWrap.js +1 -1
  148. package/lib/getNodeForCharacterOffset.js +3 -3
  149. package/lib/getReactRootElementInContainer.js +2 -2
  150. package/lib/getTextContentAccessor.js +2 -2
  151. package/lib/getUnboundedScrollPosition.js +1 -1
  152. package/lib/hyphenate.js +1 -1
  153. package/lib/hyphenateStyleName.js +1 -1
  154. package/lib/instantiateReactComponent.js +90 -68
  155. package/lib/invariant.js +1 -1
  156. package/lib/isEventSupported.js +2 -2
  157. package/lib/isNode.js +4 -5
  158. package/lib/isTextInputElement.js +3 -4
  159. package/lib/isTextNode.js +1 -1
  160. package/lib/joinClasses.js +2 -2
  161. package/lib/keyMirror.js +2 -2
  162. package/lib/keyOf.js +1 -1
  163. package/lib/mapObject.js +1 -1
  164. package/lib/memoizeStringOnly.js +5 -6
  165. package/lib/onlyChild.js +2 -2
  166. package/lib/performance.js +1 -1
  167. package/lib/performanceNow.js +1 -1
  168. package/lib/quoteAttributeValueForBrowser.js +26 -0
  169. package/lib/setInnerHTML.js +13 -2
  170. package/lib/setTextContent.js +40 -0
  171. package/lib/shallowEqual.js +2 -2
  172. package/lib/shouldUpdateReactComponent.js +71 -7
  173. package/lib/toArray.js +2 -2
  174. package/lib/traverseAllChildren.js +114 -56
  175. package/lib/update.js +2 -2
  176. package/lib/warning.js +20 -2
  177. package/package.json +1 -1
  178. package/lib/CompositionEventPlugin.js +0 -257
  179. package/lib/ReactLegacyElement.js +0 -243
  180. package/lib/copyProperties.js +0 -54
  181. package/lib/deprecated.js +0 -47
  182. package/lib/merge.js +0 -34
  183. package/lib/mergeInto.js +0 -24
  184. package/lib/monitorCodeUse.js +0 -30
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013-2014, Facebook, Inc.
2
+ * Copyright 2013-2015, Facebook, Inc.
3
3
  * All rights reserved.
4
4
  *
5
5
  * This source code is licensed under the BSD-style license found in the
@@ -9,431 +9,123 @@
9
9
  * @providesModule ReactComponent
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
- var ReactElement = require("./ReactElement");
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 keyMirror = require("./keyMirror");
17
+ var warning = require("./warning");
21
18
 
22
19
  /**
23
- * Every React component is in one of these life cycles.
20
+ * Base class helpers for the updating state of a component.
24
21
  */
25
- var ComponentLifeCycle = keyMirror({
26
- /**
27
- * Mounted components have a DOM node representation and are capable of
28
- * receiving new props.
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
- * 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.
28
+ * Sets a subset of the state. Always use this to mutate
29
+ * state. You should treat `this.state` as immutable.
43
30
  *
44
- * @private
45
- */
46
- var unmountIDFromEnvironment = null;
47
-
48
- /**
49
- * The "image" of a component tree, is the platform specific (typically
50
- * serialized) data that represents a tree of lower level UI building blocks.
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.
38
+ *
39
+ * When a function is provided to setState, it will be called at some point in
40
+ * the future (not synchronously). It will be called with the up to date
41
+ * component arguments (state, props, context). These values can be different
42
+ * from this.* because your function may be called after receiveProps but before
43
+ * shouldComponentUpdate, and this new state, props, and context will not yet be
44
+ * assigned to this.
54
45
  *
55
- * @private
46
+ * @param {object|function} partialState Next partial state or function to
47
+ * produce next partial state to be merged with current state.
48
+ * @param {?function} callback Called after state is updated.
49
+ * @final
50
+ * @protected
56
51
  */
57
- var mountImageIntoNode = null;
52
+ ReactComponent.prototype.setState = function(partialState, callback) {
53
+ ("production" !== process.env.NODE_ENV ? invariant(
54
+ typeof partialState === 'object' ||
55
+ typeof partialState === 'function' ||
56
+ partialState == null,
57
+ 'setState(...): takes an object of state variables to update or a ' +
58
+ 'function which returns an object of state variables.'
59
+ ) : invariant(typeof partialState === 'object' ||
60
+ typeof partialState === 'function' ||
61
+ partialState == null));
62
+ if ("production" !== process.env.NODE_ENV) {
63
+ ("production" !== process.env.NODE_ENV ? warning(
64
+ partialState != null,
65
+ 'setState(...): You passed an undefined or null state object; ' +
66
+ 'instead, use forceUpdate().'
67
+ ) : null);
68
+ }
69
+ ReactUpdateQueue.enqueueSetState(this, partialState);
70
+ if (callback) {
71
+ ReactUpdateQueue.enqueueCallback(this, callback);
72
+ }
73
+ };
58
74
 
59
75
  /**
60
- * Components are the basic units of composition in React.
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:
76
+ * Forces an update. This should only be invoked when it is known with
77
+ * certainty that we are **not** in a DOM transaction.
67
78
  *
68
- * `mountComponent`
69
- * Initializes the component, renders markup, and registers event listeners.
79
+ * You may want to call this when you know that some deeper aspect of the
80
+ * component's state has changed but `setState` was not called.
70
81
  *
71
- * `receiveComponent`
72
- * Updates the rendered DOM nodes to match the given component.
82
+ * This will not invoke `shouldUpdateComponent`, but it will invoke
83
+ * `componentWillUpdate` and `componentDidUpdate`.
73
84
  *
74
- * `unmountComponent`
75
- * Releases any resources allocated by this component.
76
- *
77
- * Components can also be "owned" by other components. Being owned by another
78
- * component means being constructed by that component. This is different from
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.
81
- *
82
- * @class ReactComponent
85
+ * @param {?function} callback Called after update is complete.
86
+ * @final
87
+ * @protected
83
88
  */
84
- var ReactComponent = {
85
-
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
- /**
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.
89
+ ReactComponent.prototype.forceUpdate = function(callback) {
90
+ ReactUpdateQueue.enqueueForceUpdate(this);
91
+ if (callback) {
92
+ ReactUpdateQueue.enqueueCallback(this, callback);
93
+ }
94
+ };
350
95
 
351
- if (nextElement._owner !== prevElement._owner ||
352
- nextElement.ref !== prevElement.ref) {
353
- if (prevElement.ref != null) {
354
- ReactOwner.removeComponentAsRefFrom(
355
- this, prevElement.ref, prevElement._owner
356
- );
357
- }
358
- // Correct, even if the owner is the same, and only the ref has changed.
359
- if (nextElement.ref != null) {
360
- ReactOwner.addComponentAsRefTo(
361
- this,
362
- nextElement.ref,
363
- nextElement._owner
364
- );
96
+ /**
97
+ * Deprecated APIs. These APIs used to exist on classic React classes but since
98
+ * we would like to deprecate them, we're not going to move them over to this
99
+ * modern base class. Instead, we define a getter that warns if it's accessed.
100
+ */
101
+ if ("production" !== process.env.NODE_ENV) {
102
+ var deprecatedAPIs = {
103
+ getDOMNode: 'getDOMNode',
104
+ isMounted: 'isMounted',
105
+ replaceState: 'replaceState',
106
+ setProps: 'setProps'
107
+ };
108
+ var defineDeprecationWarning = function(methodName, displayName) {
109
+ try {
110
+ Object.defineProperty(ReactComponent.prototype, methodName, {
111
+ get: function() {
112
+ ("production" !== process.env.NODE_ENV ? warning(
113
+ false,
114
+ '%s(...) is deprecated in plain JavaScript React classes.',
115
+ displayName
116
+ ) : null);
117
+ return undefined;
365
118
  }
366
- }
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];
119
+ });
120
+ } catch (x) {
121
+ // IE will fail on defineProperty (es5-shim/sham too)
122
+ }
123
+ };
124
+ for (var fnName in deprecatedAPIs) {
125
+ if (deprecatedAPIs.hasOwnProperty(fnName)) {
126
+ defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
435
127
  }
436
128
  }
437
- };
129
+ }
438
130
 
439
131
  module.exports = ReactComponent;