react 0.7.1 → 0.10.0-rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/README.md +10 -231
  2. package/addons.js +1 -0
  3. package/lib/AutoFocusMixin.js +32 -0
  4. package/lib/CSSCore.js +115 -0
  5. package/lib/CSSProperty.js +121 -0
  6. package/lib/CSSPropertyOperations.js +97 -0
  7. package/lib/ChangeEventPlugin.js +387 -0
  8. package/lib/ClientReactRootIndex.js +30 -0
  9. package/lib/CompositionEventPlugin.js +260 -0
  10. package/lib/DOMChildrenOperations.js +171 -0
  11. package/lib/DOMProperty.js +270 -0
  12. package/lib/DOMPropertyOperations.js +181 -0
  13. package/lib/Danger.js +187 -0
  14. package/lib/DefaultDOMPropertyConfig.js +196 -0
  15. package/lib/DefaultEventPluginOrder.js +44 -0
  16. package/lib/EnterLeaveEventPlugin.js +145 -0
  17. package/lib/EventConstants.js +76 -0
  18. package/lib/EventListener.js +69 -0
  19. package/lib/EventPluginHub.js +295 -0
  20. package/lib/EventPluginRegistry.js +281 -0
  21. package/lib/EventPluginUtils.js +214 -0
  22. package/lib/EventPropagators.js +143 -0
  23. package/lib/ExecutionEnvironment.js +44 -0
  24. package/lib/LinkedStateMixin.js +46 -0
  25. package/lib/LinkedValueUtils.js +160 -0
  26. package/lib/MobileSafariClickEventPlugin.js +63 -0
  27. package/lib/PooledClass.js +119 -0
  28. package/lib/React.js +97 -0
  29. package/lib/ReactBrowserComponentMixin.js +42 -0
  30. package/lib/ReactCSSTransitionGroup.js +65 -0
  31. package/lib/ReactCSSTransitionGroupChild.js +138 -0
  32. package/lib/ReactChildren.js +132 -0
  33. package/lib/ReactComponent.js +595 -0
  34. package/lib/ReactComponentBrowserEnvironment.js +124 -0
  35. package/lib/ReactCompositeComponent.js +1587 -0
  36. package/lib/ReactContext.js +67 -0
  37. package/lib/ReactCurrentOwner.js +39 -0
  38. package/lib/ReactDOM.js +207 -0
  39. package/lib/ReactDOMButton.js +69 -0
  40. package/lib/ReactDOMComponent.js +416 -0
  41. package/lib/ReactDOMForm.js +62 -0
  42. package/lib/ReactDOMIDOperations.js +218 -0
  43. package/lib/ReactDOMImg.js +61 -0
  44. package/lib/ReactDOMInput.js +182 -0
  45. package/lib/ReactDOMOption.js +55 -0
  46. package/lib/ReactDOMSelect.js +180 -0
  47. package/lib/ReactDOMSelection.js +189 -0
  48. package/lib/ReactDOMTextarea.js +144 -0
  49. package/lib/ReactDefaultBatchingStrategy.js +75 -0
  50. package/lib/ReactDefaultInjection.js +125 -0
  51. package/lib/ReactDefaultPerf.js +244 -0
  52. package/lib/ReactDefaultPerfAnalysis.js +199 -0
  53. package/lib/ReactErrorUtils.js +37 -0
  54. package/lib/ReactEventEmitter.js +339 -0
  55. package/lib/ReactEventEmitterMixin.js +57 -0
  56. package/lib/ReactEventTopLevelCallback.js +149 -0
  57. package/lib/ReactInjection.js +43 -0
  58. package/lib/ReactInputSelection.js +141 -0
  59. package/lib/ReactInstanceHandles.js +338 -0
  60. package/lib/ReactLink.js +54 -0
  61. package/lib/ReactMarkupChecksum.js +53 -0
  62. package/lib/ReactMount.js +649 -0
  63. package/lib/ReactMountReady.js +95 -0
  64. package/lib/ReactMultiChild.js +432 -0
  65. package/lib/ReactMultiChildUpdateTypes.js +38 -0
  66. package/lib/ReactOwner.js +159 -0
  67. package/lib/ReactPerf.js +85 -0
  68. package/lib/ReactPropTransferer.js +147 -0
  69. package/lib/ReactPropTypeLocationNames.js +31 -0
  70. package/lib/ReactPropTypeLocations.js +29 -0
  71. package/lib/ReactPropTypes.js +359 -0
  72. package/lib/ReactPutListenerQueue.js +61 -0
  73. package/lib/ReactReconcileTransaction.js +182 -0
  74. package/lib/ReactRootIndex.js +36 -0
  75. package/lib/ReactServerRendering.js +89 -0
  76. package/lib/ReactServerRenderingTransaction.js +116 -0
  77. package/lib/ReactStateSetters.js +111 -0
  78. package/lib/ReactTestUtils.js +394 -0
  79. package/lib/ReactTextComponent.js +121 -0
  80. package/lib/ReactTransitionChildMapping.js +106 -0
  81. package/lib/ReactTransitionEvents.js +97 -0
  82. package/lib/ReactTransitionGroup.js +187 -0
  83. package/lib/ReactUpdates.js +148 -0
  84. package/lib/ReactWithAddons.js +53 -0
  85. package/lib/SelectEventPlugin.js +200 -0
  86. package/lib/ServerReactRootIndex.js +36 -0
  87. package/lib/SimpleEventPlugin.js +413 -0
  88. package/lib/SyntheticClipboardEvent.js +51 -0
  89. package/lib/SyntheticCompositionEvent.js +51 -0
  90. package/lib/SyntheticDragEvent.js +44 -0
  91. package/lib/SyntheticEvent.js +164 -0
  92. package/lib/SyntheticFocusEvent.js +44 -0
  93. package/lib/SyntheticKeyboardEvent.js +58 -0
  94. package/lib/SyntheticMouseEvent.js +85 -0
  95. package/lib/SyntheticTouchEvent.js +50 -0
  96. package/lib/SyntheticUIEvent.js +45 -0
  97. package/lib/SyntheticWheelEvent.js +66 -0
  98. package/lib/Transaction.js +276 -0
  99. package/lib/ViewportMetrics.js +37 -0
  100. package/lib/accumulate.js +54 -0
  101. package/lib/adler32.js +39 -0
  102. package/lib/cloneWithProps.js +59 -0
  103. package/lib/containsNode.js +49 -0
  104. package/lib/copyProperties.js +54 -0
  105. package/lib/createArrayFrom.js +91 -0
  106. package/lib/createFullPageComponent.js +63 -0
  107. package/lib/createNodesFromMarkup.js +93 -0
  108. package/lib/createObjectFrom.js +61 -0
  109. package/lib/cx.js +44 -0
  110. package/lib/dangerousStyleValue.js +57 -0
  111. package/lib/emptyFunction.js +43 -0
  112. package/lib/emptyObject.js +27 -0
  113. package/lib/escapeTextForBrowser.js +47 -0
  114. package/lib/flattenChildren.js +57 -0
  115. package/lib/focusNode.js +33 -0
  116. package/lib/forEachAccumulated.js +36 -0
  117. package/lib/getActiveElement.js +34 -0
  118. package/lib/getEventKey.js +85 -0
  119. package/lib/getEventTarget.js +36 -0
  120. package/lib/getMarkupWrap.js +118 -0
  121. package/lib/getNodeForCharacterOffset.js +80 -0
  122. package/lib/getReactRootElementInContainer.js +40 -0
  123. package/lib/getTextContentAccessor.js +42 -0
  124. package/lib/getUnboundedScrollPosition.js +45 -0
  125. package/lib/hyphenate.js +35 -0
  126. package/lib/instantiateReactComponent.js +70 -0
  127. package/lib/invariant.js +62 -0
  128. package/lib/isEventSupported.js +70 -0
  129. package/lib/isNode.js +33 -0
  130. package/lib/isTextInputElement.js +49 -0
  131. package/lib/isTextNode.js +30 -0
  132. package/lib/joinClasses.js +44 -0
  133. package/lib/keyMirror.js +58 -0
  134. package/lib/keyOf.js +41 -0
  135. package/lib/memoizeStringOnly.js +39 -0
  136. package/lib/merge.js +37 -0
  137. package/lib/mergeHelpers.js +136 -0
  138. package/lib/mergeInto.js +45 -0
  139. package/lib/mixInto.js +34 -0
  140. package/lib/monitorCodeUse.js +37 -0
  141. package/lib/objMap.js +47 -0
  142. package/lib/objMapKeyVal.js +47 -0
  143. package/lib/onlyChild.js +43 -0
  144. package/lib/performanceNow.js +42 -0
  145. package/lib/shallowEqual.js +49 -0
  146. package/lib/shouldUpdateReactComponent.js +61 -0
  147. package/lib/toArray.js +75 -0
  148. package/lib/traverseAllChildren.js +190 -0
  149. package/lib/update.js +159 -0
  150. package/lib/warning.js +48 -0
  151. package/package.json +33 -31
  152. package/react.js +1 -0
  153. package/.npmignore +0 -7
  154. package/.travis.yml +0 -7
  155. package/Jakefile.js +0 -39
  156. package/LICENSE +0 -19
  157. package/browser-test/dist.html +0 -90
  158. package/browser-test/index.html +0 -86
  159. package/browser-test/min.html +0 -90
  160. package/dist/react.js +0 -3141
  161. package/dist/react.min.js +0 -22
  162. package/doc/advanced.md +0 -175
  163. package/doc/color-def.graffle +0 -938
  164. package/doc/color-def.png +0 -0
  165. package/doc/simple.dot +0 -25
  166. package/doc/simple.png +0 -0
  167. package/examples/longer-example.js +0 -41
  168. package/examples/simple.js +0 -45
  169. package/examples/using-ast-directly.js +0 -30
  170. package/examples/using-events1.js +0 -79
  171. package/examples/using-log-events.js +0 -43
  172. package/lib/base-task.js +0 -120
  173. package/lib/cb-task.js +0 -84
  174. package/lib/core.js +0 -138
  175. package/lib/dsl.js +0 -138
  176. package/lib/error.js +0 -55
  177. package/lib/event-collector.js +0 -81
  178. package/lib/event-manager.js +0 -89
  179. package/lib/eventemitter.js +0 -20
  180. package/lib/finalcb-first-task.js +0 -68
  181. package/lib/finalcb-task.js +0 -65
  182. package/lib/id.js +0 -22
  183. package/lib/input-parser.js +0 -56
  184. package/lib/log-events.js +0 -101
  185. package/lib/parse.js +0 -41
  186. package/lib/promise-resolve.js +0 -50
  187. package/lib/promise-task.js +0 -93
  188. package/lib/react.js +0 -59
  189. package/lib/ret-task.js +0 -71
  190. package/lib/sprintf.js +0 -18
  191. package/lib/status.js +0 -14
  192. package/lib/task.js +0 -251
  193. package/lib/track-tasks.js +0 -74
  194. package/lib/validate.js +0 -159
  195. package/lib/vcon.js +0 -113
  196. package/lib/when-task.js +0 -84
  197. package/src/dist.build.requirejs +0 -20
  198. package/test/ast.mocha.js +0 -136
  199. package/test/cb-task.mocha.js +0 -220
  200. package/test/core-deferred.mocha.js +0 -143
  201. package/test/core-when.mocha.js +0 -96
  202. package/test/core.mocha.js +0 -589
  203. package/test/dsl.mocha.js +0 -352
  204. package/test/event-manager.mocha.js +0 -119
  205. package/test/exec-options.mocha.js +0 -48
  206. package/test/finalcb-task.mocha.js +0 -58
  207. package/test/input-parser.mocha.js +0 -86
  208. package/test/log-events.mocha.js +0 -88
  209. package/test/mocha.opts +0 -2
  210. package/test/module-use.mocha.js +0 -164
  211. package/test/promise-auto-resolve.mocha.js +0 -68
  212. package/test/ret-task.mocha.js +0 -220
  213. package/test/task.mocha.js +0 -42
  214. package/test/validate-cb-task.mocha.js +0 -100
  215. package/test/validate-ret-task.mocha.js +0 -110
  216. package/test/validate.mocha.js +0 -324
  217. package/test/vcon.mocha.js +0 -193
  218. package/vendor/chai/chai.js +0 -4251
  219. package/vendor/jquery/jquery-1.7.1.js +0 -9266
  220. package/vendor/jquery/jquery-1.7.1.min.js +0 -4
  221. package/vendor/node/util.js +0 -531
  222. package/vendor/requirejs/require.js +0 -2045
  223. package/vendor/requirejs/require.min.js +0 -36
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactMountReady
17
+ */
18
+
19
+ "use strict";
20
+
21
+ var PooledClass = require("./PooledClass");
22
+
23
+ var mixInto = require("./mixInto");
24
+
25
+ /**
26
+ * A specialized pseudo-event module to help keep track of components waiting to
27
+ * be notified when their DOM representations are available for use.
28
+ *
29
+ * This implements `PooledClass`, so you should never need to instantiate this.
30
+ * Instead, use `ReactMountReady.getPooled()`.
31
+ *
32
+ * @param {?array<function>} initialCollection
33
+ * @class ReactMountReady
34
+ * @implements PooledClass
35
+ * @internal
36
+ */
37
+ function ReactMountReady(initialCollection) {
38
+ this._queue = initialCollection || null;
39
+ }
40
+
41
+ mixInto(ReactMountReady, {
42
+
43
+ /**
44
+ * Enqueues a callback to be invoked when `notifyAll` is invoked. This is used
45
+ * to enqueue calls to `componentDidMount` and `componentDidUpdate`.
46
+ *
47
+ * @param {ReactComponent} component Component being rendered.
48
+ * @param {function(DOMElement)} callback Invoked when `notifyAll` is invoked.
49
+ * @internal
50
+ */
51
+ enqueue: function(component, callback) {
52
+ this._queue = this._queue || [];
53
+ this._queue.push({component: component, callback: callback});
54
+ },
55
+
56
+ /**
57
+ * Invokes all enqueued callbacks and clears the queue. This is invoked after
58
+ * the DOM representation of a component has been created or updated.
59
+ *
60
+ * @internal
61
+ */
62
+ notifyAll: function() {
63
+ var queue = this._queue;
64
+ if (queue) {
65
+ this._queue = null;
66
+ for (var i = 0, l = queue.length; i < l; i++) {
67
+ var component = queue[i].component;
68
+ var callback = queue[i].callback;
69
+ callback.call(component);
70
+ }
71
+ queue.length = 0;
72
+ }
73
+ },
74
+
75
+ /**
76
+ * Resets the internal queue.
77
+ *
78
+ * @internal
79
+ */
80
+ reset: function() {
81
+ this._queue = null;
82
+ },
83
+
84
+ /**
85
+ * `PooledClass` looks for this.
86
+ */
87
+ destructor: function() {
88
+ this.reset();
89
+ }
90
+
91
+ });
92
+
93
+ PooledClass.addPoolingTo(ReactMountReady);
94
+
95
+ module.exports = ReactMountReady;
@@ -0,0 +1,432 @@
1
+ /**
2
+ * Copyright 2013-2014 Facebook, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *
16
+ * @providesModule ReactMultiChild
17
+ * @typechecks static-only
18
+ */
19
+
20
+ "use strict";
21
+
22
+ var ReactComponent = require("./ReactComponent");
23
+ var ReactMultiChildUpdateTypes = require("./ReactMultiChildUpdateTypes");
24
+
25
+ var flattenChildren = require("./flattenChildren");
26
+ var instantiateReactComponent = require("./instantiateReactComponent");
27
+ var shouldUpdateReactComponent = require("./shouldUpdateReactComponent");
28
+
29
+ /**
30
+ * Updating children of a component may trigger recursive updates. The depth is
31
+ * used to batch recursive updates to render markup more efficiently.
32
+ *
33
+ * @type {number}
34
+ * @private
35
+ */
36
+ var updateDepth = 0;
37
+
38
+ /**
39
+ * Queue of update configuration objects.
40
+ *
41
+ * Each object has a `type` property that is in `ReactMultiChildUpdateTypes`.
42
+ *
43
+ * @type {array<object>}
44
+ * @private
45
+ */
46
+ var updateQueue = [];
47
+
48
+ /**
49
+ * Queue of markup to be rendered.
50
+ *
51
+ * @type {array<string>}
52
+ * @private
53
+ */
54
+ var markupQueue = [];
55
+
56
+ /**
57
+ * Enqueues markup to be rendered and inserted at a supplied index.
58
+ *
59
+ * @param {string} parentID ID of the parent component.
60
+ * @param {string} markup Markup that renders into an element.
61
+ * @param {number} toIndex Destination index.
62
+ * @private
63
+ */
64
+ function enqueueMarkup(parentID, markup, toIndex) {
65
+ // NOTE: Null values reduce hidden classes.
66
+ updateQueue.push({
67
+ parentID: parentID,
68
+ parentNode: null,
69
+ type: ReactMultiChildUpdateTypes.INSERT_MARKUP,
70
+ markupIndex: markupQueue.push(markup) - 1,
71
+ textContent: null,
72
+ fromIndex: null,
73
+ toIndex: toIndex
74
+ });
75
+ }
76
+
77
+ /**
78
+ * Enqueues moving an existing element to another index.
79
+ *
80
+ * @param {string} parentID ID of the parent component.
81
+ * @param {number} fromIndex Source index of the existing element.
82
+ * @param {number} toIndex Destination index of the element.
83
+ * @private
84
+ */
85
+ function enqueueMove(parentID, fromIndex, toIndex) {
86
+ // NOTE: Null values reduce hidden classes.
87
+ updateQueue.push({
88
+ parentID: parentID,
89
+ parentNode: null,
90
+ type: ReactMultiChildUpdateTypes.MOVE_EXISTING,
91
+ markupIndex: null,
92
+ textContent: null,
93
+ fromIndex: fromIndex,
94
+ toIndex: toIndex
95
+ });
96
+ }
97
+
98
+ /**
99
+ * Enqueues removing an element at an index.
100
+ *
101
+ * @param {string} parentID ID of the parent component.
102
+ * @param {number} fromIndex Index of the element to remove.
103
+ * @private
104
+ */
105
+ function enqueueRemove(parentID, fromIndex) {
106
+ // NOTE: Null values reduce hidden classes.
107
+ updateQueue.push({
108
+ parentID: parentID,
109
+ parentNode: null,
110
+ type: ReactMultiChildUpdateTypes.REMOVE_NODE,
111
+ markupIndex: null,
112
+ textContent: null,
113
+ fromIndex: fromIndex,
114
+ toIndex: null
115
+ });
116
+ }
117
+
118
+ /**
119
+ * Enqueues setting the text content.
120
+ *
121
+ * @param {string} parentID ID of the parent component.
122
+ * @param {string} textContent Text content to set.
123
+ * @private
124
+ */
125
+ function enqueueTextContent(parentID, textContent) {
126
+ // NOTE: Null values reduce hidden classes.
127
+ updateQueue.push({
128
+ parentID: parentID,
129
+ parentNode: null,
130
+ type: ReactMultiChildUpdateTypes.TEXT_CONTENT,
131
+ markupIndex: null,
132
+ textContent: textContent,
133
+ fromIndex: null,
134
+ toIndex: null
135
+ });
136
+ }
137
+
138
+ /**
139
+ * Processes any enqueued updates.
140
+ *
141
+ * @private
142
+ */
143
+ function processQueue() {
144
+ if (updateQueue.length) {
145
+ ReactComponent.BackendIDOperations.dangerouslyProcessChildrenUpdates(
146
+ updateQueue,
147
+ markupQueue
148
+ );
149
+ clearQueue();
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Clears any enqueued updates.
155
+ *
156
+ * @private
157
+ */
158
+ function clearQueue() {
159
+ updateQueue.length = 0;
160
+ markupQueue.length = 0;
161
+ }
162
+
163
+ /**
164
+ * ReactMultiChild are capable of reconciling multiple children.
165
+ *
166
+ * @class ReactMultiChild
167
+ * @internal
168
+ */
169
+ var ReactMultiChild = {
170
+
171
+ /**
172
+ * Provides common functionality for components that must reconcile multiple
173
+ * children. This is used by `ReactDOMComponent` to mount, update, and
174
+ * unmount child components.
175
+ *
176
+ * @lends {ReactMultiChild.prototype}
177
+ */
178
+ Mixin: {
179
+
180
+ /**
181
+ * Generates a "mount image" for each of the supplied children. In the case
182
+ * of `ReactDOMComponent`, a mount image is a string of markup.
183
+ *
184
+ * @param {?object} nestedChildren Nested child maps.
185
+ * @return {array} An array of mounted representations.
186
+ * @internal
187
+ */
188
+ mountChildren: function(nestedChildren, transaction) {
189
+ var children = flattenChildren(nestedChildren);
190
+ var mountImages = [];
191
+ var index = 0;
192
+ this._renderedChildren = children;
193
+ for (var name in children) {
194
+ var child = children[name];
195
+ if (children.hasOwnProperty(name)) {
196
+ // The rendered children must be turned into instances as they're
197
+ // mounted.
198
+ var childInstance = instantiateReactComponent(child);
199
+ children[name] = childInstance;
200
+ // Inlined for performance, see `ReactInstanceHandles.createReactID`.
201
+ var rootID = this._rootNodeID + name;
202
+ var mountImage = childInstance.mountComponent(
203
+ rootID,
204
+ transaction,
205
+ this._mountDepth + 1
206
+ );
207
+ childInstance._mountIndex = index;
208
+ mountImages.push(mountImage);
209
+ index++;
210
+ }
211
+ }
212
+ return mountImages;
213
+ },
214
+
215
+ /**
216
+ * Replaces any rendered children with a text content string.
217
+ *
218
+ * @param {string} nextContent String of content.
219
+ * @internal
220
+ */
221
+ updateTextContent: function(nextContent) {
222
+ updateDepth++;
223
+ var errorThrown = true;
224
+ try {
225
+ var prevChildren = this._renderedChildren;
226
+ // Remove any rendered children.
227
+ for (var name in prevChildren) {
228
+ if (prevChildren.hasOwnProperty(name)) {
229
+ this._unmountChildByName(prevChildren[name], name);
230
+ }
231
+ }
232
+ // Set new text content.
233
+ this.setTextContent(nextContent);
234
+ errorThrown = false;
235
+ } finally {
236
+ updateDepth--;
237
+ if (!updateDepth) {
238
+ errorThrown ? clearQueue() : processQueue();
239
+ }
240
+ }
241
+ },
242
+
243
+ /**
244
+ * Updates the rendered children with new children.
245
+ *
246
+ * @param {?object} nextNestedChildren Nested child maps.
247
+ * @param {ReactReconcileTransaction} transaction
248
+ * @internal
249
+ */
250
+ updateChildren: function(nextNestedChildren, transaction) {
251
+ updateDepth++;
252
+ var errorThrown = true;
253
+ try {
254
+ this._updateChildren(nextNestedChildren, transaction);
255
+ errorThrown = false;
256
+ } finally {
257
+ updateDepth--;
258
+ if (!updateDepth) {
259
+ errorThrown ? clearQueue() : processQueue();
260
+ }
261
+ }
262
+ },
263
+
264
+ /**
265
+ * Improve performance by isolating this hot code path from the try/catch
266
+ * block in `updateChildren`.
267
+ *
268
+ * @param {?object} nextNestedChildren Nested child maps.
269
+ * @param {ReactReconcileTransaction} transaction
270
+ * @final
271
+ * @protected
272
+ */
273
+ _updateChildren: function(nextNestedChildren, transaction) {
274
+ var nextChildren = flattenChildren(nextNestedChildren);
275
+ var prevChildren = this._renderedChildren;
276
+ if (!nextChildren && !prevChildren) {
277
+ return;
278
+ }
279
+ var name;
280
+ // `nextIndex` will increment for each child in `nextChildren`, but
281
+ // `lastIndex` will be the last index visited in `prevChildren`.
282
+ var lastIndex = 0;
283
+ var nextIndex = 0;
284
+ for (name in nextChildren) {
285
+ if (!nextChildren.hasOwnProperty(name)) {
286
+ continue;
287
+ }
288
+ var prevChild = prevChildren && prevChildren[name];
289
+ var nextChild = nextChildren[name];
290
+ if (shouldUpdateReactComponent(prevChild, nextChild)) {
291
+ this.moveChild(prevChild, nextIndex, lastIndex);
292
+ lastIndex = Math.max(prevChild._mountIndex, lastIndex);
293
+ prevChild.receiveComponent(nextChild, transaction);
294
+ prevChild._mountIndex = nextIndex;
295
+ } else {
296
+ if (prevChild) {
297
+ // Update `lastIndex` before `_mountIndex` gets unset by unmounting.
298
+ lastIndex = Math.max(prevChild._mountIndex, lastIndex);
299
+ this._unmountChildByName(prevChild, name);
300
+ }
301
+ // The child must be instantiated before it's mounted.
302
+ var nextChildInstance = instantiateReactComponent(nextChild);
303
+ this._mountChildByNameAtIndex(
304
+ nextChildInstance, name, nextIndex, transaction
305
+ );
306
+ }
307
+ nextIndex++;
308
+ }
309
+ // Remove children that are no longer present.
310
+ for (name in prevChildren) {
311
+ if (prevChildren.hasOwnProperty(name) &&
312
+ !(nextChildren && nextChildren[name])) {
313
+ this._unmountChildByName(prevChildren[name], name);
314
+ }
315
+ }
316
+ },
317
+
318
+ /**
319
+ * Unmounts all rendered children. This should be used to clean up children
320
+ * when this component is unmounted.
321
+ *
322
+ * @internal
323
+ */
324
+ unmountChildren: function() {
325
+ var renderedChildren = this._renderedChildren;
326
+ for (var name in renderedChildren) {
327
+ var renderedChild = renderedChildren[name];
328
+ // TODO: When is this not true?
329
+ if (renderedChild.unmountComponent) {
330
+ renderedChild.unmountComponent();
331
+ }
332
+ }
333
+ this._renderedChildren = null;
334
+ },
335
+
336
+ /**
337
+ * Moves a child component to the supplied index.
338
+ *
339
+ * @param {ReactComponent} child Component to move.
340
+ * @param {number} toIndex Destination index of the element.
341
+ * @param {number} lastIndex Last index visited of the siblings of `child`.
342
+ * @protected
343
+ */
344
+ moveChild: function(child, toIndex, lastIndex) {
345
+ // If the index of `child` is less than `lastIndex`, then it needs to
346
+ // be moved. Otherwise, we do not need to move it because a child will be
347
+ // inserted or moved before `child`.
348
+ if (child._mountIndex < lastIndex) {
349
+ enqueueMove(this._rootNodeID, child._mountIndex, toIndex);
350
+ }
351
+ },
352
+
353
+ /**
354
+ * Creates a child component.
355
+ *
356
+ * @param {ReactComponent} child Component to create.
357
+ * @param {string} mountImage Markup to insert.
358
+ * @protected
359
+ */
360
+ createChild: function(child, mountImage) {
361
+ enqueueMarkup(this._rootNodeID, mountImage, child._mountIndex);
362
+ },
363
+
364
+ /**
365
+ * Removes a child component.
366
+ *
367
+ * @param {ReactComponent} child Child to remove.
368
+ * @protected
369
+ */
370
+ removeChild: function(child) {
371
+ enqueueRemove(this._rootNodeID, child._mountIndex);
372
+ },
373
+
374
+ /**
375
+ * Sets this text content string.
376
+ *
377
+ * @param {string} textContent Text content to set.
378
+ * @protected
379
+ */
380
+ setTextContent: function(textContent) {
381
+ enqueueTextContent(this._rootNodeID, textContent);
382
+ },
383
+
384
+ /**
385
+ * Mounts a child with the supplied name.
386
+ *
387
+ * NOTE: This is part of `updateChildren` and is here for readability.
388
+ *
389
+ * @param {ReactComponent} child Component to mount.
390
+ * @param {string} name Name of the child.
391
+ * @param {number} index Index at which to insert the child.
392
+ * @param {ReactReconcileTransaction} transaction
393
+ * @private
394
+ */
395
+ _mountChildByNameAtIndex: function(child, name, index, transaction) {
396
+ // Inlined for performance, see `ReactInstanceHandles.createReactID`.
397
+ var rootID = this._rootNodeID + name;
398
+ var mountImage = child.mountComponent(
399
+ rootID,
400
+ transaction,
401
+ this._mountDepth + 1
402
+ );
403
+ child._mountIndex = index;
404
+ this.createChild(child, mountImage);
405
+ this._renderedChildren = this._renderedChildren || {};
406
+ this._renderedChildren[name] = child;
407
+ },
408
+
409
+ /**
410
+ * Unmounts a rendered child by name.
411
+ *
412
+ * NOTE: This is part of `updateChildren` and is here for readability.
413
+ *
414
+ * @param {ReactComponent} child Component to unmount.
415
+ * @param {string} name Name of the child in `this._renderedChildren`.
416
+ * @private
417
+ */
418
+ _unmountChildByName: function(child, name) {
419
+ // TODO: When is this not true?
420
+ if (ReactComponent.isValidComponent(child)) {
421
+ this.removeChild(child);
422
+ child._mountIndex = null;
423
+ child.unmountComponent();
424
+ delete this._renderedChildren[name];
425
+ }
426
+ }
427
+
428
+ }
429
+
430
+ };
431
+
432
+ module.exports = ReactMultiChild;