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
@@ -9,7 +9,7 @@
9
9
  * @providesModule ReactPropTransferer
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var assign = require("./Object.assign");
15
15
  var emptyFunction = require("./emptyFunction");
@@ -101,7 +101,7 @@ var ReactPropTransferer = {
101
101
  */
102
102
  mergeProps: function(oldProps, newProps) {
103
103
  return transferInto(assign({}, oldProps), newProps);
104
- },
104
+ }
105
105
 
106
106
  };
107
107
 
@@ -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 ReactPropTypeLocationNames
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactPropTypeLocationNames = {};
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 ReactPropTypeLocations
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var keyMirror = require("./keyMirror");
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 ReactPropTypes
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var ReactElement = require("./ReactElement");
15
15
  var ReactPropTypeLocationNames = require("./ReactPropTypeLocationNames");
@@ -94,10 +94,11 @@ function createChainableTypeChecker(validate) {
94
94
  var locationName = ReactPropTypeLocationNames[location];
95
95
  if (isRequired) {
96
96
  return new Error(
97
- ("Required " + locationName + " `" + propName + "` was not specified in ")+
97
+ ("Required " + locationName + " `" + propName + "` was not specified in ") +
98
98
  ("`" + componentName + "`.")
99
99
  );
100
100
  }
101
+ return null;
101
102
  } else {
102
103
  return validate(props, propName, componentName, location);
103
104
  }
@@ -125,12 +126,13 @@ function createPrimitiveTypeChecker(expectedType) {
125
126
  ("supplied to `" + componentName + "`, expected `" + expectedType + "`.")
126
127
  );
127
128
  }
129
+ return null;
128
130
  }
129
131
  return createChainableTypeChecker(validate);
130
132
  }
131
133
 
132
134
  function createAnyTypeChecker() {
133
- return createChainableTypeChecker(emptyFunction.thatReturns());
135
+ return createChainableTypeChecker(emptyFunction.thatReturns(null));
134
136
  }
135
137
 
136
138
  function createArrayOfTypeChecker(typeChecker) {
@@ -150,6 +152,7 @@ function createArrayOfTypeChecker(typeChecker) {
150
152
  return error;
151
153
  }
152
154
  }
155
+ return null;
153
156
  }
154
157
  return createChainableTypeChecker(validate);
155
158
  }
@@ -163,6 +166,7 @@ function createElementTypeChecker() {
163
166
  ("`" + componentName + "`, expected a ReactElement.")
164
167
  );
165
168
  }
169
+ return null;
166
170
  }
167
171
  return createChainableTypeChecker(validate);
168
172
  }
@@ -177,6 +181,7 @@ function createInstanceTypeChecker(expectedClass) {
177
181
  ("`" + componentName + "`, expected instance of `" + expectedClassName + "`.")
178
182
  );
179
183
  }
184
+ return null;
180
185
  }
181
186
  return createChainableTypeChecker(validate);
182
187
  }
@@ -186,7 +191,7 @@ function createEnumTypeChecker(expectedValues) {
186
191
  var propValue = props[propName];
187
192
  for (var i = 0; i < expectedValues.length; i++) {
188
193
  if (propValue === expectedValues[i]) {
189
- return;
194
+ return null;
190
195
  }
191
196
  }
192
197
 
@@ -219,6 +224,7 @@ function createObjectOfTypeChecker(typeChecker) {
219
224
  }
220
225
  }
221
226
  }
227
+ return null;
222
228
  }
223
229
  return createChainableTypeChecker(validate);
224
230
  }
@@ -228,7 +234,7 @@ function createUnionTypeChecker(arrayOfTypeCheckers) {
228
234
  for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
229
235
  var checker = arrayOfTypeCheckers[i];
230
236
  if (checker(props, propName, componentName, location) == null) {
231
- return;
237
+ return null;
232
238
  }
233
239
  }
234
240
 
@@ -250,6 +256,7 @@ function createNodeChecker() {
250
256
  ("`" + componentName + "`, expected a ReactNode.")
251
257
  );
252
258
  }
259
+ return null;
253
260
  }
254
261
  return createChainableTypeChecker(validate);
255
262
  }
@@ -275,12 +282,13 @@ function createShapeTypeChecker(shapeTypes) {
275
282
  return error;
276
283
  }
277
284
  }
285
+ return null;
278
286
  }
279
- return createChainableTypeChecker(validate, 'expected `object`');
287
+ return createChainableTypeChecker(validate);
280
288
  }
281
289
 
282
290
  function isNode(propValue) {
283
- switch(typeof propValue) {
291
+ switch (typeof propValue) {
284
292
  case 'number':
285
293
  case 'string':
286
294
  return true;
@@ -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 ReactPutListenerQueue
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
14
  var PooledClass = require("./PooledClass");
15
15
  var ReactBrowserEventEmitter = require("./ReactBrowserEventEmitter");
@@ -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 static-only
11
11
  */
12
12
 
13
- "use strict";
13
+ 'use strict';
14
14
 
15
15
  var CallbackQueue = require("./CallbackQueue");
16
16
  var PooledClass = require("./PooledClass");
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Copyright 2013-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 ReactReconciler
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ var ReactRef = require("./ReactRef");
15
+ var ReactElementValidator = require("./ReactElementValidator");
16
+
17
+ /**
18
+ * Helper to call ReactRef.attachRefs with this composite component, split out
19
+ * to avoid allocations in the transaction mount-ready queue.
20
+ */
21
+ function attachRefs() {
22
+ ReactRef.attachRefs(this, this._currentElement);
23
+ }
24
+
25
+ var ReactReconciler = {
26
+
27
+ /**
28
+ * Initializes the component, renders markup, and registers event listeners.
29
+ *
30
+ * @param {ReactComponent} internalInstance
31
+ * @param {string} rootID DOM ID of the root node.
32
+ * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
33
+ * @return {?string} Rendered markup to be inserted into the DOM.
34
+ * @final
35
+ * @internal
36
+ */
37
+ mountComponent: function(internalInstance, rootID, transaction, context) {
38
+ var markup = internalInstance.mountComponent(rootID, transaction, context);
39
+ if ("production" !== process.env.NODE_ENV) {
40
+ ReactElementValidator.checkAndWarnForMutatedProps(
41
+ internalInstance._currentElement
42
+ );
43
+ }
44
+ transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
45
+ return markup;
46
+ },
47
+
48
+ /**
49
+ * Releases any resources allocated by `mountComponent`.
50
+ *
51
+ * @final
52
+ * @internal
53
+ */
54
+ unmountComponent: function(internalInstance) {
55
+ ReactRef.detachRefs(internalInstance, internalInstance._currentElement);
56
+ internalInstance.unmountComponent();
57
+ },
58
+
59
+ /**
60
+ * Update a component using a new element.
61
+ *
62
+ * @param {ReactComponent} internalInstance
63
+ * @param {ReactElement} nextElement
64
+ * @param {ReactReconcileTransaction} transaction
65
+ * @param {object} context
66
+ * @internal
67
+ */
68
+ receiveComponent: function(
69
+ internalInstance, nextElement, transaction, context
70
+ ) {
71
+ var prevElement = internalInstance._currentElement;
72
+
73
+ if (nextElement === prevElement && nextElement._owner != null) {
74
+ // Since elements are immutable after the owner is rendered,
75
+ // we can do a cheap identity compare here to determine if this is a
76
+ // superfluous reconcile. It's possible for state to be mutable but such
77
+ // change should trigger an update of the owner which would recreate
78
+ // the element. We explicitly check for the existence of an owner since
79
+ // it's possible for an element created outside a composite to be
80
+ // deeply mutated and reused.
81
+ return;
82
+ }
83
+
84
+ if ("production" !== process.env.NODE_ENV) {
85
+ ReactElementValidator.checkAndWarnForMutatedProps(nextElement);
86
+ }
87
+
88
+ var refsChanged = ReactRef.shouldUpdateRefs(
89
+ this,
90
+ prevElement,
91
+ nextElement
92
+ );
93
+
94
+ if (refsChanged) {
95
+ ReactRef.detachRefs(internalInstance, prevElement);
96
+ }
97
+
98
+ internalInstance.receiveComponent(nextElement, transaction, context);
99
+
100
+ if (refsChanged) {
101
+ transaction.getReactMountReady().enqueue(attachRefs, internalInstance);
102
+ }
103
+ },
104
+
105
+ /**
106
+ * Flush any dirty changes in a component.
107
+ *
108
+ * @param {ReactComponent} internalInstance
109
+ * @param {ReactReconcileTransaction} transaction
110
+ * @internal
111
+ */
112
+ performUpdateIfNecessary: function(
113
+ internalInstance,
114
+ transaction
115
+ ) {
116
+ internalInstance.performUpdateIfNecessary(transaction);
117
+ }
118
+
119
+ };
120
+
121
+ module.exports = ReactReconciler;
package/lib/ReactRef.js CHANGED
@@ -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,87 +9,60 @@
9
9
  * @providesModule ReactRef
10
10
  */
11
11
 
12
- "use strict";
12
+ 'use strict';
13
13
 
14
- var ReactUpdates = require("./ReactUpdates");
14
+ var ReactOwner = require("./ReactOwner");
15
15
 
16
- var accumulate = require("./accumulate");
17
- var assign = require("./Object.assign");
18
- var forEachAccumulated = require("./forEachAccumulated");
19
- var invariant = require("./invariant");
16
+ var ReactRef = {};
20
17
 
21
- function ReactRef() {
22
- this._value = null;
23
- this._successCallbacks = null;
24
- this._failureCallbacks = null;
18
+ function attachRef(ref, component, owner) {
19
+ if (typeof ref === 'function') {
20
+ ref(component.getPublicInstance());
21
+ } else {
22
+ // Legacy ref
23
+ ReactOwner.addComponentAsRefTo(component, ref, owner);
24
+ }
25
25
  }
26
26
 
27
- /**
28
- * Call the enqueued success or failure callbacks for a ref, as appropriate.
29
- */
30
- function dispatchCallbacks() {
31
- /*jshint validthis:true */
32
- var successCallbacks = this._successCallbacks;
33
- var failureCallbacks = this._failureCallbacks;
34
- this._successCallbacks = null;
35
- this._failureCallbacks = null;
36
-
37
- if (this._value) {
38
- forEachAccumulated(successCallbacks, callSuccess, this);
27
+ function detachRef(ref, component, owner) {
28
+ if (typeof ref === 'function') {
29
+ ref(null);
39
30
  } else {
40
- forEachAccumulated(failureCallbacks, callFailure);
31
+ // Legacy ref
32
+ ReactOwner.removeComponentAsRefFrom(component, ref, owner);
41
33
  }
42
34
  }
43
35
 
44
- /**
45
- * Call a single success callback, passing the ref's value.
46
- */
47
- function callSuccess(cb) {
48
- /*jshint validthis:true */
49
- cb(this._value);
50
- }
36
+ ReactRef.attachRefs = function(instance, element) {
37
+ var ref = element.ref;
38
+ if (ref != null) {
39
+ attachRef(ref, instance, element._owner);
40
+ }
41
+ };
51
42
 
52
- /**
53
- * Call a single failure callback, passing no arguments.
54
- */
55
- function callFailure(cb) {
56
- cb();
57
- }
43
+ ReactRef.shouldUpdateRefs = function(instance, prevElement, nextElement) {
44
+ // If either the owner or a `ref` has changed, make sure the newest owner
45
+ // has stored a reference to `this`, and the previous owner (if different)
46
+ // has forgotten the reference to `this`. We use the element instead
47
+ // of the public this.props because the post processing cannot determine
48
+ // a ref. The ref conceptually lives on the element.
58
49
 
59
- assign(ReactRef.prototype, {
60
- /**
61
- * Get the value of a ref asynchronously. Accepts a success callback and an
62
- * optional failure callback. If the ref has been rendered, the success
63
- * callback will be called with the component instance; otherwise, the failure
64
- * callback will be executed.
65
- *
66
- * @param {function} success Callback in case of success
67
- * @param {?function} failure Callback in case of failure
68
- */
69
- then: function(success, failure) {
70
- ("production" !== process.env.NODE_ENV ? invariant(
71
- typeof success === 'function',
72
- 'ReactRef.then(...): Must provide a success callback.'
73
- ) : invariant(typeof success === 'function'));
74
- if (this._successCallbacks == null) {
75
- ReactUpdates.asap(dispatchCallbacks, this);
76
- }
77
- this._successCallbacks = accumulate(this._successCallbacks, success);
78
- if (failure) {
79
- this._failureCallbacks = accumulate(this._failureCallbacks, failure);
80
- }
81
- }
82
- });
50
+ // TODO: Should this even be possible? The owner cannot change because
51
+ // it's forbidden by shouldUpdateReactComponent. The ref can change
52
+ // if you swap the keys of but not the refs. Reconsider where this check
53
+ // is made. It probably belongs where the key checking and
54
+ // instantiateReactComponent is done.
83
55
 
84
- ReactRef.attachRef = function(ref, value) {
85
- ref._value = value.getPublicInstance();
56
+ return (
57
+ nextElement._owner !== prevElement._owner ||
58
+ nextElement.ref !== prevElement.ref
59
+ );
86
60
  };
87
61
 
88
- ReactRef.detachRef = function(ref, value) {
89
- // Check that `component` is still the current ref because we do not want to
90
- // detach the ref if another component stole it.
91
- if (ref._value === value) {
92
- ref._value = null;
62
+ ReactRef.detachRefs = function(instance, element) {
63
+ var ref = element.ref;
64
+ if (ref != null) {
65
+ detachRef(ref, instance, element._owner);
93
66
  }
94
67
  };
95
68