Reverted immutable element change (for now)
Brian Vaughn committed
Feb 8, 2019 at 16:05 UTC
c6b0338f13b47c94b965f301619c7f36763eae73
2 files changed
+9
-19
src/devtools/store.js
+7
-17
@@ -29,7 +29,7 @@ const debug = (methodName, ...args) => {
29
*/
30
export default class Store extends EventEmitter {
31
// Map of ID to Element.
32
- // Elements are read-only so they wokr well with memoization.
32
+ // Elements are mutable (for now) to avoid excessive cloning during tree updates.
33
_idToElement: Map<number, Element> = new Map();
34
35
// Total number of visible elements (within all roots).
@@ -283,11 +283,7 @@ export default class Store extends EventEmitter {
283
// Maybe in the future we'll revisit this.
284
} else {
285
parentElement = ((this._idToElement.get(parentID): any): Element);
286
-
287
- this._idToElement.set(parentID, {
288
- ...parentElement,
289
- children: parentElement.children.concat(id),
290
- });
286
+ parentElement.children = parentElement.children.concat(id);
287
288
const element: Element = {
289
children: [],
@@ -331,12 +327,9 @@ export default class Store extends EventEmitter {
327
this._roots = this._roots.filter(rootID => rootID !== id);
328
this._rootIDToRendererID.delete(id);
329
} else {
334
- this._idToElement.set(parentID, {
335
- ...parentElement,
336
- children: parentElement.children.filter(
337
- childID => childID !== id
338
- ),
339
- });
330
+ parentElement.children = parentElement.children.filter(
331
+ childID => childID !== id
332
+ );
333
}
334
335
// Track removed items so search results can be updated
@@ -358,6 +351,7 @@ export default class Store extends EventEmitter {
351
debug('Re-order', `fiber ${id} children ${children.join(',')}`);
352
353
element = ((this._idToElement.get(id): any): Element);
354
+ element.children = Array.from(children);
355
356
const prevWeight = element.weight;
357
let childWeight = 0;
@@ -367,11 +361,7 @@ export default class Store extends EventEmitter {
361
childWeight += child.weight;
362
});
363
370
- this._idToElement.set(id, {
371
- ...element,
372
- children: Array.from(children),
373
- weight: childWeight + 1,
374
- });
364
+ element.weight = childWeight + 1;
365
366
weightDelta = childWeight + 1 - prevWeight;
367
break;
src/devtools/types.js
+2
-2
@@ -18,7 +18,7 @@ export type ElementType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
18
// Some of its information (e.g. id, type, displayName) come from the backend.
19
// Other bits (e.g. weight and depth) are computed on the frontend for windowing and display purposes.
20
// Elements are udpated on a push basis– meaning the backend pushes updates to the frontend when needed.
21
-export type Element = $ReadOnly<{|
21
+export type Element = {|
22
id: number,
23
parentID: number,
24
children: Array<number>,
@@ -37,7 +37,7 @@ export type Element = $ReadOnly<{|
37
// This property is used to quickly determine the total number of Elements,
38
// and the Element at any given index (for windowing purposes).
39
weight: number,
40
-|}>;
40
+|};
41
42
export type Owner = {|
43
displayName: string,