react 0.13.0-alpha.1 → 0.13.0-rc1

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 (182) hide show
  1. package/dist/JSXTransformer.js +1376 -596
  2. package/dist/react-with-addons.js +3256 -2363
  3. package/dist/react-with-addons.min.js +7 -7
  4. package/dist/react.js +3092 -2266
  5. package/dist/react.min.js +6 -7
  6. package/lib/AutoFocusMixin.js +2 -2
  7. package/lib/BeforeInputEventPlugin.js +5 -9
  8. package/lib/CSSCore.js +1 -1
  9. package/lib/CSSProperty.js +4 -2
  10. package/lib/CSSPropertyOperations.js +44 -17
  11. package/lib/CallbackQueue.js +3 -3
  12. package/lib/ChangeEventPlugin.js +2 -2
  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 +7 -6
  18. package/lib/DefaultEventPluginOrder.js +3 -3
  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 +1 -1
  27. package/lib/FallbackCompositionState.js +7 -5
  28. package/lib/HTMLDOMPropertyConfig.js +22 -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 +2 -2
  34. package/lib/PooledClass.js +2 -2
  35. package/lib/React.js +9 -13
  36. package/lib/ReactBrowserComponentMixin.js +2 -2
  37. package/lib/ReactBrowserEventEmitter.js +4 -4
  38. package/lib/ReactCSSTransitionGroup.js +2 -2
  39. package/lib/ReactCSSTransitionGroupChild.js +12 -7
  40. package/lib/ReactChildReconciler.js +11 -7
  41. package/lib/ReactChildren.js +13 -10
  42. package/lib/ReactClass.js +161 -135
  43. package/lib/ReactComponent.js +100 -158
  44. package/lib/ReactComponentBrowserEnvironment.js +2 -2
  45. package/lib/ReactComponentEnvironment.js +3 -3
  46. package/lib/ReactComponentWithPureRenderMixin.js +2 -2
  47. package/lib/ReactCompositeComponent.js +336 -484
  48. package/lib/ReactContext.js +14 -4
  49. package/lib/ReactCurrentOwner.js +2 -2
  50. package/lib/ReactDOM.js +2 -2
  51. package/lib/ReactDOMButton.js +2 -2
  52. package/lib/ReactDOMComponent.js +42 -52
  53. package/lib/ReactDOMForm.js +2 -2
  54. package/lib/ReactDOMIDOperations.js +4 -4
  55. package/lib/ReactDOMIframe.js +43 -0
  56. package/lib/ReactDOMImg.js +2 -2
  57. package/lib/ReactDOMInput.js +2 -2
  58. package/lib/ReactDOMOption.js +2 -2
  59. package/lib/ReactDOMSelect.js +3 -3
  60. package/lib/ReactDOMSelection.js +2 -2
  61. package/lib/ReactDOMTextComponent.js +4 -13
  62. package/lib/ReactDOMTextarea.js +2 -2
  63. package/lib/ReactDefaultBatchingStrategy.js +5 -5
  64. package/lib/ReactDefaultInjection.js +26 -2
  65. package/lib/ReactDefaultPerf.js +12 -4
  66. package/lib/ReactDefaultPerfAnalysis.js +1 -1
  67. package/lib/ReactElement.js +7 -5
  68. package/lib/ReactElementValidator.js +185 -65
  69. package/lib/ReactEmptyComponent.js +17 -6
  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 +180 -0
  74. package/lib/ReactInjection.js +2 -2
  75. package/lib/ReactInputSelection.js +2 -2
  76. package/lib/ReactInstanceHandles.js +4 -3
  77. package/lib/ReactInstanceMap.js +2 -2
  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 +87 -23
  82. package/lib/ReactMultiChild.js +19 -7
  83. package/lib/ReactMultiChildUpdateTypes.js +2 -2
  84. package/lib/ReactNativeComponent.js +34 -37
  85. package/lib/ReactOwner.js +2 -2
  86. package/lib/ReactPerf.js +2 -2
  87. package/lib/ReactPropTransferer.js +3 -3
  88. package/lib/ReactPropTypeLocationNames.js +2 -2
  89. package/lib/ReactPropTypeLocations.js +2 -2
  90. package/lib/ReactPropTypes.js +16 -8
  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 +41 -68
  95. package/lib/ReactRootIndex.js +2 -2
  96. package/lib/ReactServerRendering.js +4 -3
  97. package/lib/ReactServerRenderingTransaction.js +2 -2
  98. package/lib/ReactStateSetters.js +2 -2
  99. package/lib/ReactTestUtils.js +49 -8
  100. package/lib/ReactTransitionChildMapping.js +8 -4
  101. package/lib/ReactTransitionEvents.js +2 -2
  102. package/lib/ReactTransitionGroup.js +6 -6
  103. package/lib/ReactUpdateQueue.js +295 -0
  104. package/lib/ReactUpdates.js +13 -22
  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 +2 -2
  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 +5 -5
  122. package/lib/ViewportMetrics.js +2 -2
  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 +2 -2
  131. package/lib/createNodesFromMarkup.js +4 -4
  132. package/lib/cx.js +16 -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 +26 -9
  138. package/lib/flattenChildren.js +11 -9
  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 +2 -2
  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 +21 -21
  155. package/lib/invariant.js +1 -1
  156. package/lib/isEventSupported.js +2 -2
  157. package/lib/isNode.js +1 -1
  158. package/lib/isTextInputElement.js +2 -2
  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 +64 -8
  173. package/lib/toArray.js +2 -2
  174. package/lib/traverseAllChildren.js +19 -5
  175. package/lib/update.js +2 -2
  176. package/lib/warning.js +20 -2
  177. package/package.json +1 -1
  178. package/lib/accumulate.js +0 -47
  179. package/lib/copyProperties.js +0 -56
  180. package/lib/merge.js +0 -34
  181. package/lib/mergeInto.js +0 -24
  182. 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
@@ -10,7 +10,7 @@
10
10
  * @typechecks
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var ReactRootIndexInjection = {
16
16
  /**
@@ -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,7 +9,7 @@
9
9
  * @typechecks static-only
10
10
  * @providesModule ReactServerRendering
11
11
  */
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactElement = require("./ReactElement");
15
15
  var ReactInstanceHandles = require("./ReactInstanceHandles");
@@ -38,7 +38,8 @@ function renderToString(element) {
38
38
 
39
39
  return transaction.perform(function() {
40
40
  var componentInstance = instantiateReactComponent(element, null);
41
- var markup = componentInstance.mountComponent(id, transaction, emptyObject);
41
+ var markup =
42
+ componentInstance.mountComponent(id, transaction, emptyObject);
42
43
  return ReactMarkupChecksum.addChecksumToMarkup(markup);
43
44
  }, null);
44
45
  } finally {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2014, Facebook, Inc.
2
+ * Copyright 2014-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
@@ -10,7 +10,7 @@
10
10
  * @typechecks
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var PooledClass = require("./PooledClass");
16
16
  var CallbackQueue = require("./CallbackQueue");
@@ -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,7 +9,7 @@
9
9
  * @providesModule ReactStateSetters
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactStateSetters = {
15
15
  /**
@@ -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,13 +9,14 @@
9
9
  * @providesModule ReactTestUtils
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var EventConstants = require("./EventConstants");
15
15
  var EventPluginHub = require("./EventPluginHub");
16
16
  var EventPropagators = require("./EventPropagators");
17
17
  var React = require("./React");
18
18
  var ReactElement = require("./ReactElement");
19
+ var ReactEmptyComponent = require("./ReactEmptyComponent");
19
20
  var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
20
21
  var ReactCompositeComponent = require("./ReactCompositeComponent");
21
22
  var ReactInstanceHandles = require("./ReactInstanceHandles");
@@ -169,7 +170,7 @@ var ReactTestUtils = {
169
170
  var all =
170
171
  ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
171
172
  if (all.length !== 1) {
172
- throw new Error('Did not find exactly one match '+
173
+ throw new Error('Did not find exactly one match ' +
173
174
  '(found: ' + all.length + ') for class:' + className
174
175
  );
175
176
  }
@@ -320,15 +321,49 @@ var ReactShallowRenderer = function() {
320
321
  };
321
322
 
322
323
  ReactShallowRenderer.prototype.getRenderOutput = function() {
323
- return (this._instance && this._instance._renderedComponent) || null;
324
+ return (
325
+ (this._instance && this._instance._renderedComponent &&
326
+ this._instance._renderedComponent._renderedOutput)
327
+ || null
328
+ );
324
329
  };
325
330
 
326
- var ShallowComponentWrapper = function(inst) {
327
- this._instance = inst;
331
+ var NoopInternalComponent = function(element) {
332
+ this._renderedOutput = element;
333
+ this._currentElement = element === null || element === false ?
334
+ ReactEmptyComponent.emptyElement :
335
+ element;
328
336
  };
337
+
338
+ NoopInternalComponent.prototype = {
339
+
340
+ mountComponent: function() {
341
+ },
342
+
343
+ receiveComponent: function(element) {
344
+ this._renderedOutput = element;
345
+ this._currentElement = element === null || element === false ?
346
+ ReactEmptyComponent.emptyElement :
347
+ element;
348
+ },
349
+
350
+ unmountComponent: function() {
351
+ }
352
+
353
+ };
354
+
355
+ var ShallowComponentWrapper = function() { };
329
356
  assign(
330
357
  ShallowComponentWrapper.prototype,
331
- ReactCompositeComponent.ShallowMixin
358
+ ReactCompositeComponent.Mixin, {
359
+ _instantiateReactComponent: function(element) {
360
+ return new NoopInternalComponent(element);
361
+ },
362
+ _replaceNodeWithMarkupByID: function() {},
363
+ _renderValidatedComponent:
364
+ ReactCompositeComponent.Mixin.
365
+ _renderValidatedComponentWithoutOwnerOrContext
366
+ }
332
367
  );
333
368
 
334
369
  ReactShallowRenderer.prototype.render = function(element, context) {
@@ -337,10 +372,16 @@ ReactShallowRenderer.prototype.render = function(element, context) {
337
372
  ReactUpdates.ReactReconcileTransaction.release(transaction);
338
373
  };
339
374
 
375
+ ReactShallowRenderer.prototype.unmount = function() {
376
+ if (this._instance) {
377
+ this._instance.unmountComponent();
378
+ }
379
+ };
380
+
340
381
  ReactShallowRenderer.prototype._render = function(element, transaction, context) {
341
382
  if (!this._instance) {
342
383
  var rootID = ReactInstanceHandles.createReactRootID();
343
- var instance = new ShallowComponentWrapper(new element.type(element.props));
384
+ var instance = new ShallowComponentWrapper(element.type);
344
385
  instance.construct(element);
345
386
 
346
387
  instance.mountComponent(rootID, transaction, context);
@@ -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
@@ -10,9 +10,10 @@
10
10
  * @providesModule ReactTransitionChildMapping
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var ReactChildren = require("./ReactChildren");
16
+ var ReactFragment = require("./ReactFragment");
16
17
 
17
18
  var ReactTransitionChildMapping = {
18
19
  /**
@@ -23,9 +24,12 @@ var ReactTransitionChildMapping = {
23
24
  * @return {object} Mapping of key to child
24
25
  */
25
26
  getChildMapping: function(children) {
26
- return ReactChildren.map(children, function(child) {
27
+ if (!children) {
28
+ return children;
29
+ }
30
+ return ReactFragment.extract(ReactChildren.map(children, function(child) {
27
31
  return child;
28
- });
32
+ }));
29
33
  },
30
34
 
31
35
  /**
@@ -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,7 +9,7 @@
9
9
  * @providesModule ReactTransitionEvents
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ExecutionEnvironment = require("./ExecutionEnvironment");
15
15
 
@@ -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,7 +9,7 @@
9
9
  * @providesModule ReactTransitionGroup
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var React = require("./React");
15
15
  var ReactTransitionChildMapping = require("./ReactTransitionChildMapping");
@@ -202,7 +202,7 @@ var ReactTransitionGroup = React.createClass({
202
202
  render: function() {
203
203
  // TODO: we could get rid of the need for the wrapper node
204
204
  // by cloning a single child
205
- var childrenToRender = {};
205
+ var childrenToRender = [];
206
206
  for (var key in this.state.children) {
207
207
  var child = this.state.children[key];
208
208
  if (child) {
@@ -211,10 +211,10 @@ var ReactTransitionGroup = React.createClass({
211
211
  // already been removed. In case you need this behavior you can provide
212
212
  // a childFactory function to wrap every child, even the ones that are
213
213
  // leaving.
214
- childrenToRender[key] = cloneWithProps(
214
+ childrenToRender.push(cloneWithProps(
215
215
  this.props.childFactory(child),
216
- {ref: key}
217
- );
216
+ {ref: key, key: key}
217
+ ));
218
218
  }
219
219
  }
220
220
  return React.createElement(
@@ -0,0 +1,295 @@
1
+ /**
2
+ * Copyright 2015, 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 ReactUpdateQueue
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var ReactLifeCycle = require("./ReactLifeCycle");
15
+ var ReactCurrentOwner = require("./ReactCurrentOwner");
16
+ var ReactElement = require("./ReactElement");
17
+ var ReactInstanceMap = require("./ReactInstanceMap");
18
+ var ReactUpdates = require("./ReactUpdates");
19
+
20
+ var assign = require("./Object.assign");
21
+ var invariant = require("./invariant");
22
+ var warning = require("./warning");
23
+
24
+ function enqueueUpdate(internalInstance) {
25
+ if (internalInstance !== ReactLifeCycle.currentlyMountingInstance) {
26
+ // If we're in a componentWillMount handler, don't enqueue a rerender
27
+ // because ReactUpdates assumes we're in a browser context (which is
28
+ // wrong for server rendering) and we're about to do a render anyway.
29
+ // See bug in #1740.
30
+ ReactUpdates.enqueueUpdate(internalInstance);
31
+ }
32
+ }
33
+
34
+ function getInternalInstanceReadyForUpdate(publicInstance, callerName) {
35
+ ("production" !== process.env.NODE_ENV ? invariant(
36
+ ReactCurrentOwner.current == null,
37
+ '%s(...): Cannot update during an existing state transition ' +
38
+ '(such as within `render`). Render methods should be a pure function ' +
39
+ 'of props and state.',
40
+ callerName
41
+ ) : invariant(ReactCurrentOwner.current == null));
42
+
43
+ var internalInstance = ReactInstanceMap.get(publicInstance);
44
+ if (!internalInstance) {
45
+ if ("production" !== process.env.NODE_ENV) {
46
+ // Only warn when we have a callerName. Otherwise we should be silent.
47
+ // We're probably calling from enqueueCallback. We don't want to warn
48
+ // there because we already warned for the corresponding lifecycle method.
49
+ ("production" !== process.env.NODE_ENV ? warning(
50
+ !callerName,
51
+ '%s(...): Can only update a mounted or mounting component. ' +
52
+ 'This usually means you called %s() on an unmounted ' +
53
+ 'component. This is a no-op.',
54
+ callerName,
55
+ callerName
56
+ ) : null);
57
+ }
58
+ return null;
59
+ }
60
+
61
+ if (internalInstance === ReactLifeCycle.currentlyUnmountingInstance) {
62
+ return null;
63
+ }
64
+
65
+ return internalInstance;
66
+ }
67
+
68
+ /**
69
+ * ReactUpdateQueue allows for state updates to be scheduled into a later
70
+ * reconciliation step.
71
+ */
72
+ var ReactUpdateQueue = {
73
+
74
+ /**
75
+ * Enqueue a callback that will be executed after all the pending updates
76
+ * have processed.
77
+ *
78
+ * @param {ReactClass} publicInstance The instance to use as `this` context.
79
+ * @param {?function} callback Called after state is updated.
80
+ * @internal
81
+ */
82
+ enqueueCallback: function(publicInstance, callback) {
83
+ ("production" !== process.env.NODE_ENV ? invariant(
84
+ typeof callback === 'function',
85
+ 'enqueueCallback(...): You called `setProps`, `replaceProps`, ' +
86
+ '`setState`, `replaceState`, or `forceUpdate` with a callback that ' +
87
+ 'isn\'t callable.'
88
+ ) : invariant(typeof callback === 'function'));
89
+ var internalInstance = getInternalInstanceReadyForUpdate(publicInstance);
90
+
91
+ // Previously we would throw an error if we didn't have an internal
92
+ // instance. Since we want to make it a no-op instead, we mirror the same
93
+ // behavior we have in other enqueue* methods.
94
+ // We also need to ignore callbacks in componentWillMount. See
95
+ // enqueueUpdates.
96
+ if (!internalInstance ||
97
+ internalInstance === ReactLifeCycle.currentlyMountingInstance) {
98
+ return null;
99
+ }
100
+
101
+ if (internalInstance._pendingCallbacks) {
102
+ internalInstance._pendingCallbacks.push(callback);
103
+ } else {
104
+ internalInstance._pendingCallbacks = [callback];
105
+ }
106
+ // TODO: The callback here is ignored when setState is called from
107
+ // componentWillMount. Either fix it or disallow doing so completely in
108
+ // favor of getInitialState. Alternatively, we can disallow
109
+ // componentWillMount during server-side rendering.
110
+ enqueueUpdate(internalInstance);
111
+ },
112
+
113
+ enqueueCallbackInternal: function(internalInstance, callback) {
114
+ ("production" !== process.env.NODE_ENV ? invariant(
115
+ typeof callback === 'function',
116
+ 'enqueueCallback(...): You called `setProps`, `replaceProps`, ' +
117
+ '`setState`, `replaceState`, or `forceUpdate` with a callback that ' +
118
+ 'isn\'t callable.'
119
+ ) : invariant(typeof callback === 'function'));
120
+ if (internalInstance._pendingCallbacks) {
121
+ internalInstance._pendingCallbacks.push(callback);
122
+ } else {
123
+ internalInstance._pendingCallbacks = [callback];
124
+ }
125
+ enqueueUpdate(internalInstance);
126
+ },
127
+
128
+ /**
129
+ * Forces an update. This should only be invoked when it is known with
130
+ * certainty that we are **not** in a DOM transaction.
131
+ *
132
+ * You may want to call this when you know that some deeper aspect of the
133
+ * component's state has changed but `setState` was not called.
134
+ *
135
+ * This will not invoke `shouldUpdateComponent`, but it will invoke
136
+ * `componentWillUpdate` and `componentDidUpdate`.
137
+ *
138
+ * @param {ReactClass} publicInstance The instance that should rerender.
139
+ * @internal
140
+ */
141
+ enqueueForceUpdate: function(publicInstance) {
142
+ var internalInstance = getInternalInstanceReadyForUpdate(
143
+ publicInstance,
144
+ 'forceUpdate'
145
+ );
146
+
147
+ if (!internalInstance) {
148
+ return;
149
+ }
150
+
151
+ internalInstance._pendingForceUpdate = true;
152
+
153
+ enqueueUpdate(internalInstance);
154
+ },
155
+
156
+ /**
157
+ * Replaces all of the state. Always use this or `setState` to mutate state.
158
+ * You should treat `this.state` as immutable.
159
+ *
160
+ * There is no guarantee that `this.state` will be immediately updated, so
161
+ * accessing `this.state` after calling this method may return the old value.
162
+ *
163
+ * @param {ReactClass} publicInstance The instance that should rerender.
164
+ * @param {object} completeState Next state.
165
+ * @internal
166
+ */
167
+ enqueueReplaceState: function(publicInstance, completeState) {
168
+ var internalInstance = getInternalInstanceReadyForUpdate(
169
+ publicInstance,
170
+ 'replaceState'
171
+ );
172
+
173
+ if (!internalInstance) {
174
+ return;
175
+ }
176
+
177
+ internalInstance._pendingStateQueue = [completeState];
178
+ internalInstance._pendingReplaceState = true;
179
+
180
+ enqueueUpdate(internalInstance);
181
+ },
182
+
183
+ /**
184
+ * Sets a subset of the state. This only exists because _pendingState is
185
+ * internal. This provides a merging strategy that is not available to deep
186
+ * properties which is confusing. TODO: Expose pendingState or don't use it
187
+ * during the merge.
188
+ *
189
+ * @param {ReactClass} publicInstance The instance that should rerender.
190
+ * @param {object} partialState Next partial state to be merged with state.
191
+ * @internal
192
+ */
193
+ enqueueSetState: function(publicInstance, partialState) {
194
+ var internalInstance = getInternalInstanceReadyForUpdate(
195
+ publicInstance,
196
+ 'setState'
197
+ );
198
+
199
+ if (!internalInstance) {
200
+ return;
201
+ }
202
+
203
+ var queue =
204
+ internalInstance._pendingStateQueue ||
205
+ (internalInstance._pendingStateQueue = []);
206
+ queue.push(partialState);
207
+
208
+ enqueueUpdate(internalInstance);
209
+ },
210
+
211
+ /**
212
+ * Sets a subset of the props.
213
+ *
214
+ * @param {ReactClass} publicInstance The instance that should rerender.
215
+ * @param {object} partialProps Subset of the next props.
216
+ * @internal
217
+ */
218
+ enqueueSetProps: function(publicInstance, partialProps) {
219
+ var internalInstance = getInternalInstanceReadyForUpdate(
220
+ publicInstance,
221
+ 'setProps'
222
+ );
223
+
224
+ if (!internalInstance) {
225
+ return;
226
+ }
227
+
228
+ ("production" !== process.env.NODE_ENV ? invariant(
229
+ internalInstance._isTopLevel,
230
+ 'setProps(...): You called `setProps` on a ' +
231
+ 'component with a parent. This is an anti-pattern since props will ' +
232
+ 'get reactively updated when rendered. Instead, change the owner\'s ' +
233
+ '`render` method to pass the correct value as props to the component ' +
234
+ 'where it is created.'
235
+ ) : invariant(internalInstance._isTopLevel));
236
+
237
+ // Merge with the pending element if it exists, otherwise with existing
238
+ // element props.
239
+ var element = internalInstance._pendingElement ||
240
+ internalInstance._currentElement;
241
+ var props = assign({}, element.props, partialProps);
242
+ internalInstance._pendingElement = ReactElement.cloneAndReplaceProps(
243
+ element,
244
+ props
245
+ );
246
+
247
+ enqueueUpdate(internalInstance);
248
+ },
249
+
250
+ /**
251
+ * Replaces all of the props.
252
+ *
253
+ * @param {ReactClass} publicInstance The instance that should rerender.
254
+ * @param {object} props New props.
255
+ * @internal
256
+ */
257
+ enqueueReplaceProps: function(publicInstance, props) {
258
+ var internalInstance = getInternalInstanceReadyForUpdate(
259
+ publicInstance,
260
+ 'replaceProps'
261
+ );
262
+
263
+ if (!internalInstance) {
264
+ return;
265
+ }
266
+
267
+ ("production" !== process.env.NODE_ENV ? invariant(
268
+ internalInstance._isTopLevel,
269
+ 'replaceProps(...): You called `replaceProps` on a ' +
270
+ 'component with a parent. This is an anti-pattern since props will ' +
271
+ 'get reactively updated when rendered. Instead, change the owner\'s ' +
272
+ '`render` method to pass the correct value as props to the component ' +
273
+ 'where it is created.'
274
+ ) : invariant(internalInstance._isTopLevel));
275
+
276
+ // Merge with the pending element if it exists, otherwise with existing
277
+ // element props.
278
+ var element = internalInstance._pendingElement ||
279
+ internalInstance._currentElement;
280
+ internalInstance._pendingElement = ReactElement.cloneAndReplaceProps(
281
+ element,
282
+ props
283
+ );
284
+
285
+ enqueueUpdate(internalInstance);
286
+ },
287
+
288
+ enqueueElementInternal: function(internalInstance, newElement) {
289
+ internalInstance._pendingElement = newElement;
290
+ enqueueUpdate(internalInstance);
291
+ }
292
+
293
+ };
294
+
295
+ module.exports = ReactUpdateQueue;