@samitouri / QOS-React / commits / dc188dd521

Update ReactNativeDOMIDOperations to deal with a single parent node

This is the new protocol.

Sebastian Markbage committed Apr 5, 2016 at 01:12 UTC dc188dd5216257568f97700741382bbb8d13d243
1 file changed +27 -30
src/renderers/native/ReactNative/ReactNativeDOMIDOperations.js
+27 -30
@@ -11,6 +11,7 @@
11 */
12 'use strict';
13
14 +var ReactNativeComponentTree = require('ReactNativeComponentTree');
15 var ReactNativeTagHandles = require('ReactNativeTagHandles');
16 var ReactMultiChildUpdateTypes = require('ReactMultiChildUpdateTypes');
17 var ReactPerf = require('ReactPerf');
@@ -24,50 +25,46 @@ var UIManager = require('UIManager');
25 * (including deletes/moves). TODO: refactor so this can be shared with
26 * DOMChildrenOperations.
27 *
27 - * @param {array<object>} updates List of update configurations.
28 + * @param {ReactNativeBaseComponent} updates List of update configurations.
29 * @param {array<string>} markup List of markup strings - in the case of React
30 * IOS, the ids of new components assumed to be already created.
31 */
31 -var dangerouslyProcessChildrenUpdates = function(childrenUpdates, markupList) {
32 +var dangerouslyProcessChildrenUpdates = function(inst, childrenUpdates) {
33 if (!childrenUpdates.length) {
34 return;
35 }
35 - var byContainerTag = {};
36 - // Group by parent ID - send them across the bridge in separate commands per
37 - // containerID.
36 +
37 + var containerTag = ReactNativeComponentTree.getNodeFromInstance(inst);
38 +
39 + var moveFromIndices;
40 + var moveToIndices;
41 + var addChildTags;
42 + var addAtIndices;
43 + var removeAtIndices;
44 +
45 for (var i = 0; i < childrenUpdates.length; i++) {
46 var update = childrenUpdates[i];
40 - var containerTag = update.parentID;
41 - throw new Error('parentID is borked. See changes to multiChild');
42 - var updates = byContainerTag[containerTag] || (byContainerTag[containerTag] = {});
47 if (update.type === ReactMultiChildUpdateTypes.MOVE_EXISTING) {
44 - (updates.moveFromIndices || (updates.moveFromIndices = [])).push(update.fromIndex);
45 - (updates.moveToIndices || (updates.moveToIndices = [])).push(update.toIndex);
48 + (moveFromIndices || (moveFromIndices = [])).push(update.fromIndex);
49 + (moveToIndices || (moveToIndices = [])).push(update.toIndex);
50 } else if (update.type === ReactMultiChildUpdateTypes.REMOVE_NODE) {
47 - (updates.removeAtIndices || (updates.removeAtIndices = [])).push(update.fromIndex);
51 + (removeAtIndices || (removeAtIndices = [])).push(update.fromIndex);
52 } else if (update.type === ReactMultiChildUpdateTypes.INSERT_MARKUP) {
49 - var mountImage = markupList[update.markupIndex];
53 + var mountImage = update.content;
54 var tag = mountImage;
51 - var rootNodeID = mountImage.rootNodeID;
52 - (updates.addAtIndices || (updates.addAtIndices = [])).push(update.toIndex);
53 - (updates.addChildTags || (updates.addChildTags = [])).push(tag);
55 + (addAtIndices || (addAtIndices = [])).push(update.toIndex);
56 + (addChildTags || (addChildTags = [])).push(tag);
57 }
58 }
56 - // Note this enumeration order will be different on V8! Move `byContainerTag`
57 - // to a sparse array as soon as we confirm there are not horrible perf
58 - // penalties.
59 - for (var updateParentTagString in byContainerTag) {
60 - var updateParentTagNumber = +updateParentTagString;
61 - var childUpdatesToSend = byContainerTag[updateParentTagNumber];
62 - UIManager.manageChildren(
63 - updateParentTagNumber,
64 - childUpdatesToSend.moveFromIndices,
65 - childUpdatesToSend.moveToIndices,
66 - childUpdatesToSend.addChildTags,
67 - childUpdatesToSend.addAtIndices,
68 - childUpdatesToSend.removeAtIndices
69 - );
70 - }
59 +
60 + UIManager.manageChildren(
61 + containerTag,
62 + moveFromIndices,
63 + moveToIndices,
64 + addChildTags,
65 + addAtIndices,
66 + removeAtIndices
67 + );
68 };
69
70 /**