react 15.3.1 → 15.4.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. package/dist/react-with-addons.js +3901 -21391
  2. package/dist/react-with-addons.min.js +3 -6
  3. package/dist/react.js +2671 -19498
  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 +5 -2
  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/traverseAllChildren.js +11 -2
  33. package/lib/update.js +6 -7
  34. package/package.json +1 -1
  35. package/lib/AutoFocusUtils.js +0 -24
  36. package/lib/BeforeInputEventPlugin.js +0 -388
  37. package/lib/CSSProperty.js +0 -148
  38. package/lib/CSSPropertyOperations.js +0 -205
  39. package/lib/CallbackQueue.js +0 -106
  40. package/lib/ChangeEventPlugin.js +0 -325
  41. package/lib/DOMChildrenOperations.js +0 -194
  42. package/lib/DOMLazyTree.js +0 -118
  43. package/lib/DOMProperty.js +0 -206
  44. package/lib/DOMPropertyOperations.js +0 -221
  45. package/lib/Danger.js +0 -48
  46. package/lib/DefaultEventPluginOrder.js +0 -27
  47. package/lib/DisabledInputUtils.js +0 -50
  48. package/lib/EnterLeaveEventPlugin.js +0 -105
  49. package/lib/EventConstants.js +0 -97
  50. package/lib/EventPluginHub.js +0 -251
  51. package/lib/EventPluginRegistry.js +0 -247
  52. package/lib/EventPluginUtils.js +0 -229
  53. package/lib/EventPropagators.js +0 -137
  54. package/lib/FallbackCompositionState.js +0 -95
  55. package/lib/HTMLDOMPropertyConfig.js +0 -209
  56. package/lib/LinkedValueUtils.js +0 -136
  57. package/lib/NativeMethodsMixin.js +0 -167
  58. package/lib/ReactBrowserEventEmitter.js +0 -317
  59. package/lib/ReactChildReconciler.js +0 -154
  60. package/lib/ReactChildrenMutationWarningHook.js +0 -54
  61. package/lib/ReactComponentBrowserEnvironment.js +0 -30
  62. package/lib/ReactComponentEnvironment.js +0 -45
  63. package/lib/ReactComponentTreeTestUtils.js +0 -87
  64. package/lib/ReactCompositeComponent.js +0 -920
  65. package/lib/ReactDOM.js +0 -110
  66. package/lib/ReactDOMButton.js +0 -24
  67. package/lib/ReactDOMComponent.js +0 -1005
  68. package/lib/ReactDOMComponentTree.js +0 -188
  69. package/lib/ReactDOMContainerInfo.js +0 -33
  70. package/lib/ReactDOMEmptyComponent.js +0 -60
  71. package/lib/ReactDOMFiber.js +0 -76
  72. package/lib/ReactDOMIDOperations.js +0 -34
  73. package/lib/ReactDOMInput.js +0 -269
  74. package/lib/ReactDOMNullInputValuePropHook.js +0 -43
  75. package/lib/ReactDOMOption.js +0 -123
  76. package/lib/ReactDOMSelect.js +0 -201
  77. package/lib/ReactDOMSelection.js +0 -212
  78. package/lib/ReactDOMServer.js +0 -26
  79. package/lib/ReactDOMTextComponent.js +0 -164
  80. package/lib/ReactDOMTextarea.js +0 -155
  81. package/lib/ReactDOMTreeTraversal.js +0 -136
  82. package/lib/ReactDOMUnknownPropertyHook.js +0 -112
  83. package/lib/ReactDebugTool.js +0 -307
  84. package/lib/ReactDefaultBatchingStrategy.js +0 -68
  85. package/lib/ReactDefaultInjection.js +0 -84
  86. package/lib/ReactEmptyComponent.js +0 -30
  87. package/lib/ReactErrorUtils.js +0 -76
  88. package/lib/ReactEventEmitterMixin.js +0 -33
  89. package/lib/ReactEventListener.js +0 -157
  90. package/lib/ReactFeatureFlags.js +0 -22
  91. package/lib/ReactHostComponent.js +0 -76
  92. package/lib/ReactHostOperationHistoryHook.js +0 -37
  93. package/lib/ReactInjection.js +0 -36
  94. package/lib/ReactInputSelection.js +0 -124
  95. package/lib/ReactInstanceHandles.js +0 -302
  96. package/lib/ReactInstanceMap.js +0 -48
  97. package/lib/ReactInstrumentation.js +0 -21
  98. package/lib/ReactInvalidSetStateWarningHook.js +0 -36
  99. package/lib/ReactMarkupChecksum.js +0 -50
  100. package/lib/ReactMount.js +0 -534
  101. package/lib/ReactMultiChild.js +0 -451
  102. package/lib/ReactMultiChildUpdateTypes.js +0 -32
  103. package/lib/ReactNative.js +0 -71
  104. package/lib/ReactNativeAttributePayload.js +0 -371
  105. package/lib/ReactNativeBaseComponent.js +0 -198
  106. package/lib/ReactNativeBridgeEventPlugin.js +0 -60
  107. package/lib/ReactNativeComponentEnvironment.js +0 -31
  108. package/lib/ReactNativeComponentTree.js +0 -68
  109. package/lib/ReactNativeContainerInfo.js +0 -21
  110. package/lib/ReactNativeDOMIDOperations.js +0 -79
  111. package/lib/ReactNativeDefaultInjection.js +0 -101
  112. package/lib/ReactNativeEventEmitter.js +0 -191
  113. package/lib/ReactNativeEventPluginOrder.js +0 -16
  114. package/lib/ReactNativeGlobalResponderHandler.js +0 -25
  115. package/lib/ReactNativeMount.js +0 -193
  116. package/lib/ReactNativePropRegistry.js +0 -52
  117. package/lib/ReactNativeReconcileTransaction.js +0 -116
  118. package/lib/ReactNativeTagHandles.js +0 -56
  119. package/lib/ReactNativeTextComponent.js +0 -71
  120. package/lib/ReactNativeTreeTraversal.js +0 -127
  121. package/lib/ReactNodeTypes.js +0 -40
  122. package/lib/ReactNoop.js +0 -173
  123. package/lib/ReactOwner.js +0 -94
  124. package/lib/ReactPerf.js +0 -494
  125. package/lib/ReactReconcileTransaction.js +0 -178
  126. package/lib/ReactReconciler.js +0 -168
  127. package/lib/ReactRef.js +0 -80
  128. package/lib/ReactServerBatchingStrategy.js +0 -22
  129. package/lib/ReactServerRendering.js +0 -90
  130. package/lib/ReactServerRenderingTransaction.js +0 -90
  131. package/lib/ReactServerUpdateQueue.js +0 -141
  132. package/lib/ReactSimpleEmptyComponent.js +0 -37
  133. package/lib/ReactTestMount.js +0 -126
  134. package/lib/ReactTestReconcileTransaction.js +0 -108
  135. package/lib/ReactTestRenderer.js +0 -144
  136. package/lib/ReactTestUtils.js +0 -518
  137. package/lib/ReactUpdateQueue.js +0 -226
  138. package/lib/ReactUpdates.js +0 -251
  139. package/lib/ResponderEventPlugin.js +0 -510
  140. package/lib/ResponderSyntheticEvent.js +0 -39
  141. package/lib/ResponderTouchHistoryStore.js +0 -184
  142. package/lib/SVGDOMPropertyConfig.js +0 -302
  143. package/lib/SelectEventPlugin.js +0 -196
  144. package/lib/SimpleEventPlugin.js +0 -635
  145. package/lib/SyntheticAnimationEvent.js +0 -39
  146. package/lib/SyntheticClipboardEvent.js +0 -38
  147. package/lib/SyntheticCompositionEvent.js +0 -36
  148. package/lib/SyntheticDragEvent.js +0 -36
  149. package/lib/SyntheticEvent.js +0 -267
  150. package/lib/SyntheticFocusEvent.js +0 -36
  151. package/lib/SyntheticInputEvent.js +0 -37
  152. package/lib/SyntheticKeyboardEvent.js +0 -84
  153. package/lib/SyntheticMouseEvent.js +0 -72
  154. package/lib/SyntheticTouchEvent.js +0 -45
  155. package/lib/SyntheticTransitionEvent.js +0 -39
  156. package/lib/SyntheticUIEvent.js +0 -59
  157. package/lib/SyntheticWheelEvent.js +0 -54
  158. package/lib/TapEventPlugin.js +0 -110
  159. package/lib/TouchHistoryMath.js +0 -99
  160. package/lib/Transaction.js +0 -233
  161. package/lib/ViewportMetrics.js +0 -27
  162. package/lib/accumulate.js +0 -46
  163. package/lib/accumulateInto.js +0 -58
  164. package/lib/adler32.js +0 -44
  165. package/lib/createMicrosoftUnsafeLocalFunction.js +0 -32
  166. package/lib/createReactNativeComponentClass.js +0 -42
  167. package/lib/dangerousStyleValue.js +0 -79
  168. package/lib/escapeTextContentForBrowser.js +0 -123
  169. package/lib/findDOMNode.js +0 -60
  170. package/lib/findNodeHandle.js +0 -91
  171. package/lib/forEachAccumulated.js +0 -31
  172. package/lib/getEventCharCode.js +0 -50
  173. package/lib/getEventKey.js +0 -102
  174. package/lib/getEventModifierState.js +0 -43
  175. package/lib/getEventTarget.js +0 -35
  176. package/lib/getHostComponentFromComposite.js +0 -30
  177. package/lib/getNodeForCharacterOffset.js +0 -74
  178. package/lib/getTestDocument.js +0 -21
  179. package/lib/getTextContentAccessor.js +0 -33
  180. package/lib/getVendorPrefixedEventName.js +0 -101
  181. package/lib/instantiateReactComponent.js +0 -119
  182. package/lib/isEventSupported.js +0 -60
  183. package/lib/isTextInputElement.js +0 -51
  184. package/lib/quoteAttributeValueForBrowser.js +0 -26
  185. package/lib/reactComponentExpect.js +0 -217
  186. package/lib/setInnerHTML.js +0 -98
  187. package/lib/setTextContent.js +0 -48
  188. package/lib/shouldUpdateReactComponent.js +0 -42
  189. package/lib/validateDOMNesting.js +0 -369
@@ -1,71 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-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 ReactNative
10
- *
11
- */
12
- 'use strict';
13
-
14
- // Require ReactNativeDefaultInjection first for its side effects of setting up
15
- // the JS environment
16
-
17
- var ReactNativeComponentTree = require('./ReactNativeComponentTree');
18
- var ReactNativeDefaultInjection = require('./ReactNativeDefaultInjection');
19
-
20
- var ReactElement = require('./ReactElement');
21
- var ReactNativeMount = require('./ReactNativeMount');
22
- var ReactUpdates = require('./ReactUpdates');
23
-
24
- var findNodeHandle = require('./findNodeHandle');
25
-
26
- ReactNativeDefaultInjection.inject();
27
-
28
- var render = function (element, mountInto, callback) {
29
- return ReactNativeMount.renderComponent(element, mountInto, callback);
30
- };
31
-
32
- var ReactNative = {
33
- hasReactNativeInitialized: false,
34
- findNodeHandle: findNodeHandle,
35
- render: render,
36
- unmountComponentAtNode: ReactNativeMount.unmountComponentAtNode,
37
-
38
- /* eslint-disable camelcase */
39
- unstable_batchedUpdates: ReactUpdates.batchedUpdates,
40
- /* eslint-enable camelcase */
41
-
42
- unmountComponentAtNodeAndRemoveContainer: ReactNativeMount.unmountComponentAtNodeAndRemoveContainer
43
- };
44
-
45
- // Inject the runtime into a devtools global hook regardless of browser.
46
- // Allows for debugging when the hook is injected on the page.
47
- /* globals __REACT_DEVTOOLS_GLOBAL_HOOK__ */
48
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
49
- __REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
50
- ComponentTree: {
51
- getClosestInstanceFromNode: function (node) {
52
- return ReactNativeComponentTree.getClosestInstanceFromNode(node);
53
- },
54
- getNodeFromInstance: function (inst) {
55
- // inst is an internal instance (but could be a composite)
56
- while (inst._renderedComponent) {
57
- inst = inst._renderedComponent;
58
- }
59
- if (inst) {
60
- return ReactNativeComponentTree.getNodeFromInstance(inst);
61
- } else {
62
- return null;
63
- }
64
- }
65
- },
66
- Mount: ReactNativeMount,
67
- Reconciler: require('./ReactReconciler')
68
- });
69
- }
70
-
71
- module.exports = ReactNative;
@@ -1,371 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-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 ReactNativeAttributePayload
10
- *
11
- */
12
- 'use strict';
13
-
14
- var ReactNativePropRegistry = require('./ReactNativePropRegistry');
15
-
16
- var deepDiffer = require('react-native/lib/deepDiffer');
17
- var flattenStyle = require('react-native/lib/flattenStyle');
18
-
19
- var emptyObject = {};
20
-
21
- /**
22
- * Create a payload that contains all the updates between two sets of props.
23
- *
24
- * These helpers are all encapsulated into a single module, because they use
25
- * mutation as a performance optimization which leads to subtle shared
26
- * dependencies between the code paths. To avoid this mutable state leaking
27
- * across modules, I've kept them isolated to this module.
28
- */
29
-
30
- /*| boolean*/
31
-
32
-
33
- // Tracks removed keys
34
- var removedKeys = null;
35
- var removedKeyCount = 0;
36
-
37
- function defaultDiffer(prevProp, nextProp) {
38
- if (typeof nextProp !== 'object' || nextProp === null) {
39
- // Scalars have already been checked for equality
40
- return true;
41
- } else {
42
- // For objects and arrays, the default diffing algorithm is a deep compare
43
- return deepDiffer(prevProp, nextProp);
44
- }
45
- }
46
-
47
- function resolveObject(idOrObject) {
48
- if (typeof idOrObject === 'number') {
49
- return ReactNativePropRegistry.getByID(idOrObject);
50
- }
51
- return idOrObject;
52
- }
53
-
54
- function restoreDeletedValuesInNestedArray(updatePayload, node, validAttributes) {
55
- if (Array.isArray(node)) {
56
- var i = node.length;
57
- while (i-- && removedKeyCount > 0) {
58
- restoreDeletedValuesInNestedArray(updatePayload, node[i], validAttributes);
59
- }
60
- } else if (node && removedKeyCount > 0) {
61
- var obj = resolveObject(node);
62
- for (var propKey in removedKeys) {
63
- if (!removedKeys[propKey]) {
64
- continue;
65
- }
66
- var nextProp = obj[propKey];
67
- if (nextProp === undefined) {
68
- continue;
69
- }
70
-
71
- var attributeConfig = validAttributes[propKey];
72
- if (!attributeConfig) {
73
- continue; // not a valid native prop
74
- }
75
-
76
- if (typeof nextProp === 'function') {
77
- nextProp = true;
78
- }
79
- if (typeof nextProp === 'undefined') {
80
- nextProp = null;
81
- }
82
-
83
- if (typeof attributeConfig !== 'object') {
84
- // case: !Object is the default case
85
- updatePayload[propKey] = nextProp;
86
- } else if (typeof attributeConfig.diff === 'function' || typeof attributeConfig.process === 'function') {
87
- // case: CustomAttributeConfiguration
88
- var nextValue = typeof attributeConfig.process === 'function' ? attributeConfig.process(nextProp) : nextProp;
89
- updatePayload[propKey] = nextValue;
90
- }
91
- removedKeys[propKey] = false;
92
- removedKeyCount--;
93
- }
94
- }
95
- }
96
-
97
- function diffNestedArrayProperty(updatePayload, prevArray, nextArray, validAttributes) {
98
- var minLength = prevArray.length < nextArray.length ? prevArray.length : nextArray.length;
99
- var i;
100
- for (i = 0; i < minLength; i++) {
101
- // Diff any items in the array in the forward direction. Repeated keys
102
- // will be overwritten by later values.
103
- updatePayload = diffNestedProperty(updatePayload, prevArray[i], nextArray[i], validAttributes);
104
- }
105
- for (; i < prevArray.length; i++) {
106
- // Clear out all remaining properties.
107
- updatePayload = clearNestedProperty(updatePayload, prevArray[i], validAttributes);
108
- }
109
- for (; i < nextArray.length; i++) {
110
- // Add all remaining properties.
111
- updatePayload = addNestedProperty(updatePayload, nextArray[i], validAttributes);
112
- }
113
- return updatePayload;
114
- }
115
-
116
- function diffNestedProperty(updatePayload, prevProp, nextProp, validAttributes) {
117
-
118
- if (!updatePayload && prevProp === nextProp) {
119
- // If no properties have been added, then we can bail out quickly on object
120
- // equality.
121
- return updatePayload;
122
- }
123
-
124
- if (!prevProp || !nextProp) {
125
- if (nextProp) {
126
- return addNestedProperty(updatePayload, nextProp, validAttributes);
127
- }
128
- if (prevProp) {
129
- return clearNestedProperty(updatePayload, prevProp, validAttributes);
130
- }
131
- return updatePayload;
132
- }
133
-
134
- if (!Array.isArray(prevProp) && !Array.isArray(nextProp)) {
135
- // Both are leaves, we can diff the leaves.
136
- return diffProperties(updatePayload, resolveObject(prevProp), resolveObject(nextProp), validAttributes);
137
- }
138
-
139
- if (Array.isArray(prevProp) && Array.isArray(nextProp)) {
140
- // Both are arrays, we can diff the arrays.
141
- return diffNestedArrayProperty(updatePayload, prevProp, nextProp, validAttributes);
142
- }
143
-
144
- if (Array.isArray(prevProp)) {
145
- return diffProperties(updatePayload,
146
- // $FlowFixMe - We know that this is always an object when the input is.
147
- flattenStyle(prevProp),
148
- // $FlowFixMe - We know that this isn't an array because of above flow.
149
- resolveObject(nextProp), validAttributes);
150
- }
151
-
152
- return diffProperties(updatePayload, resolveObject(prevProp),
153
- // $FlowFixMe - We know that this is always an object when the input is.
154
- flattenStyle(nextProp), validAttributes);
155
- }
156
-
157
- /**
158
- * addNestedProperty takes a single set of props and valid attribute
159
- * attribute configurations. It processes each prop and adds it to the
160
- * updatePayload.
161
- */
162
- function addNestedProperty(updatePayload, nextProp, validAttributes) {
163
- if (!nextProp) {
164
- return updatePayload;
165
- }
166
-
167
- if (!Array.isArray(nextProp)) {
168
- // Add each property of the leaf.
169
- return addProperties(updatePayload, resolveObject(nextProp), validAttributes);
170
- }
171
-
172
- for (var i = 0; i < nextProp.length; i++) {
173
- // Add all the properties of the array.
174
- updatePayload = addNestedProperty(updatePayload, nextProp[i], validAttributes);
175
- }
176
-
177
- return updatePayload;
178
- }
179
-
180
- /**
181
- * clearNestedProperty takes a single set of props and valid attributes. It
182
- * adds a null sentinel to the updatePayload, for each prop key.
183
- */
184
- function clearNestedProperty(updatePayload, prevProp, validAttributes) {
185
- if (!prevProp) {
186
- return updatePayload;
187
- }
188
-
189
- if (!Array.isArray(prevProp)) {
190
- // Add each property of the leaf.
191
- return clearProperties(updatePayload, resolveObject(prevProp), validAttributes);
192
- }
193
-
194
- for (var i = 0; i < prevProp.length; i++) {
195
- // Add all the properties of the array.
196
- updatePayload = clearNestedProperty(updatePayload, prevProp[i], validAttributes);
197
- }
198
- return updatePayload;
199
- }
200
-
201
- /**
202
- * diffProperties takes two sets of props and a set of valid attributes
203
- * and write to updatePayload the values that changed or were deleted.
204
- * If no updatePayload is provided, a new one is created and returned if
205
- * anything changed.
206
- */
207
- function diffProperties(updatePayload, prevProps, nextProps, validAttributes) {
208
- var attributeConfig;
209
- var nextProp;
210
- var prevProp;
211
-
212
- for (var propKey in nextProps) {
213
- attributeConfig = validAttributes[propKey];
214
- if (!attributeConfig) {
215
- continue; // not a valid native prop
216
- }
217
-
218
- prevProp = prevProps[propKey];
219
- nextProp = nextProps[propKey];
220
-
221
- // functions are converted to booleans as markers that the associated
222
- // events should be sent from native.
223
- if (typeof nextProp === 'function') {
224
- nextProp = true;
225
- // If nextProp is not a function, then don't bother changing prevProp
226
- // since nextProp will win and go into the updatePayload regardless.
227
- if (typeof prevProp === 'function') {
228
- prevProp = true;
229
- }
230
- }
231
-
232
- // An explicit value of undefined is treated as a null because it overrides
233
- // any other preceeding value.
234
- if (typeof nextProp === 'undefined') {
235
- nextProp = null;
236
- if (typeof prevProp === 'undefined') {
237
- prevProp = null;
238
- }
239
- }
240
-
241
- if (removedKeys) {
242
- removedKeys[propKey] = false;
243
- }
244
-
245
- if (updatePayload && updatePayload[propKey] !== undefined) {
246
- // Something else already triggered an update to this key because another
247
- // value diffed. Since we're now later in the nested arrays our value is
248
- // more important so we need to calculate it and override the existing
249
- // value. It doesn't matter if nothing changed, we'll set it anyway.
250
-
251
- // Pattern match on: attributeConfig
252
- if (typeof attributeConfig !== 'object') {
253
- // case: !Object is the default case
254
- updatePayload[propKey] = nextProp;
255
- } else if (typeof attributeConfig.diff === 'function' || typeof attributeConfig.process === 'function') {
256
- // case: CustomAttributeConfiguration
257
- var nextValue = typeof attributeConfig.process === 'function' ? attributeConfig.process(nextProp) : nextProp;
258
- updatePayload[propKey] = nextValue;
259
- }
260
- continue;
261
- }
262
-
263
- if (prevProp === nextProp) {
264
- continue; // nothing changed
265
- }
266
-
267
- // Pattern match on: attributeConfig
268
- if (typeof attributeConfig !== 'object') {
269
- // case: !Object is the default case
270
- if (defaultDiffer(prevProp, nextProp)) {
271
- // a normal leaf has changed
272
- (updatePayload || (updatePayload = {}))[propKey] = nextProp;
273
- }
274
- } else if (typeof attributeConfig.diff === 'function' || typeof attributeConfig.process === 'function') {
275
- // case: CustomAttributeConfiguration
276
- var shouldUpdate = prevProp === undefined || (typeof attributeConfig.diff === 'function' ? attributeConfig.diff(prevProp, nextProp) : defaultDiffer(prevProp, nextProp));
277
- if (shouldUpdate) {
278
- nextValue = typeof attributeConfig.process === 'function' ? attributeConfig.process(nextProp) : nextProp;
279
- (updatePayload || (updatePayload = {}))[propKey] = nextValue;
280
- }
281
- } else {
282
- // default: fallthrough case when nested properties are defined
283
- removedKeys = null;
284
- removedKeyCount = 0;
285
- // We think that attributeConfig is not CustomAttributeConfiguration at
286
- // this point so we assume it must be AttributeConfiguration.
287
- // $FlowFixMe
288
- updatePayload = diffNestedProperty(updatePayload, prevProp, nextProp, attributeConfig);
289
- if (removedKeyCount > 0 && updatePayload) {
290
- restoreDeletedValuesInNestedArray(updatePayload, nextProp, attributeConfig);
291
- removedKeys = null;
292
- }
293
- }
294
- }
295
-
296
- // Also iterate through all the previous props to catch any that have been
297
- // removed and make sure native gets the signal so it can reset them to the
298
- // default.
299
- for (propKey in prevProps) {
300
- if (nextProps[propKey] !== undefined) {
301
- continue; // we've already covered this key in the previous pass
302
- }
303
- attributeConfig = validAttributes[propKey];
304
- if (!attributeConfig) {
305
- continue; // not a valid native prop
306
- }
307
-
308
- if (updatePayload && updatePayload[propKey] !== undefined) {
309
- // This was already updated to a diff result earlier.
310
- continue;
311
- }
312
-
313
- prevProp = prevProps[propKey];
314
- if (prevProp === undefined) {
315
- continue; // was already empty anyway
316
- }
317
- // Pattern match on: attributeConfig
318
- if (typeof attributeConfig !== 'object' || typeof attributeConfig.diff === 'function' || typeof attributeConfig.process === 'function') {
319
-
320
- // case: CustomAttributeConfiguration | !Object
321
- // Flag the leaf property for removal by sending a sentinel.
322
- (updatePayload || (updatePayload = {}))[propKey] = null;
323
- if (!removedKeys) {
324
- removedKeys = {};
325
- }
326
- if (!removedKeys[propKey]) {
327
- removedKeys[propKey] = true;
328
- removedKeyCount++;
329
- }
330
- } else {
331
- // default:
332
- // This is a nested attribute configuration where all the properties
333
- // were removed so we need to go through and clear out all of them.
334
- updatePayload = clearNestedProperty(updatePayload, prevProp, attributeConfig);
335
- }
336
- }
337
- return updatePayload;
338
- }
339
-
340
- /**
341
- * addProperties adds all the valid props to the payload after being processed.
342
- */
343
- function addProperties(updatePayload, props, validAttributes) {
344
- // TODO: Fast path
345
- return diffProperties(updatePayload, emptyObject, props, validAttributes);
346
- }
347
-
348
- /**
349
- * clearProperties clears all the previous props by adding a null sentinel
350
- * to the payload for each valid key.
351
- */
352
- function clearProperties(updatePayload, prevProps, validAttributes) {
353
- // TODO: Fast path
354
- return diffProperties(updatePayload, prevProps, emptyObject, validAttributes);
355
- }
356
-
357
- var ReactNativeAttributePayload = {
358
-
359
- create: function (props, validAttributes) {
360
- return addProperties(null, // updatePayload
361
- props, validAttributes);
362
- },
363
-
364
- diff: function (prevProps, nextProps, validAttributes) {
365
- return diffProperties(null, // updatePayload
366
- prevProps, nextProps, validAttributes);
367
- }
368
-
369
- };
370
-
371
- module.exports = ReactNativeAttributePayload;
@@ -1,198 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-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 ReactNativeBaseComponent
10
- *
11
- */
12
- 'use strict';
13
-
14
- var _assign = require('object-assign');
15
-
16
- var NativeMethodsMixin = require('./NativeMethodsMixin');
17
- var ReactNativeAttributePayload = require('./ReactNativeAttributePayload');
18
- var ReactNativeComponentTree = require('./ReactNativeComponentTree');
19
- var ReactNativeEventEmitter = require('./ReactNativeEventEmitter');
20
- var ReactNativeTagHandles = require('./ReactNativeTagHandles');
21
- var ReactMultiChild = require('./ReactMultiChild');
22
- var UIManager = require('react-native/lib/UIManager');
23
-
24
- var deepFreezeAndThrowOnMutationInDev = require('react-native/lib/deepFreezeAndThrowOnMutationInDev');
25
-
26
- var registrationNames = ReactNativeEventEmitter.registrationNames;
27
- var putListener = ReactNativeEventEmitter.putListener;
28
- var deleteListener = ReactNativeEventEmitter.deleteListener;
29
- var deleteAllListeners = ReactNativeEventEmitter.deleteAllListeners;
30
-
31
- // require('UIManagerStatTracker').install(); // uncomment to enable
32
-
33
- /**
34
- * @constructor ReactNativeBaseComponent
35
- * @extends ReactComponent
36
- * @extends ReactMultiChild
37
- * @param {!object} UIKit View Configuration.
38
- */
39
- var ReactNativeBaseComponent = function (viewConfig) {
40
- this.viewConfig = viewConfig;
41
- };
42
-
43
- /**
44
- * Mixin for containers that contain UIViews. NOTE: markup is rendered markup
45
- * which is a `viewID` ... see the return value for `mountComponent` !
46
- */
47
- ReactNativeBaseComponent.Mixin = {
48
- getPublicInstance: function () {
49
- // TODO: This should probably use a composite wrapper
50
- return this;
51
- },
52
-
53
- unmountComponent: function () {
54
- ReactNativeComponentTree.uncacheNode(this);
55
- deleteAllListeners(this);
56
- this.unmountChildren();
57
- this._rootNodeID = 0;
58
- },
59
-
60
- /**
61
- * Every native component is responsible for allocating its own `tag`, and
62
- * issuing the native `createView` command. But it is not responsible for
63
- * recording the fact that its own `rootNodeID` is associated with a
64
- * `nodeHandle`. Only the code that actually adds its `nodeHandle` (`tag`) as
65
- * a child of a container can confidently record that in
66
- * `ReactNativeTagHandles`.
67
- */
68
- initializeChildren: function (children, containerTag, transaction, context) {
69
- var mountImages = this.mountChildren(children, transaction, context);
70
- // In a well balanced tree, half of the nodes are in the bottom row and have
71
- // no children - let's avoid calling out to the native bridge for a large
72
- // portion of the children.
73
- if (mountImages.length) {
74
-
75
- // TODO: Pool these per platform view class. Reusing the `mountImages`
76
- // array would likely be a jit deopt.
77
- var createdTags = [];
78
- for (var i = 0, l = mountImages.length; i < l; i++) {
79
- var mountImage = mountImages[i];
80
- var childTag = mountImage;
81
- createdTags[i] = childTag;
82
- }
83
- UIManager.setChildren(containerTag, createdTags);
84
- }
85
- },
86
-
87
- /**
88
- * Updates the component's currently mounted representation.
89
- *
90
- * @param {object} nextElement
91
- * @param {ReactReconcileTransaction} transaction
92
- * @param {object} context
93
- * @internal
94
- */
95
- receiveComponent: function (nextElement, transaction, context) {
96
- var prevElement = this._currentElement;
97
- this._currentElement = nextElement;
98
-
99
- if (process.env.NODE_ENV !== 'production') {
100
- for (var key in this.viewConfig.validAttributes) {
101
- if (nextElement.props.hasOwnProperty(key)) {
102
- deepFreezeAndThrowOnMutationInDev(nextElement.props[key]);
103
- }
104
- }
105
- }
106
-
107
- var updatePayload = ReactNativeAttributePayload.diff(prevElement.props, nextElement.props, this.viewConfig.validAttributes);
108
-
109
- if (updatePayload) {
110
- UIManager.updateView(this._rootNodeID, this.viewConfig.uiViewClassName, updatePayload);
111
- }
112
-
113
- this._reconcileListenersUponUpdate(prevElement.props, nextElement.props);
114
- this.updateChildren(nextElement.props.children, transaction, context);
115
- },
116
-
117
- /**
118
- * @param {object} initialProps Native component props.
119
- */
120
- _registerListenersUponCreation: function (initialProps) {
121
- for (var key in initialProps) {
122
- // NOTE: The check for `!props[key]`, is only possible because this method
123
- // registers listeners the *first* time a component is created.
124
- if (registrationNames[key] && initialProps[key]) {
125
- var listener = initialProps[key];
126
- putListener(this, key, listener);
127
- }
128
- }
129
- },
130
-
131
- /**
132
- * Reconciles event listeners, adding or removing if necessary.
133
- * @param {object} prevProps Native component props including events.
134
- * @param {object} nextProps Next native component props including events.
135
- */
136
- _reconcileListenersUponUpdate: function (prevProps, nextProps) {
137
- for (var key in nextProps) {
138
- if (registrationNames[key] && nextProps[key] !== prevProps[key]) {
139
- if (nextProps[key]) {
140
- putListener(this, key, nextProps[key]);
141
- } else {
142
- deleteListener(this, key);
143
- }
144
- }
145
- }
146
- },
147
-
148
- /**
149
- * Currently this still uses IDs for reconciliation so this can return null.
150
- *
151
- * @return {null} Null.
152
- */
153
- getHostNode: function () {
154
- return this._rootNodeID;
155
- },
156
-
157
- /**
158
- * @param {ReactNativeReconcileTransaction} transaction
159
- * @param {?ReactNativeBaseComponent} the parent component instance
160
- * @param {?object} info about the host container
161
- * @param {object} context
162
- * @return {string} Unique iOS view tag.
163
- */
164
- mountComponent: function (transaction, hostParent, hostContainerInfo, context) {
165
- var tag = ReactNativeTagHandles.allocateTag();
166
-
167
- this._rootNodeID = tag;
168
- this._hostParent = hostParent;
169
- this._hostContainerInfo = hostContainerInfo;
170
-
171
- if (process.env.NODE_ENV !== 'production') {
172
- for (var key in this.viewConfig.validAttributes) {
173
- if (this._currentElement.props.hasOwnProperty(key)) {
174
- deepFreezeAndThrowOnMutationInDev(this._currentElement.props[key]);
175
- }
176
- }
177
- }
178
-
179
- var updatePayload = ReactNativeAttributePayload.create(this._currentElement.props, this.viewConfig.validAttributes);
180
-
181
- var nativeTopRootTag = hostContainerInfo._tag;
182
- UIManager.createView(tag, this.viewConfig.uiViewClassName, nativeTopRootTag, updatePayload);
183
-
184
- ReactNativeComponentTree.precacheNode(this, tag);
185
-
186
- this._registerListenersUponCreation(this._currentElement.props);
187
- this.initializeChildren(this._currentElement.props.children, tag, transaction, context);
188
- return tag;
189
- }
190
- };
191
-
192
- /**
193
- * Order of mixins is important. ReactNativeBaseComponent overrides methods in
194
- * ReactMultiChild.
195
- */
196
- _assign(ReactNativeBaseComponent.prototype, ReactMultiChild.Mixin, ReactNativeBaseComponent.Mixin, NativeMethodsMixin);
197
-
198
- module.exports = ReactNativeBaseComponent;