react 0.8.0 → 0.10.0

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 (160) hide show
  1. package/README.md +0 -8
  2. package/addons.js +0 -3
  3. package/lib/AutoFocusMixin.js +32 -0
  4. package/lib/CSSCore.js +23 -22
  5. package/lib/CSSProperty.js +32 -1
  6. package/lib/CSSPropertyOperations.js +1 -1
  7. package/lib/ChangeEventPlugin.js +27 -5
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +58 -10
  10. package/lib/DOMChildrenOperations.js +39 -3
  11. package/lib/DOMProperty.js +9 -5
  12. package/lib/DOMPropertyOperations.js +21 -8
  13. package/lib/Danger.js +9 -8
  14. package/lib/DefaultDOMPropertyConfig.js +23 -14
  15. package/lib/DefaultEventPluginOrder.js +1 -1
  16. package/lib/EnterLeaveEventPlugin.js +38 -5
  17. package/lib/EventConstants.js +4 -1
  18. package/lib/EventListener.js +42 -34
  19. package/lib/EventPluginHub.js +118 -13
  20. package/lib/EventPluginRegistry.js +62 -18
  21. package/lib/EventPluginUtils.js +33 -4
  22. package/lib/EventPropagators.js +7 -43
  23. package/lib/ExecutionEnvironment.js +4 -1
  24. package/lib/LinkedStateMixin.js +1 -1
  25. package/lib/LinkedValueUtils.js +160 -0
  26. package/lib/MobileSafariClickEventPlugin.js +1 -1
  27. package/lib/PooledClass.js +7 -1
  28. package/lib/React.js +30 -4
  29. package/lib/ReactBrowserComponentMixin.js +42 -0
  30. package/lib/ReactCSSTransitionGroup.js +65 -0
  31. package/lib/{ReactTransitionableChild.js → ReactCSSTransitionGroupChild.js} +22 -36
  32. package/lib/ReactChildren.js +4 -4
  33. package/lib/ReactComponent.js +163 -83
  34. package/lib/ReactComponentBrowserEnvironment.js +55 -71
  35. package/lib/ReactCompositeComponent.js +686 -119
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +1 -1
  38. package/lib/ReactDOM.js +19 -6
  39. package/lib/ReactDOMButton.js +6 -1
  40. package/lib/ReactDOMComponent.js +66 -24
  41. package/lib/ReactDOMForm.js +13 -3
  42. package/lib/ReactDOMIDOperations.js +106 -61
  43. package/lib/ReactDOMImg.js +61 -0
  44. package/lib/ReactDOMInput.js +28 -15
  45. package/lib/ReactDOMOption.js +13 -8
  46. package/lib/ReactDOMSelect.js +38 -18
  47. package/lib/ReactDOMSelection.js +1 -1
  48. package/lib/ReactDOMTextarea.js +19 -11
  49. package/lib/ReactDefaultBatchingStrategy.js +1 -1
  50. package/lib/ReactDefaultInjection.js +60 -26
  51. package/lib/ReactDefaultPerf.js +208 -371
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +6 -15
  54. package/lib/ReactEventEmitter.js +144 -146
  55. package/lib/ReactEventEmitterMixin.js +1 -33
  56. package/lib/ReactEventTopLevelCallback.js +75 -15
  57. package/lib/ReactInjection.js +43 -0
  58. package/lib/ReactInputSelection.js +3 -2
  59. package/lib/ReactInstanceHandles.js +36 -20
  60. package/lib/ReactLink.js +2 -2
  61. package/lib/ReactMarkupChecksum.js +1 -1
  62. package/lib/ReactMount.js +136 -104
  63. package/lib/ReactMountReady.js +2 -2
  64. package/lib/ReactMultiChild.js +40 -49
  65. package/lib/ReactMultiChildUpdateTypes.js +3 -1
  66. package/lib/ReactOwner.js +17 -4
  67. package/lib/ReactPerf.js +6 -9
  68. package/lib/ReactPropTransferer.js +41 -22
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/{ReactComponentEnvironment.js → ReactPropTypeLocations.js} +11 -6
  71. package/lib/ReactPropTypes.js +249 -48
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +28 -7
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +46 -19
  76. package/lib/ReactServerRenderingTransaction.js +116 -0
  77. package/lib/ReactStateSetters.js +1 -1
  78. package/lib/ReactTestUtils.js +394 -0
  79. package/lib/ReactTextComponent.js +33 -6
  80. package/lib/{ReactTransitionKeySet.js → ReactTransitionChildMapping.js} +43 -48
  81. package/lib/ReactTransitionEvents.js +1 -1
  82. package/lib/ReactTransitionGroup.js +133 -58
  83. package/lib/ReactUpdates.js +15 -12
  84. package/lib/ReactWithAddons.js +15 -3
  85. package/lib/SelectEventPlugin.js +23 -40
  86. package/lib/ServerReactRootIndex.js +36 -0
  87. package/lib/SimpleEventPlugin.js +55 -7
  88. package/lib/SyntheticClipboardEvent.js +8 -2
  89. package/lib/SyntheticCompositionEvent.js +1 -1
  90. package/lib/SyntheticDragEvent.js +44 -0
  91. package/lib/SyntheticEvent.js +3 -2
  92. package/lib/SyntheticFocusEvent.js +1 -1
  93. package/lib/SyntheticKeyboardEvent.js +5 -3
  94. package/lib/SyntheticMouseEvent.js +1 -1
  95. package/lib/SyntheticTouchEvent.js +1 -1
  96. package/lib/SyntheticUIEvent.js +1 -1
  97. package/lib/SyntheticWheelEvent.js +11 -8
  98. package/lib/Transaction.js +62 -37
  99. package/lib/ViewportMetrics.js +1 -1
  100. package/lib/accumulate.js +1 -1
  101. package/lib/adler32.js +1 -1
  102. package/lib/cloneWithProps.js +59 -0
  103. package/lib/containsNode.js +1 -1
  104. package/lib/copyProperties.js +1 -1
  105. package/lib/createArrayFrom.js +11 -14
  106. package/lib/createFullPageComponent.js +63 -0
  107. package/lib/createNodesFromMarkup.js +1 -1
  108. package/lib/createObjectFrom.js +1 -1
  109. package/lib/cx.js +3 -3
  110. package/lib/dangerousStyleValue.js +1 -1
  111. package/lib/emptyFunction.js +1 -1
  112. package/lib/emptyObject.js +27 -0
  113. package/lib/escapeTextForBrowser.js +1 -1
  114. package/lib/flattenChildren.js +6 -3
  115. package/lib/focusNode.js +33 -0
  116. package/lib/forEachAccumulated.js +1 -1
  117. package/lib/getActiveElement.js +5 -4
  118. package/lib/getEventKey.js +85 -0
  119. package/lib/getEventTarget.js +1 -1
  120. package/lib/getMarkupWrap.js +11 -1
  121. package/lib/getNodeForCharacterOffset.js +1 -1
  122. package/lib/getReactRootElementInContainer.js +1 -1
  123. package/lib/getTextContentAccessor.js +6 -4
  124. package/lib/getUnboundedScrollPosition.js +3 -3
  125. package/lib/hyphenate.js +1 -1
  126. package/lib/instantiateReactComponent.js +70 -0
  127. package/lib/invariant.js +20 -12
  128. package/lib/isEventSupported.js +8 -12
  129. package/lib/isNode.js +2 -2
  130. package/lib/isTextInputElement.js +1 -1
  131. package/lib/isTextNode.js +1 -1
  132. package/lib/joinClasses.js +1 -1
  133. package/lib/keyMirror.js +1 -1
  134. package/lib/keyOf.js +1 -1
  135. package/lib/memoizeStringOnly.js +1 -1
  136. package/lib/merge.js +1 -1
  137. package/lib/mergeHelpers.js +6 -7
  138. package/lib/mergeInto.js +1 -1
  139. package/lib/mixInto.js +1 -1
  140. package/lib/monitorCodeUse.js +37 -0
  141. package/lib/objMap.js +1 -1
  142. package/lib/objMapKeyVal.js +1 -1
  143. package/lib/onlyChild.js +43 -0
  144. package/lib/performanceNow.js +1 -1
  145. package/lib/shallowEqual.js +1 -1
  146. package/lib/shouldUpdateReactComponent.js +61 -0
  147. package/lib/toArray.js +75 -0
  148. package/lib/traverseAllChildren.js +72 -9
  149. package/lib/update.js +159 -0
  150. package/lib/warning.js +48 -0
  151. package/package.json +3 -3
  152. package/react.js +0 -3
  153. package/ReactJSErrors.js +0 -40
  154. package/lib/$.js +0 -46
  155. package/lib/CallbackRegistry.js +0 -91
  156. package/lib/LinkedValueMixin.js +0 -68
  157. package/lib/ex.js +0 -49
  158. package/lib/filterAttributes.js +0 -45
  159. package/lib/ge.js +0 -76
  160. package/lib/mutateHTMLNodeWithMarkup.js +0 -100
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule instantiateReactComponent
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var warning = require("./warning");
23
+
24
+ /**
25
+ * Validate a `componentDescriptor`. This should be exposed publicly in a follow
26
+ * up diff.
27
+ *
28
+ * @param {object} descriptor
29
+ * @return {boolean} Returns true if this is a valid descriptor of a Component.
30
+ */
31
+ function isValidComponentDescriptor(descriptor) {
32
+ return (
33
+ typeof descriptor.constructor === 'function' &&
34
+ typeof descriptor.constructor.prototype.construct === 'function' &&
35
+ typeof descriptor.constructor.prototype.mountComponent === 'function' &&
36
+ typeof descriptor.constructor.prototype.receiveComponent === 'function'
37
+ );
38
+ }
39
+
40
+ /**
41
+ * Given a `componentDescriptor` create an instance that will actually be
42
+ * mounted. Currently it just extracts an existing clone from composite
43
+ * components but this is an implementation detail which will change.
44
+ *
45
+ * @param {object} descriptor
46
+ * @return {object} A new instance of componentDescriptor's constructor.
47
+ * @protected
48
+ */
49
+ function instantiateReactComponent(descriptor) {
50
+ if ("production" !== process.env.NODE_ENV) {
51
+ ("production" !== process.env.NODE_ENV ? warning(
52
+ isValidComponentDescriptor(descriptor),
53
+ 'Only React Components are valid for mounting.'
54
+ ) : null);
55
+ // We use the clone of a composite component instead of the original
56
+ // instance. This allows us to warn you if you're are accessing the wrong
57
+ // instance.
58
+ var instance = descriptor.__realComponentInstance || descriptor;
59
+ instance._descriptor = descriptor;
60
+ return instance;
61
+ }
62
+ // In prod we don't clone, we simply use the same instance for unaffected
63
+ // behavior. We have to keep the descriptor around for comparison later on.
64
+ // This should ideally be accepted in the constructor of the instance but
65
+ // since that is currently overloaded, we just manually attach it here.
66
+ descriptor._descriptor = descriptor;
67
+ return descriptor;
68
+ }
69
+
70
+ module.exports = instantiateReactComponent;
package/lib/invariant.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -16,26 +16,32 @@
16
16
  * @providesModule invariant
17
17
  */
18
18
 
19
+ "use strict";
20
+
19
21
  /**
20
22
  * Use invariant() to assert state which your program assumes to be true.
21
23
  *
22
- * Provide sprintf style format and arguments to provide information about
23
- * what broke and what you were expecting.
24
+ * Provide sprintf-style format (only %s is supported) and arguments
25
+ * to provide information about what broke and what you were
26
+ * expecting.
24
27
  *
25
28
  * The invariant message will be stripped in production, but the invariant
26
29
  * will remain to ensure logic does not differ in production.
27
30
  */
28
31
 
29
- function invariant(condition) {
32
+ var invariant = function(condition) {
30
33
  if (!condition) {
31
- throw new Error('Invariant Violation');
34
+ var error = new Error(
35
+ 'Minified exception occured; use the non-minified dev environment for ' +
36
+ 'the full error message and additional helpful warnings.'
37
+ );
38
+ error.framesToPop = 1;
39
+ throw error;
32
40
  }
33
- }
34
-
35
- module.exports = invariant;
41
+ };
36
42
 
37
43
  if ("production" !== process.env.NODE_ENV) {
38
- var invariantDev = function(condition, format, a, b, c, d, e, f) {
44
+ invariant = function(condition, format, a, b, c, d, e, f) {
39
45
  if (format === undefined) {
40
46
  throw new Error('invariant requires an error message argument');
41
47
  }
@@ -43,12 +49,14 @@ if ("production" !== process.env.NODE_ENV) {
43
49
  if (!condition) {
44
50
  var args = [a, b, c, d, e, f];
45
51
  var argIndex = 0;
46
- throw new Error(
52
+ var error = new Error(
47
53
  'Invariant Violation: ' +
48
54
  format.replace(/%s/g, function() { return args[argIndex++]; })
49
55
  );
56
+ error.framesToPop = 1; // we don't care about invariant's own frame
57
+ throw error;
50
58
  }
51
59
  };
52
-
53
- module.exports = invariantDev;
54
60
  }
61
+
62
+ module.exports = invariant;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -20,13 +20,13 @@
20
20
 
21
21
  var ExecutionEnvironment = require("./ExecutionEnvironment");
22
22
 
23
- var testNode, useHasFeature;
23
+ var useHasFeature;
24
24
  if (ExecutionEnvironment.canUseDOM) {
25
- testNode = document.createElement('div');
26
25
  useHasFeature =
27
26
  document.implementation &&
28
27
  document.implementation.hasFeature &&
29
- // `hasFeature` always returns true in Firefox 19+.
28
+ // always returns true in newer browsers as per the standard.
29
+ // @see http://dom.spec.whatwg.org/#dom-domimplementation-hasfeature
30
30
  document.implementation.hasFeature('', '') !== true;
31
31
  }
32
32
 
@@ -45,21 +45,18 @@ if (ExecutionEnvironment.canUseDOM) {
45
45
  * @license Modernizr 3.0.0pre (Custom Build) | MIT
46
46
  */
47
47
  function isEventSupported(eventNameSuffix, capture) {
48
- if (!testNode || (capture && !testNode.addEventListener)) {
48
+ if (!ExecutionEnvironment.canUseDOM ||
49
+ capture && !('addEventListener' in document)) {
49
50
  return false;
50
51
  }
51
- var element = document.createElement('div');
52
52
 
53
53
  var eventName = 'on' + eventNameSuffix;
54
- var isSupported = eventName in element;
54
+ var isSupported = eventName in document;
55
55
 
56
56
  if (!isSupported) {
57
+ var element = document.createElement('div');
57
58
  element.setAttribute(eventName, 'return;');
58
59
  isSupported = typeof element[eventName] === 'function';
59
- if (typeof element[eventName] !== 'undefined') {
60
- element[eventName] = undefined;
61
- }
62
- element.removeAttribute(eventName);
63
60
  }
64
61
 
65
62
  if (!isSupported && useHasFeature && eventNameSuffix === 'wheel') {
@@ -67,7 +64,6 @@ function isEventSupported(eventNameSuffix, capture) {
67
64
  isSupported = document.implementation.hasFeature('Events.wheel', '3.0');
68
65
  }
69
66
 
70
- element = null;
71
67
  return isSupported;
72
68
  }
73
69
 
package/lib/isNode.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
23
23
  */
24
24
  function isNode(object) {
25
25
  return !!(object && (
26
- typeof Node !== 'undefined' ? object instanceof Node :
26
+ typeof Node === 'function' ? object instanceof Node :
27
27
  typeof object === 'object' &&
28
28
  typeof object.nodeType === 'number' &&
29
29
  typeof object.nodeName === 'string'
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/isTextNode.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/keyMirror.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/keyOf.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/merge.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -66,9 +66,9 @@ var mergeHelpers = {
66
66
  checkMergeArrayArgs: function(one, two) {
67
67
  ("production" !== process.env.NODE_ENV ? invariant(
68
68
  Array.isArray(one) && Array.isArray(two),
69
- 'Critical assumptions about the merge functions have been violated. ' +
70
- 'This is the fault of the merge functions themselves, not necessarily ' +
71
- 'the callers.'
69
+ 'Tried to merge arrays, instead got %s and %s.',
70
+ one,
71
+ two
72
72
  ) : invariant(Array.isArray(one) && Array.isArray(two)));
73
73
  },
74
74
 
@@ -87,9 +87,8 @@ var mergeHelpers = {
87
87
  checkMergeObjectArg: function(arg) {
88
88
  ("production" !== process.env.NODE_ENV ? invariant(
89
89
  !isTerminal(arg) && !Array.isArray(arg),
90
- 'Critical assumptions about the merge functions have been violated. ' +
91
- 'This is the fault of the merge functions themselves, not necessarily ' +
92
- 'the callers.'
90
+ 'Tried to merge an object, instead got %s.',
91
+ arg
93
92
  ) : invariant(!isTerminal(arg) && !Array.isArray(arg)));
94
93
  },
95
94
 
package/lib/mergeInto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
package/lib/mixInto.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright 2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule monitorCodeUse
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var invariant = require("./invariant");
22
+
23
+ /**
24
+ * Provides open-source compatible instrumentation for monitoring certain API
25
+ * uses before we're ready to issue a warning or refactor. It accepts an event
26
+ * name which may only contain the characters [a-z0-9_] and an optional data
27
+ * object with further information.
28
+ */
29
+
30
+ function monitorCodeUse(eventName, data) {
31
+ ("production" !== process.env.NODE_ENV ? invariant(
32
+ eventName && !/[^a-z0-9_]/.test(eventName),
33
+ 'You must provide an eventName using only the characters [a-z0-9_]'
34
+ ) : invariant(eventName && !/[^a-z0-9_]/.test(eventName)));
35
+ }
36
+
37
+ module.exports = monitorCodeUse;
package/lib/objMap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule onlyChild
17
+ */
18
+ "use strict";
19
+
20
+ var ReactComponent = require("./ReactComponent");
21
+
22
+ var invariant = require("./invariant");
23
+
24
+ /**
25
+ * Returns the first child in a collection of children and verifies that there
26
+ * is only one child in the collection. The current implementation of this
27
+ * function assumes that a single child gets passed without a wrapper, but the
28
+ * purpose of this helper function is to abstract away the particular structure
29
+ * of children.
30
+ *
31
+ * @param {?object} children Child collection structure.
32
+ * @return {ReactComponent} The first and only `ReactComponent` contained in the
33
+ * structure.
34
+ */
35
+ function onlyChild(children) {
36
+ ("production" !== process.env.NODE_ENV ? invariant(
37
+ ReactComponent.isValidComponent(children),
38
+ 'onlyChild must be passed a children with exactly one child.'
39
+ ) : invariant(ReactComponent.isValidComponent(children)));
40
+ return children;
41
+ }
42
+
43
+ module.exports = onlyChild;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright 2013 Facebook, Inc.
2
+ * Copyright 2013-2014 Facebook, Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule shouldUpdateReactComponent
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ /**
23
+ * Given a `prevComponentInstance` and `nextComponent`, determines if
24
+ * `prevComponentInstance` should be updated as opposed to being destroyed or
25
+ * replaced by a new instance. The second argument is a descriptor. Future
26
+ * versions of the reconciler should only compare descriptors to other
27
+ * descriptors.
28
+ *
29
+ * @param {?object} prevComponentInstance
30
+ * @param {?object} nextDescriptor
31
+ * @return {boolean} True if `prevComponentInstance` should be updated.
32
+ * @protected
33
+ */
34
+ function shouldUpdateReactComponent(prevComponentInstance, nextDescriptor) {
35
+ // TODO: Remove warning after a release.
36
+ if (prevComponentInstance && nextDescriptor &&
37
+ prevComponentInstance.constructor === nextDescriptor.constructor && (
38
+ (prevComponentInstance.props && prevComponentInstance.props.key) ===
39
+ (nextDescriptor.props && nextDescriptor.props.key)
40
+ )) {
41
+ if (prevComponentInstance._owner === nextDescriptor._owner) {
42
+ return true;
43
+ } else {
44
+ if ("production" !== process.env.NODE_ENV) {
45
+ if (prevComponentInstance.state) {
46
+ console.warn(
47
+ 'A recent change to React has been found to impact your code. ' +
48
+ 'A mounted component will now be unmounted and replaced by a ' +
49
+ 'component (of the same class) if their owners are different. ' +
50
+ 'Previously, ownership was not considered when updating.',
51
+ prevComponentInstance,
52
+ nextDescriptor
53
+ );
54
+ }
55
+ }
56
+ }
57
+ }
58
+ return false;
59
+ }
60
+
61
+ module.exports = shouldUpdateReactComponent;