Add parent reference to desktop node
Summary: There are some situations where we are doing a traversal of the entire node hierachy looking for something. In some situtations this linear search can be replaced with a walk up the anchestory path making the code easier to understand and more efficient Reviewed By: lblasa Differential Revision: D41548253 fbshipit-source-id: 4fb2141282f1f9663835c3b7812d30dcc59b707e
This commit is contained in:
committed by
Facebook GitHub Bot
parent
57dcf72763
commit
8eb0866760
@@ -128,8 +128,9 @@ export function plugin(client: PluginClient<Events>) {
|
||||
}
|
||||
|
||||
event.nodes.forEach((node) => {
|
||||
draft.nodes.set(node.id, node);
|
||||
draft.nodes.set(node.id, {...node});
|
||||
});
|
||||
setParentPointers(rootId.get()!!, undefined, draft.nodes);
|
||||
});
|
||||
|
||||
uiState.treeState.update((draft) => {
|
||||
@@ -164,6 +165,21 @@ export function plugin(client: PluginClient<Events>) {
|
||||
};
|
||||
}
|
||||
|
||||
function setParentPointers(
|
||||
cur: Id,
|
||||
parent: Id | undefined,
|
||||
nodes: Map<Id, UINode>,
|
||||
) {
|
||||
const node = nodes.get(cur);
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
node.parent = parent;
|
||||
node.children.forEach((child) => {
|
||||
setParentPointers(child, cur, nodes);
|
||||
});
|
||||
}
|
||||
|
||||
function collapseinActiveChildren(node: UINode, draft: TreeState) {
|
||||
if (node.activeChild) {
|
||||
const inactiveChildren = node.children.filter(
|
||||
|
||||
Reference in New Issue
Block a user