recursively invalidate nodes
Summary: When a node invalidates, all its children need to be updated. This was the case in v1 of Layout Inspector (3141b954bf/src/plugins/layout/index.js (L684-L692)) but got lost when writing v2.
Reviewed By: passy
Differential Revision: D15469096
fbshipit-source-id: 9ef5368387ccbce6e5c71de28c24f5790906cee9
This commit is contained in:
committed by
Facebook Github Bot
parent
dd2d309c0c
commit
c1bff77f50
@@ -109,14 +109,7 @@ export default class Inspector extends Component<Props> {
|
||||
const ids = nodes
|
||||
.map(n => [n.id, ...(n.children || [])])
|
||||
.reduce((acc, cv) => acc.concat(cv), []);
|
||||
this.getNodes(ids, {}).then(nodes => {
|
||||
nodes.forEach(node => {
|
||||
// Check if there are new IDs in the children array, and call getNodes()
|
||||
// if there are any
|
||||
const cIds = node.children.filter(c => !this.elements()[c]);
|
||||
this.getNodes(cIds, {});
|
||||
});
|
||||
});
|
||||
this.invalidate(ids);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -166,6 +159,19 @@ export default class Inspector extends Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
invalidate(ids: Array<ElementID>): Promise<Array<Element>> {
|
||||
if (ids.length === 0) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
return this.getNodes(ids, {}).then((elements: Array<Element>) => {
|
||||
const children = elements
|
||||
.filter((element: Element) => this.elements()[element.id]?.expanded)
|
||||
.map((element: Element) => element.children)
|
||||
.reduce((acc, val) => acc.concat(val), []);
|
||||
return this.invalidate(children);
|
||||
});
|
||||
}
|
||||
|
||||
updateElement(id: ElementID, data: Object) {
|
||||
this.props.setPersistedState({
|
||||
[this.props.ax ? 'AXelements' : 'elements']: {
|
||||
|
||||
Reference in New Issue
Block a user