Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 34ed7be

Browse files
author
Brian Vaughn
committed
Store properly updates parent-child map for reparented fibers
1 parent ef8c92d commit 34ed7be

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

frontend/Store.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,12 @@ class Store extends EventEmitter {
647647
}
648648

649649
_mountComponent(data: DataType) {
650+
if (this._nodes.has(data.id)) {
651+
// This node has been re-parented.
652+
this._updateComponent(data);
653+
return;
654+
}
655+
650656
var map = Map(data).set('renders', 1);
651657
if (data.nodeType === 'Composite') {
652658
map = map.set('collapsed', true);
@@ -663,16 +669,18 @@ class Store extends EventEmitter {
663669
}
664670

665671
_updateComponent(data: DataType) {
666-
var node = this.get(data.id);
672+
var id = data.id;
673+
var node = this.get(id);
667674
if (!node) {
668675
return;
669676
}
670677
data.renders = node.get('renders') + 1;
671-
this._nodes = this._nodes.mergeIn([data.id], Map(data));
678+
this._nodes = this._nodes.mergeIn([id], Map(data));
672679
if (data.children && data.children.forEach) {
673680
data.children.forEach(cid => {
674-
if (!this._parents.get(cid)) {
675-
this._parents = this._parents.set(cid, data.id);
681+
var pid = this._parents.get(cid);
682+
if (!pid) {
683+
this._parents = this._parents.set(cid, id);
676684
var childNode = this._nodes.get(cid);
677685
var childID = childNode.get('id');
678686
if (
@@ -687,6 +695,9 @@ class Store extends EventEmitter {
687695
this.emit('searchRoots');
688696
this.highlightSearch();
689697
}
698+
} else if (pid !== id) {
699+
// This node has been re-parented.
700+
this._parents = this._parents.set(cid, id);
690701
}
691702
});
692703
}

0 commit comments

Comments
 (0)