react 15.3.1-rc.2 → 15.4.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/react-with-addons.js +3961 -21387
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2701 -19464
  4. package/dist/react.min.js +2 -6
  5. package/lib/LinkedStateMixin.js +1 -2
  6. package/lib/PooledClass.js +3 -0
  7. package/lib/ReactAddonsDOMDependencies.js +36 -0
  8. package/lib/ReactAddonsDOMDependenciesUMDShim.js +32 -0
  9. package/lib/ReactCSSTransitionGroup.js +60 -42
  10. package/lib/ReactCSSTransitionGroupChild.js +2 -2
  11. package/lib/ReactClass.js +38 -53
  12. package/lib/ReactComponentTreeHook.js +84 -100
  13. package/lib/{DOMNamespaces.js → ReactComponentTreeHookUMDShim.js} +5 -7
  14. package/lib/ReactCurrentOwner.js +1 -1
  15. package/lib/{renderSubtreeIntoContainer.js → ReactCurrentOwnerUMDShim.js} +6 -4
  16. package/lib/ReactElement.js +6 -29
  17. package/lib/ReactElementSymbol.js +20 -0
  18. package/lib/{ReactDOMComponentFlags.js → ReactElementType.js} +4 -9
  19. package/lib/ReactElementValidator.js +1 -2
  20. package/lib/ReactPropTypeLocationNames.js +1 -0
  21. package/lib/ReactPropTypeLocations.js +2 -11
  22. package/lib/ReactPropTypes.js +30 -13
  23. package/lib/ReactPropTypesSecret.js +1 -0
  24. package/lib/ReactTransitionEvents.js +1 -1
  25. package/lib/ReactTransitionGroup.js +145 -141
  26. package/lib/ReactUMDEntry.js +11 -5
  27. package/lib/{ReactDOMFeatureFlags.js → ReactUMDShim.js} +4 -6
  28. package/lib/ReactVersion.js +1 -1
  29. package/lib/ReactWithAddons.js +15 -2
  30. package/lib/ReactWithAddonsUMDEntry.js +11 -5
  31. package/lib/canDefineProperty.js +2 -0
  32. package/lib/onlyChild.js +1 -1
  33. package/lib/traverseAllChildren.js +11 -2
  34. package/lib/update.js +6 -7
  35. package/package.json +2 -2
  36. package/lib/AutoFocusUtils.js +0 -24
  37. package/lib/BeforeInputEventPlugin.js +0 -388
  38. package/lib/CSSProperty.js +0 -148
  39. package/lib/CSSPropertyOperations.js +0 -205
  40. package/lib/CallbackQueue.js +0 -106
  41. package/lib/ChangeEventPlugin.js +0 -325
  42. package/lib/DOMChildrenOperations.js +0 -194
  43. package/lib/DOMLazyTree.js +0 -118
  44. package/lib/DOMProperty.js +0 -206
  45. package/lib/DOMPropertyOperations.js +0 -221
  46. package/lib/Danger.js +0 -48
  47. package/lib/DefaultEventPluginOrder.js +0 -27
  48. package/lib/DisabledInputUtils.js +0 -50
  49. package/lib/EnterLeaveEventPlugin.js +0 -105
  50. package/lib/EventConstants.js +0 -97
  51. package/lib/EventPluginHub.js +0 -251
  52. package/lib/EventPluginRegistry.js +0 -247
  53. package/lib/EventPluginUtils.js +0 -229
  54. package/lib/EventPropagators.js +0 -137
  55. package/lib/FallbackCompositionState.js +0 -95
  56. package/lib/HTMLDOMPropertyConfig.js +0 -209
  57. package/lib/LinkedValueUtils.js +0 -136
  58. package/lib/NativeMethodsMixin.js +0 -167
  59. package/lib/ReactBrowserEventEmitter.js +0 -317
  60. package/lib/ReactChildReconciler.js +0 -154
  61. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  62. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  63. package/lib/ReactComponentEnvironment.js +0 -45
  64. package/lib/ReactComponentTreeTestUtils.js +0 -87
  65. package/lib/ReactCompositeComponent.js +0 -920
  66. package/lib/ReactDOM.js +0 -110
  67. package/lib/ReactDOMButton.js +0 -24
  68. package/lib/ReactDOMComponent.js +0 -1005
  69. package/lib/ReactDOMComponentTree.js +0 -188
  70. package/lib/ReactDOMContainerInfo.js +0 -33
  71. package/lib/ReactDOMEmptyComponent.js +0 -60
  72. package/lib/ReactDOMFiber.js +0 -78
  73. package/lib/ReactDOMIDOperations.js +0 -34
  74. package/lib/ReactDOMInput.js +0 -269
  75. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  76. package/lib/ReactDOMOption.js +0 -123
  77. package/lib/ReactDOMSelect.js +0 -201
  78. package/lib/ReactDOMSelection.js +0 -212
  79. package/lib/ReactDOMServer.js +0 -26
  80. package/lib/ReactDOMTextComponent.js +0 -164
  81. package/lib/ReactDOMTextarea.js +0 -155
  82. package/lib/ReactDOMTreeTraversal.js +0 -136
  83. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  84. package/lib/ReactDebugTool.js +0 -307
  85. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  86. package/lib/ReactDefaultInjection.js +0 -84
  87. package/lib/ReactEmptyComponent.js +0 -30
  88. package/lib/ReactErrorUtils.js +0 -76
  89. package/lib/ReactEventEmitterMixin.js +0 -33
  90. package/lib/ReactEventListener.js +0 -157
  91. package/lib/ReactFeatureFlags.js +0 -22
  92. package/lib/ReactHostComponent.js +0 -76
  93. package/lib/ReactHostOperationHistoryHook.js +0 -37
  94. package/lib/ReactInjection.js +0 -36
  95. package/lib/ReactInputSelection.js +0 -124
  96. package/lib/ReactInstanceHandles.js +0 -302
  97. package/lib/ReactInstanceMap.js +0 -48
  98. package/lib/ReactInstrumentation.js +0 -21
  99. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  100. package/lib/ReactMarkupChecksum.js +0 -50
  101. package/lib/ReactMount.js +0 -495
  102. package/lib/ReactMultiChild.js +0 -451
  103. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  104. package/lib/ReactNative.js +0 -71
  105. package/lib/ReactNativeAttributePayload.js +0 -371
  106. package/lib/ReactNativeBaseComponent.js +0 -198
  107. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  108. package/lib/ReactNativeComponentEnvironment.js +0 -31
  109. package/lib/ReactNativeComponentTree.js +0 -68
  110. package/lib/ReactNativeContainerInfo.js +0 -21
  111. package/lib/ReactNativeDOMIDOperations.js +0 -79
  112. package/lib/ReactNativeDefaultInjection.js +0 -101
  113. package/lib/ReactNativeEventEmitter.js +0 -191
  114. package/lib/ReactNativeEventPluginOrder.js +0 -16
  115. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  116. package/lib/ReactNativeMount.js +0 -193
  117. package/lib/ReactNativePropRegistry.js +0 -52
  118. package/lib/ReactNativeReconcileTransaction.js +0 -116
  119. package/lib/ReactNativeTagHandles.js +0 -56
  120. package/lib/ReactNativeTextComponent.js +0 -71
  121. package/lib/ReactNativeTreeTraversal.js +0 -127
  122. package/lib/ReactNodeTypes.js +0 -40
  123. package/lib/ReactNoop.js +0 -173
  124. package/lib/ReactOwner.js +0 -94
  125. package/lib/ReactPerf.js +0 -494
  126. package/lib/ReactReconcileTransaction.js +0 -178
  127. package/lib/ReactReconciler.js +0 -168
  128. package/lib/ReactRef.js +0 -80
  129. package/lib/ReactServerBatchingStrategy.js +0 -22
  130. package/lib/ReactServerRendering.js +0 -90
  131. package/lib/ReactServerRenderingTransaction.js +0 -90
  132. package/lib/ReactServerUpdateQueue.js +0 -141
  133. package/lib/ReactSimpleEmptyComponent.js +0 -37
  134. package/lib/ReactTestMount.js +0 -123
  135. package/lib/ReactTestReconcileTransaction.js +0 -108
  136. package/lib/ReactTestRenderer.js +0 -144
  137. package/lib/ReactTestUtils.js +0 -518
  138. package/lib/ReactUpdateQueue.js +0 -226
  139. package/lib/ReactUpdates.js +0 -251
  140. package/lib/ResponderEventPlugin.js +0 -510
  141. package/lib/ResponderSyntheticEvent.js +0 -39
  142. package/lib/ResponderTouchHistoryStore.js +0 -184
  143. package/lib/SVGDOMPropertyConfig.js +0 -302
  144. package/lib/SelectEventPlugin.js +0 -196
  145. package/lib/SimpleEventPlugin.js +0 -635
  146. package/lib/SyntheticAnimationEvent.js +0 -39
  147. package/lib/SyntheticClipboardEvent.js +0 -38
  148. package/lib/SyntheticCompositionEvent.js +0 -36
  149. package/lib/SyntheticDragEvent.js +0 -36
  150. package/lib/SyntheticEvent.js +0 -267
  151. package/lib/SyntheticFocusEvent.js +0 -36
  152. package/lib/SyntheticInputEvent.js +0 -37
  153. package/lib/SyntheticKeyboardEvent.js +0 -84
  154. package/lib/SyntheticMouseEvent.js +0 -72
  155. package/lib/SyntheticTouchEvent.js +0 -45
  156. package/lib/SyntheticTransitionEvent.js +0 -39
  157. package/lib/SyntheticUIEvent.js +0 -59
  158. package/lib/SyntheticWheelEvent.js +0 -54
  159. package/lib/TapEventPlugin.js +0 -110
  160. package/lib/TouchHistoryMath.js +0 -99
  161. package/lib/Transaction.js +0 -233
  162. package/lib/ViewportMetrics.js +0 -27
  163. package/lib/accumulate.js +0 -46
  164. package/lib/accumulateInto.js +0 -58
  165. package/lib/adler32.js +0 -44
  166. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  167. package/lib/createReactNativeComponentClass.js +0 -42
  168. package/lib/dangerousStyleValue.js +0 -79
  169. package/lib/escapeTextContentForBrowser.js +0 -122
  170. package/lib/findDOMNode.js +0 -60
  171. package/lib/findNodeHandle.js +0 -91
  172. package/lib/forEachAccumulated.js +0 -31
  173. package/lib/getEventCharCode.js +0 -50
  174. package/lib/getEventKey.js +0 -102
  175. package/lib/getEventModifierState.js +0 -43
  176. package/lib/getEventTarget.js +0 -35
  177. package/lib/getHostComponentFromComposite.js +0 -30
  178. package/lib/getNodeForCharacterOffset.js +0 -74
  179. package/lib/getTestDocument.js +0 -21
  180. package/lib/getTextContentAccessor.js +0 -33
  181. package/lib/getVendorPrefixedEventName.js +0 -101
  182. package/lib/instantiateReactComponent.js +0 -119
  183. package/lib/isEventSupported.js +0 -60
  184. package/lib/isTextInputElement.js +0 -51
  185. package/lib/quoteAttributeValueForBrowser.js +0 -26
  186. package/lib/reactComponentExpect.js +0 -217
  187. package/lib/setInnerHTML.js +0 -98
  188. package/lib/setTextContent.js +0 -48
  189. package/lib/shouldUpdateReactComponent.js +0 -42
  190. package/lib/validateDOMNesting.js +0 -369
@@ -1,154 +0,0 @@
1
- /**
2
- * Copyright 2014-present, 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 ReactChildReconciler
10
- */
11
-
12
- 'use strict';
13
-
14
- var ReactReconciler = require('./ReactReconciler');
15
-
16
- var instantiateReactComponent = require('./instantiateReactComponent');
17
- var KeyEscapeUtils = require('./KeyEscapeUtils');
18
- var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
19
- var traverseAllChildren = require('./traverseAllChildren');
20
- var warning = require('fbjs/lib/warning');
21
-
22
- var ReactComponentTreeHook;
23
-
24
- if (typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'test') {
25
- // Temporary hack.
26
- // Inline requires don't work well with Jest:
27
- // https://github.com/facebook/react/issues/7240
28
- // Remove the inline requires when we don't need them anymore:
29
- // https://github.com/facebook/react/pull/7178
30
- ReactComponentTreeHook = require('./ReactComponentTreeHook');
31
- }
32
-
33
- function instantiateChild(childInstances, child, name, selfDebugID) {
34
- // We found a component instance.
35
- var keyUnique = childInstances[name] === undefined;
36
- if (process.env.NODE_ENV !== 'production') {
37
- if (!ReactComponentTreeHook) {
38
- ReactComponentTreeHook = require('./ReactComponentTreeHook');
39
- }
40
- if (!keyUnique) {
41
- process.env.NODE_ENV !== 'production' ? warning(false, 'flattenChildren(...): Encountered two children with the same key, ' + '`%s`. Child keys must be unique; when two children share a key, only ' + 'the first child will be used.%s', KeyEscapeUtils.unescape(name), ReactComponentTreeHook.getStackAddendumByID(selfDebugID)) : void 0;
42
- }
43
- }
44
- if (child != null && keyUnique) {
45
- childInstances[name] = instantiateReactComponent(child, true);
46
- }
47
- }
48
-
49
- /**
50
- * ReactChildReconciler provides helpers for initializing or updating a set of
51
- * children. Its output is suitable for passing it onto ReactMultiChild which
52
- * does diffed reordering and insertion.
53
- */
54
- var ReactChildReconciler = {
55
- /**
56
- * Generates a "mount image" for each of the supplied children. In the case
57
- * of `ReactDOMComponent`, a mount image is a string of markup.
58
- *
59
- * @param {?object} nestedChildNodes Nested child maps.
60
- * @return {?object} A set of child instances.
61
- * @internal
62
- */
63
- instantiateChildren: function (nestedChildNodes, transaction, context, selfDebugID // 0 in production and for roots
64
- ) {
65
- if (nestedChildNodes == null) {
66
- return null;
67
- }
68
- var childInstances = {};
69
-
70
- if (process.env.NODE_ENV !== 'production') {
71
- traverseAllChildren(nestedChildNodes, function (childInsts, child, name) {
72
- return instantiateChild(childInsts, child, name, selfDebugID);
73
- }, childInstances);
74
- } else {
75
- traverseAllChildren(nestedChildNodes, instantiateChild, childInstances);
76
- }
77
- return childInstances;
78
- },
79
-
80
- /**
81
- * Updates the rendered children and returns a new set of children.
82
- *
83
- * @param {?object} prevChildren Previously initialized set of children.
84
- * @param {?object} nextChildren Flat child element maps.
85
- * @param {ReactReconcileTransaction} transaction
86
- * @param {object} context
87
- * @return {?object} A new set of child instances.
88
- * @internal
89
- */
90
- updateChildren: function (prevChildren, nextChildren, mountImages, removedNodes, transaction, hostParent, hostContainerInfo, context, selfDebugID // 0 in production and for roots
91
- ) {
92
- // We currently don't have a way to track moves here but if we use iterators
93
- // instead of for..in we can zip the iterators and check if an item has
94
- // moved.
95
- // TODO: If nothing has changed, return the prevChildren object so that we
96
- // can quickly bailout if nothing has changed.
97
- if (!nextChildren && !prevChildren) {
98
- return;
99
- }
100
- var name;
101
- var prevChild;
102
- for (name in nextChildren) {
103
- if (!nextChildren.hasOwnProperty(name)) {
104
- continue;
105
- }
106
- prevChild = prevChildren && prevChildren[name];
107
- var prevElement = prevChild && prevChild._currentElement;
108
- var nextElement = nextChildren[name];
109
- if (prevChild != null && shouldUpdateReactComponent(prevElement, nextElement)) {
110
- ReactReconciler.receiveComponent(prevChild, nextElement, transaction, context);
111
- nextChildren[name] = prevChild;
112
- } else {
113
- if (prevChild) {
114
- removedNodes[name] = ReactReconciler.getHostNode(prevChild);
115
- ReactReconciler.unmountComponent(prevChild, false);
116
- }
117
- // The child must be instantiated before it's mounted.
118
- var nextChildInstance = instantiateReactComponent(nextElement, true);
119
- nextChildren[name] = nextChildInstance;
120
- // Creating mount image now ensures refs are resolved in right order
121
- // (see https://github.com/facebook/react/pull/7101 for explanation).
122
- var nextChildMountImage = ReactReconciler.mountComponent(nextChildInstance, transaction, hostParent, hostContainerInfo, context, selfDebugID);
123
- mountImages.push(nextChildMountImage);
124
- }
125
- }
126
- // Unmount children that are no longer present.
127
- for (name in prevChildren) {
128
- if (prevChildren.hasOwnProperty(name) && !(nextChildren && nextChildren.hasOwnProperty(name))) {
129
- prevChild = prevChildren[name];
130
- removedNodes[name] = ReactReconciler.getHostNode(prevChild);
131
- ReactReconciler.unmountComponent(prevChild, false);
132
- }
133
- }
134
- },
135
-
136
- /**
137
- * Unmounts all rendered children. This should be used to clean up children
138
- * when this component is unmounted.
139
- *
140
- * @param {?object} renderedChildren Previously initialized set of children.
141
- * @internal
142
- */
143
- unmountChildren: function (renderedChildren, safely) {
144
- for (var name in renderedChildren) {
145
- if (renderedChildren.hasOwnProperty(name)) {
146
- var renderedChild = renderedChildren[name];
147
- ReactReconciler.unmountComponent(renderedChild, safely);
148
- }
149
- }
150
- }
151
-
152
- };
153
-
154
- module.exports = ReactChildReconciler;
@@ -1,54 +0,0 @@
1
- /**
2
- * Copyright 2013-present, 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 ReactChildrenMutationWarningHook
10
- */
11
-
12
- 'use strict';
13
-
14
- var ReactComponentTreeHook = require('./ReactComponentTreeHook');
15
-
16
- var warning = require('fbjs/lib/warning');
17
-
18
- function handleElement(debugID, element) {
19
- if (element == null) {
20
- return;
21
- }
22
- if (element._shadowChildren === undefined) {
23
- return;
24
- }
25
- if (element._shadowChildren === element.props.children) {
26
- return;
27
- }
28
- var isMutated = false;
29
- if (Array.isArray(element._shadowChildren)) {
30
- if (element._shadowChildren.length === element.props.children.length) {
31
- for (var i = 0; i < element._shadowChildren.length; i++) {
32
- if (element._shadowChildren[i] !== element.props.children[i]) {
33
- isMutated = true;
34
- }
35
- }
36
- } else {
37
- isMutated = true;
38
- }
39
- }
40
- if (!Array.isArray(element._shadowChildren) || isMutated) {
41
- process.env.NODE_ENV !== 'production' ? warning(false, 'Component\'s children should not be mutated.%s', ReactComponentTreeHook.getStackAddendumByID(debugID)) : void 0;
42
- }
43
- }
44
-
45
- var ReactChildrenMutationWarningHook = {
46
- onMountComponent: function (debugID) {
47
- handleElement(debugID, ReactComponentTreeHook.getElement(debugID));
48
- },
49
- onUpdateComponent: function (debugID) {
50
- handleElement(debugID, ReactComponentTreeHook.getElement(debugID));
51
- }
52
- };
53
-
54
- module.exports = ReactChildrenMutationWarningHook;
@@ -1,30 +0,0 @@
1
- /**
2
- * Copyright 2013-present, 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 ReactComponentBrowserEnvironment
10
- */
11
-
12
- 'use strict';
13
-
14
- var DOMChildrenOperations = require('./DOMChildrenOperations');
15
- var ReactDOMIDOperations = require('./ReactDOMIDOperations');
16
-
17
- /**
18
- * Abstracts away all functionality of the reconciler that requires knowledge of
19
- * the browser context. TODO: These callers should be refactored to avoid the
20
- * need for this injection.
21
- */
22
- var ReactComponentBrowserEnvironment = {
23
-
24
- processChildrenUpdates: ReactDOMIDOperations.dangerouslyProcessChildrenUpdates,
25
-
26
- replaceNodeWithMarkup: DOMChildrenOperations.dangerouslyReplaceNodeWithMarkup
27
-
28
- };
29
-
30
- module.exports = ReactComponentBrowserEnvironment;
@@ -1,45 +0,0 @@
1
- /**
2
- * Copyright 2014-present, 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 ReactComponentEnvironment
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant');
15
-
16
- var invariant = require('fbjs/lib/invariant');
17
-
18
- var injected = false;
19
-
20
- var ReactComponentEnvironment = {
21
-
22
- /**
23
- * Optionally injectable hook for swapping out mount images in the middle of
24
- * the tree.
25
- */
26
- replaceNodeWithMarkup: null,
27
-
28
- /**
29
- * Optionally injectable hook for processing a queue of child updates. Will
30
- * later move into MultiChildComponents.
31
- */
32
- processChildrenUpdates: null,
33
-
34
- injection: {
35
- injectEnvironment: function (environment) {
36
- !!injected ? process.env.NODE_ENV !== 'production' ? invariant(false, 'ReactCompositeComponent: injectEnvironment() can only be called once.') : _prodInvariant('104') : void 0;
37
- ReactComponentEnvironment.replaceNodeWithMarkup = environment.replaceNodeWithMarkup;
38
- ReactComponentEnvironment.processChildrenUpdates = environment.processChildrenUpdates;
39
- injected = true;
40
- }
41
- }
42
-
43
- };
44
-
45
- module.exports = ReactComponentEnvironment;
@@ -1,87 +0,0 @@
1
- /**
2
- * Copyright 2016-present, 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 ReactComponentTreeTestUtils
10
- */
11
-
12
- 'use strict';
13
-
14
- var _assign = require('object-assign');
15
-
16
- var _extends = _assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
17
-
18
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
-
20
- var ReactComponentTreeHook = require('./ReactComponentTreeHook');
21
-
22
- function getRootDisplayNames() {
23
- return ReactComponentTreeHook.getRootIDs().map(ReactComponentTreeHook.getDisplayName);
24
- }
25
-
26
- function getRegisteredDisplayNames() {
27
- return ReactComponentTreeHook.getRegisteredIDs().map(ReactComponentTreeHook.getDisplayName);
28
- }
29
-
30
- function expectTree(rootID, expectedTree, parentPath) {
31
- var displayName = ReactComponentTreeHook.getDisplayName(rootID);
32
- var ownerID = ReactComponentTreeHook.getOwnerID(rootID);
33
- var parentID = ReactComponentTreeHook.getParentID(rootID);
34
- var childIDs = ReactComponentTreeHook.getChildIDs(rootID);
35
- var text = ReactComponentTreeHook.getText(rootID);
36
- var element = ReactComponentTreeHook.getElement(rootID);
37
- var path = parentPath ? parentPath + ' > ' + displayName : displayName;
38
-
39
- function expectEqual(actual, expected, name) {
40
- // Get Jasmine to print descriptive error messages.
41
- // We pass path so that we know where the mismatch occurred.
42
- expect(_defineProperty({
43
- path: path
44
- }, name, actual)).toEqual(_defineProperty({
45
- path: path
46
- }, name, expected));
47
- }
48
-
49
- if (expectedTree.parentDisplayName !== undefined) {
50
- expectEqual(ReactComponentTreeHook.getDisplayName(parentID), expectedTree.parentDisplayName, 'parentDisplayName');
51
- }
52
- if (expectedTree.ownerDisplayName !== undefined) {
53
- expectEqual(ReactComponentTreeHook.getDisplayName(ownerID), expectedTree.ownerDisplayName, 'ownerDisplayName');
54
- }
55
- if (expectedTree.parentID !== undefined) {
56
- expectEqual(parentID, expectedTree.parentID, 'parentID');
57
- }
58
- if (expectedTree.text !== undefined) {
59
- expectEqual(text, expectedTree.text, 'text');
60
- expectEqual('' + element, expectedTree.text, 'element.toString()');
61
- } else {
62
- expectEqual(text, null, 'text');
63
- }
64
- if (expectedTree.element !== undefined) {
65
- // TODO: Comparing elements makes tests run out of memory on errors.
66
- // For now, compare just types.
67
- expectEqual(element && element.type, expectedTree.element && expectedTree.element.type, 'element.type');
68
- } else if (text == null) {
69
- expectEqual(typeof element, 'object', 'typeof element');
70
- }
71
- if (expectedTree.children !== undefined) {
72
- expectEqual(childIDs.length, expectedTree.children.length, 'children.length');
73
- for (var i = 0; i < childIDs.length; i++) {
74
- expectTree(childIDs[i], _extends({ parentID: rootID }, expectedTree.children[i]), path);
75
- }
76
- } else {
77
- expectEqual(childIDs, [], 'childIDs');
78
- }
79
- }
80
-
81
- var ReactComponentTreeTestUtils = {
82
- expectTree: expectTree,
83
- getRootDisplayNames: getRootDisplayNames,
84
- getRegisteredDisplayNames: getRegisteredDisplayNames
85
- };
86
-
87
- module.exports = ReactComponentTreeTestUtils;
@@ -1,920 +0,0 @@
1
- /**
2
- * Copyright 2013-present, 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 ReactCompositeComponent
10
- */
11
-
12
- 'use strict';
13
-
14
- var _prodInvariant = require('./reactProdInvariant'),
15
- _assign = require('object-assign');
16
-
17
- var ReactComponentEnvironment = require('./ReactComponentEnvironment');
18
- var ReactCurrentOwner = require('./ReactCurrentOwner');
19
- var ReactElement = require('./ReactElement');
20
- var ReactErrorUtils = require('./ReactErrorUtils');
21
- var ReactInstanceMap = require('./ReactInstanceMap');
22
- var ReactInstrumentation = require('./ReactInstrumentation');
23
- var ReactNodeTypes = require('./ReactNodeTypes');
24
- var ReactPropTypeLocations = require('./ReactPropTypeLocations');
25
- var ReactReconciler = require('./ReactReconciler');
26
-
27
- var checkReactTypeSpec = require('./checkReactTypeSpec');
28
- var emptyObject = require('fbjs/lib/emptyObject');
29
- var invariant = require('fbjs/lib/invariant');
30
- var shallowEqual = require('fbjs/lib/shallowEqual');
31
- var shouldUpdateReactComponent = require('./shouldUpdateReactComponent');
32
- var warning = require('fbjs/lib/warning');
33
-
34
- var CompositeTypes = {
35
- ImpureClass: 0,
36
- PureClass: 1,
37
- StatelessFunctional: 2
38
- };
39
-
40
- function StatelessComponent(Component) {}
41
- StatelessComponent.prototype.render = function () {
42
- var Component = ReactInstanceMap.get(this)._currentElement.type;
43
- var element = Component(this.props, this.context, this.updater);
44
- warnIfInvalidElement(Component, element);
45
- return element;
46
- };
47
-
48
- function warnIfInvalidElement(Component, element) {
49
- if (process.env.NODE_ENV !== 'production') {
50
- process.env.NODE_ENV !== 'production' ? warning(element === null || element === false || ReactElement.isValidElement(element), '%s(...): A valid React element (or null) must be returned. You may have ' + 'returned undefined, an array or some other invalid object.', Component.displayName || Component.name || 'Component') : void 0;
51
- process.env.NODE_ENV !== 'production' ? warning(!Component.childContextTypes, '%s(...): childContextTypes cannot be defined on a functional component.', Component.displayName || Component.name || 'Component') : void 0;
52
- }
53
- }
54
-
55
- function invokeComponentDidMountWithTimer() {
56
- var publicInstance = this._instance;
57
- if (this._debugID !== 0) {
58
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'componentDidMount');
59
- }
60
- publicInstance.componentDidMount();
61
- if (this._debugID !== 0) {
62
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'componentDidMount');
63
- }
64
- }
65
-
66
- function invokeComponentDidUpdateWithTimer(prevProps, prevState, prevContext) {
67
- var publicInstance = this._instance;
68
- if (this._debugID !== 0) {
69
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'componentDidUpdate');
70
- }
71
- publicInstance.componentDidUpdate(prevProps, prevState, prevContext);
72
- if (this._debugID !== 0) {
73
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'componentDidUpdate');
74
- }
75
- }
76
-
77
- function shouldConstruct(Component) {
78
- return !!(Component.prototype && Component.prototype.isReactComponent);
79
- }
80
-
81
- function isPureComponent(Component) {
82
- return !!(Component.prototype && Component.prototype.isPureReactComponent);
83
- }
84
-
85
- /**
86
- * ------------------ The Life-Cycle of a Composite Component ------------------
87
- *
88
- * - constructor: Initialization of state. The instance is now retained.
89
- * - componentWillMount
90
- * - render
91
- * - [children's constructors]
92
- * - [children's componentWillMount and render]
93
- * - [children's componentDidMount]
94
- * - componentDidMount
95
- *
96
- * Update Phases:
97
- * - componentWillReceiveProps (only called if parent updated)
98
- * - shouldComponentUpdate
99
- * - componentWillUpdate
100
- * - render
101
- * - [children's constructors or receive props phases]
102
- * - componentDidUpdate
103
- *
104
- * - componentWillUnmount
105
- * - [children's componentWillUnmount]
106
- * - [children destroyed]
107
- * - (destroyed): The instance is now blank, released by React and ready for GC.
108
- *
109
- * -----------------------------------------------------------------------------
110
- */
111
-
112
- /**
113
- * An incrementing ID assigned to each component when it is mounted. This is
114
- * used to enforce the order in which `ReactUpdates` updates dirty components.
115
- *
116
- * @private
117
- */
118
- var nextMountID = 1;
119
-
120
- /**
121
- * @lends {ReactCompositeComponent.prototype}
122
- */
123
- var ReactCompositeComponentMixin = {
124
-
125
- /**
126
- * Base constructor for all composite component.
127
- *
128
- * @param {ReactElement} element
129
- * @final
130
- * @internal
131
- */
132
- construct: function (element) {
133
- this._currentElement = element;
134
- this._rootNodeID = 0;
135
- this._compositeType = null;
136
- this._instance = null;
137
- this._hostParent = null;
138
- this._hostContainerInfo = null;
139
-
140
- // See ReactUpdateQueue
141
- this._updateBatchNumber = null;
142
- this._pendingElement = null;
143
- this._pendingStateQueue = null;
144
- this._pendingReplaceState = false;
145
- this._pendingForceUpdate = false;
146
-
147
- this._renderedNodeType = null;
148
- this._renderedComponent = null;
149
- this._context = null;
150
- this._mountOrder = 0;
151
- this._topLevelWrapper = null;
152
-
153
- // See ReactUpdates and ReactUpdateQueue.
154
- this._pendingCallbacks = null;
155
-
156
- // ComponentWillUnmount shall only be called once
157
- this._calledComponentWillUnmount = false;
158
-
159
- if (process.env.NODE_ENV !== 'production') {
160
- this._warnedAboutRefsInRender = false;
161
- }
162
- },
163
-
164
- /**
165
- * Initializes the component, renders markup, and registers event listeners.
166
- *
167
- * @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
168
- * @param {?object} hostParent
169
- * @param {?object} hostContainerInfo
170
- * @param {?object} context
171
- * @return {?string} Rendered markup to be inserted into the DOM.
172
- * @final
173
- * @internal
174
- */
175
- mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
176
- this._context = context;
177
- this._mountOrder = nextMountID++;
178
- this._hostParent = hostParent;
179
- this._hostContainerInfo = hostContainerInfo;
180
-
181
- var publicProps = this._currentElement.props;
182
- var publicContext = this._processContext(context);
183
-
184
- var Component = this._currentElement.type;
185
-
186
- var updateQueue = transaction.getUpdateQueue();
187
-
188
- // Initialize the public class
189
- var doConstruct = shouldConstruct(Component);
190
- var inst = this._constructComponent(doConstruct, publicProps, publicContext, updateQueue);
191
- var renderedElement;
192
-
193
- // Support functional components
194
- if (!doConstruct && (inst == null || inst.render == null)) {
195
- renderedElement = inst;
196
- warnIfInvalidElement(Component, renderedElement);
197
- !(inst === null || inst === false || ReactElement.isValidElement(inst)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s(...): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.', Component.displayName || Component.name || 'Component') : _prodInvariant('105', Component.displayName || Component.name || 'Component') : void 0;
198
- inst = new StatelessComponent(Component);
199
- this._compositeType = CompositeTypes.StatelessFunctional;
200
- } else {
201
- if (isPureComponent(Component)) {
202
- this._compositeType = CompositeTypes.PureClass;
203
- } else {
204
- this._compositeType = CompositeTypes.ImpureClass;
205
- }
206
- }
207
-
208
- if (process.env.NODE_ENV !== 'production') {
209
- // This will throw later in _renderValidatedComponent, but add an early
210
- // warning now to help debugging
211
- if (inst.render == null) {
212
- process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): No `render` method found on the returned component ' + 'instance: you may have forgotten to define `render`.', Component.displayName || Component.name || 'Component') : void 0;
213
- }
214
-
215
- var propsMutated = inst.props !== publicProps;
216
- var componentName = Component.displayName || Component.name || 'Component';
217
-
218
- process.env.NODE_ENV !== 'production' ? warning(inst.props === undefined || !propsMutated, '%s(...): When calling super() in `%s`, make sure to pass ' + 'up the same props that your component\'s constructor was passed.', componentName, componentName) : void 0;
219
- }
220
-
221
- // These should be set up in the constructor, but as a convenience for
222
- // simpler class abstractions, we set them up after the fact.
223
- inst.props = publicProps;
224
- inst.context = publicContext;
225
- inst.refs = emptyObject;
226
- inst.updater = updateQueue;
227
-
228
- this._instance = inst;
229
-
230
- // Store a reference from the instance back to the internal representation
231
- ReactInstanceMap.set(inst, this);
232
-
233
- if (process.env.NODE_ENV !== 'production') {
234
- // Since plain JS classes are defined without any special initialization
235
- // logic, we can not catch common errors early. Therefore, we have to
236
- // catch them here, at initialization time, instead.
237
- process.env.NODE_ENV !== 'production' ? warning(!inst.getInitialState || inst.getInitialState.isReactClassApproved, 'getInitialState was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Did you mean to define a state property instead?', this.getName() || 'a component') : void 0;
238
- process.env.NODE_ENV !== 'production' ? warning(!inst.getDefaultProps || inst.getDefaultProps.isReactClassApproved, 'getDefaultProps was defined on %s, a plain JavaScript class. ' + 'This is only supported for classes created using React.createClass. ' + 'Use a static property to define defaultProps instead.', this.getName() || 'a component') : void 0;
239
- process.env.NODE_ENV !== 'production' ? warning(!inst.propTypes, 'propTypes was defined as an instance property on %s. Use a static ' + 'property to define propTypes instead.', this.getName() || 'a component') : void 0;
240
- process.env.NODE_ENV !== 'production' ? warning(!inst.contextTypes, 'contextTypes was defined as an instance property on %s. Use a ' + 'static property to define contextTypes instead.', this.getName() || 'a component') : void 0;
241
- process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentShouldUpdate !== 'function', '%s has a method called ' + 'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' + 'The name is phrased as a question because the function is ' + 'expected to return a value.', this.getName() || 'A component') : void 0;
242
- process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentDidUnmount !== 'function', '%s has a method called ' + 'componentDidUnmount(). But there is no such lifecycle method. ' + 'Did you mean componentWillUnmount()?', this.getName() || 'A component') : void 0;
243
- process.env.NODE_ENV !== 'production' ? warning(typeof inst.componentWillRecieveProps !== 'function', '%s has a method called ' + 'componentWillRecieveProps(). Did you mean componentWillReceiveProps()?', this.getName() || 'A component') : void 0;
244
- }
245
-
246
- var initialState = inst.state;
247
- if (initialState === undefined) {
248
- inst.state = initialState = null;
249
- }
250
- !(typeof initialState === 'object' && !Array.isArray(initialState)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.state: must be set to an object or null', this.getName() || 'ReactCompositeComponent') : _prodInvariant('106', this.getName() || 'ReactCompositeComponent') : void 0;
251
-
252
- this._pendingStateQueue = null;
253
- this._pendingReplaceState = false;
254
- this._pendingForceUpdate = false;
255
-
256
- var markup;
257
- if (inst.unstable_handleError) {
258
- markup = this.performInitialMountWithErrorHandling(renderedElement, hostParent, hostContainerInfo, transaction, context);
259
- } else {
260
- markup = this.performInitialMount(renderedElement, hostParent, hostContainerInfo, transaction, context);
261
- }
262
-
263
- if (inst.componentDidMount) {
264
- if (process.env.NODE_ENV !== 'production') {
265
- transaction.getReactMountReady().enqueue(invokeComponentDidMountWithTimer, this);
266
- } else {
267
- transaction.getReactMountReady().enqueue(inst.componentDidMount, inst);
268
- }
269
- }
270
-
271
- return markup;
272
- },
273
-
274
- _constructComponent: function (doConstruct, publicProps, publicContext, updateQueue) {
275
- if (process.env.NODE_ENV !== 'production') {
276
- ReactCurrentOwner.current = this;
277
- try {
278
- return this._constructComponentWithoutOwner(doConstruct, publicProps, publicContext, updateQueue);
279
- } finally {
280
- ReactCurrentOwner.current = null;
281
- }
282
- } else {
283
- return this._constructComponentWithoutOwner(doConstruct, publicProps, publicContext, updateQueue);
284
- }
285
- },
286
-
287
- _constructComponentWithoutOwner: function (doConstruct, publicProps, publicContext, updateQueue) {
288
- var Component = this._currentElement.type;
289
- var instanceOrElement;
290
- if (doConstruct) {
291
- if (process.env.NODE_ENV !== 'production') {
292
- if (this._debugID !== 0) {
293
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'ctor');
294
- }
295
- }
296
- instanceOrElement = new Component(publicProps, publicContext, updateQueue);
297
- if (process.env.NODE_ENV !== 'production') {
298
- if (this._debugID !== 0) {
299
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'ctor');
300
- }
301
- }
302
- } else {
303
- // This can still be an instance in case of factory components
304
- // but we'll count this as time spent rendering as the more common case.
305
- if (process.env.NODE_ENV !== 'production') {
306
- if (this._debugID !== 0) {
307
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'render');
308
- }
309
- }
310
- instanceOrElement = Component(publicProps, publicContext, updateQueue);
311
- if (process.env.NODE_ENV !== 'production') {
312
- if (this._debugID !== 0) {
313
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'render');
314
- }
315
- }
316
- }
317
- return instanceOrElement;
318
- },
319
-
320
- performInitialMountWithErrorHandling: function (renderedElement, hostParent, hostContainerInfo, transaction, context) {
321
- var markup;
322
- var checkpoint = transaction.checkpoint();
323
- try {
324
- markup = this.performInitialMount(renderedElement, hostParent, hostContainerInfo, transaction, context);
325
- } catch (e) {
326
- if (process.env.NODE_ENV !== 'production') {
327
- if (this._debugID !== 0) {
328
- ReactInstrumentation.debugTool.onError();
329
- }
330
- }
331
- // Roll back to checkpoint, handle error (which may add items to the transaction), and take a new checkpoint
332
- transaction.rollback(checkpoint);
333
- this._instance.unstable_handleError(e);
334
- if (this._pendingStateQueue) {
335
- this._instance.state = this._processPendingState(this._instance.props, this._instance.context);
336
- }
337
- checkpoint = transaction.checkpoint();
338
-
339
- this._renderedComponent.unmountComponent(true);
340
- transaction.rollback(checkpoint);
341
-
342
- // Try again - we've informed the component about the error, so they can render an error message this time.
343
- // If this throws again, the error will bubble up (and can be caught by a higher error boundary).
344
- markup = this.performInitialMount(renderedElement, hostParent, hostContainerInfo, transaction, context);
345
- }
346
- return markup;
347
- },
348
-
349
- performInitialMount: function (renderedElement, hostParent, hostContainerInfo, transaction, context) {
350
- var inst = this._instance;
351
- if (inst.componentWillMount) {
352
- if (process.env.NODE_ENV !== 'production') {
353
- if (this._debugID !== 0) {
354
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'componentWillMount');
355
- }
356
- }
357
- inst.componentWillMount();
358
- if (process.env.NODE_ENV !== 'production') {
359
- if (this._debugID !== 0) {
360
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'componentWillMount');
361
- }
362
- }
363
- // When mounting, calls to `setState` by `componentWillMount` will set
364
- // `this._pendingStateQueue` without triggering a re-render.
365
- if (this._pendingStateQueue) {
366
- inst.state = this._processPendingState(inst.props, inst.context);
367
- }
368
- }
369
-
370
- // If not a stateless component, we now render
371
- if (renderedElement === undefined) {
372
- renderedElement = this._renderValidatedComponent();
373
- }
374
-
375
- var nodeType = ReactNodeTypes.getType(renderedElement);
376
- this._renderedNodeType = nodeType;
377
- var child = this._instantiateReactComponent(renderedElement, nodeType !== ReactNodeTypes.EMPTY /* shouldHaveDebugID */
378
- );
379
- this._renderedComponent = child;
380
-
381
- var selfDebugID = 0;
382
- if (process.env.NODE_ENV !== 'production') {
383
- selfDebugID = this._debugID;
384
- }
385
- var markup = ReactReconciler.mountComponent(child, transaction, hostParent, hostContainerInfo, this._processChildContext(context), selfDebugID);
386
-
387
- if (process.env.NODE_ENV !== 'production') {
388
- if (this._debugID !== 0) {
389
- ReactInstrumentation.debugTool.onSetChildren(this._debugID, child._debugID !== 0 ? [child._debugID] : []);
390
- }
391
- }
392
-
393
- return markup;
394
- },
395
-
396
- getHostNode: function () {
397
- return ReactReconciler.getHostNode(this._renderedComponent);
398
- },
399
-
400
- /**
401
- * Releases any resources allocated by `mountComponent`.
402
- *
403
- * @final
404
- * @internal
405
- */
406
- unmountComponent: function (safely) {
407
- if (!this._renderedComponent) {
408
- return;
409
- }
410
- var inst = this._instance;
411
-
412
- if (inst.componentWillUnmount && !inst._calledComponentWillUnmount) {
413
- inst._calledComponentWillUnmount = true;
414
- if (process.env.NODE_ENV !== 'production') {
415
- if (this._debugID !== 0) {
416
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'componentWillUnmount');
417
- }
418
- }
419
- if (safely) {
420
- var name = this.getName() + '.componentWillUnmount()';
421
- ReactErrorUtils.invokeGuardedCallback(name, inst.componentWillUnmount.bind(inst));
422
- } else {
423
- inst.componentWillUnmount();
424
- }
425
- if (process.env.NODE_ENV !== 'production') {
426
- if (this._debugID !== 0) {
427
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'componentWillUnmount');
428
- }
429
- }
430
- }
431
-
432
- if (this._renderedComponent) {
433
- ReactReconciler.unmountComponent(this._renderedComponent, safely);
434
- this._renderedNodeType = null;
435
- this._renderedComponent = null;
436
- this._instance = null;
437
- }
438
-
439
- // Reset pending fields
440
- // Even if this component is scheduled for another update in ReactUpdates,
441
- // it would still be ignored because these fields are reset.
442
- this._pendingStateQueue = null;
443
- this._pendingReplaceState = false;
444
- this._pendingForceUpdate = false;
445
- this._pendingCallbacks = null;
446
- this._pendingElement = null;
447
-
448
- // These fields do not really need to be reset since this object is no
449
- // longer accessible.
450
- this._context = null;
451
- this._rootNodeID = 0;
452
- this._topLevelWrapper = null;
453
-
454
- // Delete the reference from the instance to this internal representation
455
- // which allow the internals to be properly cleaned up even if the user
456
- // leaks a reference to the public instance.
457
- ReactInstanceMap.remove(inst);
458
-
459
- // Some existing components rely on inst.props even after they've been
460
- // destroyed (in event handlers).
461
- // TODO: inst.props = null;
462
- // TODO: inst.state = null;
463
- // TODO: inst.context = null;
464
- },
465
-
466
- /**
467
- * Filters the context object to only contain keys specified in
468
- * `contextTypes`
469
- *
470
- * @param {object} context
471
- * @return {?object}
472
- * @private
473
- */
474
- _maskContext: function (context) {
475
- var Component = this._currentElement.type;
476
- var contextTypes = Component.contextTypes;
477
- if (!contextTypes) {
478
- return emptyObject;
479
- }
480
- var maskedContext = {};
481
- for (var contextName in contextTypes) {
482
- maskedContext[contextName] = context[contextName];
483
- }
484
- return maskedContext;
485
- },
486
-
487
- /**
488
- * Filters the context object to only contain keys specified in
489
- * `contextTypes`, and asserts that they are valid.
490
- *
491
- * @param {object} context
492
- * @return {?object}
493
- * @private
494
- */
495
- _processContext: function (context) {
496
- var maskedContext = this._maskContext(context);
497
- if (process.env.NODE_ENV !== 'production') {
498
- var Component = this._currentElement.type;
499
- if (Component.contextTypes) {
500
- this._checkContextTypes(Component.contextTypes, maskedContext, ReactPropTypeLocations.context);
501
- }
502
- }
503
- return maskedContext;
504
- },
505
-
506
- /**
507
- * @param {object} currentContext
508
- * @return {object}
509
- * @private
510
- */
511
- _processChildContext: function (currentContext) {
512
- var Component = this._currentElement.type;
513
- var inst = this._instance;
514
- if (process.env.NODE_ENV !== 'production') {
515
- ReactInstrumentation.debugTool.onBeginProcessingChildContext();
516
- }
517
- var childContext = inst.getChildContext && inst.getChildContext();
518
- if (process.env.NODE_ENV !== 'production') {
519
- ReactInstrumentation.debugTool.onEndProcessingChildContext();
520
- }
521
- if (childContext) {
522
- !(typeof Component.childContextTypes === 'object') ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): childContextTypes must be defined in order to use getChildContext().', this.getName() || 'ReactCompositeComponent') : _prodInvariant('107', this.getName() || 'ReactCompositeComponent') : void 0;
523
- if (process.env.NODE_ENV !== 'production') {
524
- this._checkContextTypes(Component.childContextTypes, childContext, ReactPropTypeLocations.childContext);
525
- }
526
- for (var name in childContext) {
527
- !(name in Component.childContextTypes) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.getChildContext(): key "%s" is not defined in childContextTypes.', this.getName() || 'ReactCompositeComponent', name) : _prodInvariant('108', this.getName() || 'ReactCompositeComponent', name) : void 0;
528
- }
529
- return _assign({}, currentContext, childContext);
530
- }
531
- return currentContext;
532
- },
533
-
534
- /**
535
- * Assert that the context types are valid
536
- *
537
- * @param {object} typeSpecs Map of context field to a ReactPropType
538
- * @param {object} values Runtime values that need to be type-checked
539
- * @param {string} location e.g. "prop", "context", "child context"
540
- * @private
541
- */
542
- _checkContextTypes: function (typeSpecs, values, location) {
543
- checkReactTypeSpec(typeSpecs, values, location, this.getName(), null, this._debugID);
544
- },
545
-
546
- receiveComponent: function (nextElement, transaction, nextContext) {
547
- var prevElement = this._currentElement;
548
- var prevContext = this._context;
549
-
550
- this._pendingElement = null;
551
-
552
- this.updateComponent(transaction, prevElement, nextElement, prevContext, nextContext);
553
- },
554
-
555
- /**
556
- * If any of `_pendingElement`, `_pendingStateQueue`, or `_pendingForceUpdate`
557
- * is set, update the component.
558
- *
559
- * @param {ReactReconcileTransaction} transaction
560
- * @internal
561
- */
562
- performUpdateIfNecessary: function (transaction) {
563
- if (this._pendingElement != null) {
564
- ReactReconciler.receiveComponent(this, this._pendingElement, transaction, this._context);
565
- } else if (this._pendingStateQueue !== null || this._pendingForceUpdate) {
566
- this.updateComponent(transaction, this._currentElement, this._currentElement, this._context, this._context);
567
- } else {
568
- this._updateBatchNumber = null;
569
- }
570
- },
571
-
572
- /**
573
- * Perform an update to a mounted component. The componentWillReceiveProps and
574
- * shouldComponentUpdate methods are called, then (assuming the update isn't
575
- * skipped) the remaining update lifecycle methods are called and the DOM
576
- * representation is updated.
577
- *
578
- * By default, this implements React's rendering and reconciliation algorithm.
579
- * Sophisticated clients may wish to override this.
580
- *
581
- * @param {ReactReconcileTransaction} transaction
582
- * @param {ReactElement} prevParentElement
583
- * @param {ReactElement} nextParentElement
584
- * @internal
585
- * @overridable
586
- */
587
- updateComponent: function (transaction, prevParentElement, nextParentElement, prevUnmaskedContext, nextUnmaskedContext) {
588
- var inst = this._instance;
589
- !(inst != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Attempted to update component `%s` that has already been unmounted (or failed to mount).', this.getName() || 'ReactCompositeComponent') : _prodInvariant('136', this.getName() || 'ReactCompositeComponent') : void 0;
590
-
591
- var willReceive = false;
592
- var nextContext;
593
-
594
- // Determine if the context has changed or not
595
- if (this._context === nextUnmaskedContext) {
596
- nextContext = inst.context;
597
- } else {
598
- nextContext = this._processContext(nextUnmaskedContext);
599
- willReceive = true;
600
- }
601
-
602
- var prevProps = prevParentElement.props;
603
- var nextProps = nextParentElement.props;
604
-
605
- // Not a simple state update but a props update
606
- if (prevParentElement !== nextParentElement) {
607
- willReceive = true;
608
- }
609
-
610
- // An update here will schedule an update but immediately set
611
- // _pendingStateQueue which will ensure that any state updates gets
612
- // immediately reconciled instead of waiting for the next batch.
613
- if (willReceive && inst.componentWillReceiveProps) {
614
- if (process.env.NODE_ENV !== 'production') {
615
- if (this._debugID !== 0) {
616
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'componentWillReceiveProps');
617
- }
618
- }
619
- inst.componentWillReceiveProps(nextProps, nextContext);
620
- if (process.env.NODE_ENV !== 'production') {
621
- if (this._debugID !== 0) {
622
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'componentWillReceiveProps');
623
- }
624
- }
625
- }
626
-
627
- var nextState = this._processPendingState(nextProps, nextContext);
628
- var shouldUpdate = true;
629
-
630
- if (!this._pendingForceUpdate) {
631
- if (inst.shouldComponentUpdate) {
632
- if (process.env.NODE_ENV !== 'production') {
633
- if (this._debugID !== 0) {
634
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'shouldComponentUpdate');
635
- }
636
- }
637
- shouldUpdate = inst.shouldComponentUpdate(nextProps, nextState, nextContext);
638
- if (process.env.NODE_ENV !== 'production') {
639
- if (this._debugID !== 0) {
640
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'shouldComponentUpdate');
641
- }
642
- }
643
- } else {
644
- if (this._compositeType === CompositeTypes.PureClass) {
645
- shouldUpdate = !shallowEqual(prevProps, nextProps) || !shallowEqual(inst.state, nextState);
646
- }
647
- }
648
- }
649
-
650
- if (process.env.NODE_ENV !== 'production') {
651
- process.env.NODE_ENV !== 'production' ? warning(shouldUpdate !== undefined, '%s.shouldComponentUpdate(): Returned undefined instead of a ' + 'boolean value. Make sure to return true or false.', this.getName() || 'ReactCompositeComponent') : void 0;
652
- }
653
-
654
- this._updateBatchNumber = null;
655
- if (shouldUpdate) {
656
- this._pendingForceUpdate = false;
657
- // Will set `this.props`, `this.state` and `this.context`.
658
- this._performComponentUpdate(nextParentElement, nextProps, nextState, nextContext, transaction, nextUnmaskedContext);
659
- } else {
660
- // If it's determined that a component should not update, we still want
661
- // to set props and state but we shortcut the rest of the update.
662
- this._currentElement = nextParentElement;
663
- this._context = nextUnmaskedContext;
664
- inst.props = nextProps;
665
- inst.state = nextState;
666
- inst.context = nextContext;
667
- }
668
- },
669
-
670
- _processPendingState: function (props, context) {
671
- var inst = this._instance;
672
- var queue = this._pendingStateQueue;
673
- var replace = this._pendingReplaceState;
674
- this._pendingReplaceState = false;
675
- this._pendingStateQueue = null;
676
-
677
- if (!queue) {
678
- return inst.state;
679
- }
680
-
681
- if (replace && queue.length === 1) {
682
- return queue[0];
683
- }
684
-
685
- var nextState = _assign({}, replace ? queue[0] : inst.state);
686
- for (var i = replace ? 1 : 0; i < queue.length; i++) {
687
- var partial = queue[i];
688
- _assign(nextState, typeof partial === 'function' ? partial.call(inst, nextState, props, context) : partial);
689
- }
690
-
691
- return nextState;
692
- },
693
-
694
- /**
695
- * Merges new props and state, notifies delegate methods of update and
696
- * performs update.
697
- *
698
- * @param {ReactElement} nextElement Next element
699
- * @param {object} nextProps Next public object to set as properties.
700
- * @param {?object} nextState Next object to set as state.
701
- * @param {?object} nextContext Next public object to set as context.
702
- * @param {ReactReconcileTransaction} transaction
703
- * @param {?object} unmaskedContext
704
- * @private
705
- */
706
- _performComponentUpdate: function (nextElement, nextProps, nextState, nextContext, transaction, unmaskedContext) {
707
- var inst = this._instance;
708
-
709
- var hasComponentDidUpdate = Boolean(inst.componentDidUpdate);
710
- var prevProps;
711
- var prevState;
712
- var prevContext;
713
- if (hasComponentDidUpdate) {
714
- prevProps = inst.props;
715
- prevState = inst.state;
716
- prevContext = inst.context;
717
- }
718
-
719
- if (inst.componentWillUpdate) {
720
- if (process.env.NODE_ENV !== 'production') {
721
- if (this._debugID !== 0) {
722
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'componentWillUpdate');
723
- }
724
- }
725
- inst.componentWillUpdate(nextProps, nextState, nextContext);
726
- if (process.env.NODE_ENV !== 'production') {
727
- if (this._debugID !== 0) {
728
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'componentWillUpdate');
729
- }
730
- }
731
- }
732
-
733
- this._currentElement = nextElement;
734
- this._context = unmaskedContext;
735
- inst.props = nextProps;
736
- inst.state = nextState;
737
- inst.context = nextContext;
738
-
739
- this._updateRenderedComponent(transaction, unmaskedContext);
740
-
741
- if (hasComponentDidUpdate) {
742
- if (process.env.NODE_ENV !== 'production') {
743
- transaction.getReactMountReady().enqueue(invokeComponentDidUpdateWithTimer.bind(this, prevProps, prevState, prevContext), this);
744
- } else {
745
- transaction.getReactMountReady().enqueue(inst.componentDidUpdate.bind(inst, prevProps, prevState, prevContext), inst);
746
- }
747
- }
748
- },
749
-
750
- /**
751
- * Call the component's `render` method and update the DOM accordingly.
752
- *
753
- * @param {ReactReconcileTransaction} transaction
754
- * @internal
755
- */
756
- _updateRenderedComponent: function (transaction, context) {
757
- var prevComponentInstance = this._renderedComponent;
758
- var prevRenderedElement = prevComponentInstance._currentElement;
759
- var nextRenderedElement = this._renderValidatedComponent();
760
- if (shouldUpdateReactComponent(prevRenderedElement, nextRenderedElement)) {
761
- ReactReconciler.receiveComponent(prevComponentInstance, nextRenderedElement, transaction, this._processChildContext(context));
762
- } else {
763
- var oldHostNode = ReactReconciler.getHostNode(prevComponentInstance);
764
- ReactReconciler.unmountComponent(prevComponentInstance, false);
765
-
766
- var nodeType = ReactNodeTypes.getType(nextRenderedElement);
767
- this._renderedNodeType = nodeType;
768
- var child = this._instantiateReactComponent(nextRenderedElement, nodeType !== ReactNodeTypes.EMPTY /* shouldHaveDebugID */
769
- );
770
- this._renderedComponent = child;
771
-
772
- var selfDebugID = 0;
773
- if (process.env.NODE_ENV !== 'production') {
774
- selfDebugID = this._debugID;
775
- }
776
- var nextMarkup = ReactReconciler.mountComponent(child, transaction, this._hostParent, this._hostContainerInfo, this._processChildContext(context), selfDebugID);
777
-
778
- if (process.env.NODE_ENV !== 'production') {
779
- if (this._debugID !== 0) {
780
- ReactInstrumentation.debugTool.onSetChildren(this._debugID, child._debugID !== 0 ? [child._debugID] : []);
781
- }
782
- }
783
-
784
- this._replaceNodeWithMarkup(oldHostNode, nextMarkup, prevComponentInstance);
785
- }
786
- },
787
-
788
- /**
789
- * Overridden in shallow rendering.
790
- *
791
- * @protected
792
- */
793
- _replaceNodeWithMarkup: function (oldHostNode, nextMarkup, prevInstance) {
794
- ReactComponentEnvironment.replaceNodeWithMarkup(oldHostNode, nextMarkup, prevInstance);
795
- },
796
-
797
- /**
798
- * @protected
799
- */
800
- _renderValidatedComponentWithoutOwnerOrContext: function () {
801
- var inst = this._instance;
802
-
803
- if (process.env.NODE_ENV !== 'production') {
804
- if (this._debugID !== 0) {
805
- ReactInstrumentation.debugTool.onBeginLifeCycleTimer(this._debugID, 'render');
806
- }
807
- }
808
- var renderedComponent = inst.render();
809
- if (process.env.NODE_ENV !== 'production') {
810
- if (this._debugID !== 0) {
811
- ReactInstrumentation.debugTool.onEndLifeCycleTimer(this._debugID, 'render');
812
- }
813
- }
814
-
815
- if (process.env.NODE_ENV !== 'production') {
816
- // We allow auto-mocks to proceed as if they're returning null.
817
- if (renderedComponent === undefined && inst.render._isMockFunction) {
818
- // This is probably bad practice. Consider warning here and
819
- // deprecating this convenience.
820
- renderedComponent = null;
821
- }
822
- }
823
-
824
- return renderedComponent;
825
- },
826
-
827
- /**
828
- * @private
829
- */
830
- _renderValidatedComponent: function () {
831
- var renderedComponent;
832
- if (process.env.NODE_ENV !== 'production' || this._compositeType !== CompositeTypes.StatelessFunctional) {
833
- ReactCurrentOwner.current = this;
834
- try {
835
- renderedComponent = this._renderValidatedComponentWithoutOwnerOrContext();
836
- } finally {
837
- ReactCurrentOwner.current = null;
838
- }
839
- } else {
840
- renderedComponent = this._renderValidatedComponentWithoutOwnerOrContext();
841
- }
842
- !(
843
- // TODO: An `isValidNode` function would probably be more appropriate
844
- renderedComponent === null || renderedComponent === false || ReactElement.isValidElement(renderedComponent)) ? process.env.NODE_ENV !== 'production' ? invariant(false, '%s.render(): A valid React element (or null) must be returned. You may have returned undefined, an array or some other invalid object.', this.getName() || 'ReactCompositeComponent') : _prodInvariant('109', this.getName() || 'ReactCompositeComponent') : void 0;
845
-
846
- return renderedComponent;
847
- },
848
-
849
- /**
850
- * Lazily allocates the refs object and stores `component` as `ref`.
851
- *
852
- * @param {string} ref Reference name.
853
- * @param {component} component Component to store as `ref`.
854
- * @final
855
- * @private
856
- */
857
- attachRef: function (ref, component) {
858
- var inst = this.getPublicInstance();
859
- !(inst != null) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Stateless function components cannot have refs.') : _prodInvariant('110') : void 0;
860
- var publicComponentInstance = component.getPublicInstance();
861
- if (process.env.NODE_ENV !== 'production') {
862
- var componentName = component && component.getName ? component.getName() : 'a component';
863
- process.env.NODE_ENV !== 'production' ? warning(publicComponentInstance != null, 'Stateless function components cannot be given refs ' + '(See ref "%s" in %s created by %s). ' + 'Attempts to access this ref will fail.', ref, componentName, this.getName()) : void 0;
864
- }
865
- var refs = inst.refs === emptyObject ? inst.refs = {} : inst.refs;
866
- refs[ref] = publicComponentInstance;
867
- },
868
-
869
- /**
870
- * Detaches a reference name.
871
- *
872
- * @param {string} ref Name to dereference.
873
- * @final
874
- * @private
875
- */
876
- detachRef: function (ref) {
877
- var refs = this.getPublicInstance().refs;
878
- delete refs[ref];
879
- },
880
-
881
- /**
882
- * Get a text description of the component that can be used to identify it
883
- * in error messages.
884
- * @return {string} The name or null.
885
- * @internal
886
- */
887
- getName: function () {
888
- var type = this._currentElement.type;
889
- var constructor = this._instance && this._instance.constructor;
890
- return type.displayName || constructor && constructor.displayName || type.name || constructor && constructor.name || null;
891
- },
892
-
893
- /**
894
- * Get the publicly accessible representation of this component - i.e. what
895
- * is exposed by refs and returned by render. Can be null for stateless
896
- * components.
897
- *
898
- * @return {ReactComponent} the public component instance.
899
- * @internal
900
- */
901
- getPublicInstance: function () {
902
- var inst = this._instance;
903
- if (this._compositeType === CompositeTypes.StatelessFunctional) {
904
- return null;
905
- }
906
- return inst;
907
- },
908
-
909
- // Stub
910
- _instantiateReactComponent: null
911
-
912
- };
913
-
914
- var ReactCompositeComponent = {
915
-
916
- Mixin: ReactCompositeComponentMixin
917
-
918
- };
919
-
920
- module.exports = ReactCompositeComponent;