From c1bff77f509ce59423ea2af7cd5c8d6a1523d72d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20B=C3=BCchele?= Date: Fri, 24 May 2019 03:06:02 -0700 Subject: [PATCH] recursively invalidate nodes Summary: When a node invalidates, all its children need to be updated. This was the case in v1 of Layout Inspector (https://github.com/facebook/flipper/blob/3141b954bf2be4fea98924637c18265d24407868/src/plugins/layout/index.js#L684-L692) but got lost when writing v2. Reviewed By: passy Differential Revision: D15469096 fbshipit-source-id: 9ef5368387ccbce6e5c71de28c24f5790906cee9 --- src/plugins/layout/Inspector.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/plugins/layout/Inspector.js b/src/plugins/layout/Inspector.js index d36899f27..7faa68a38 100644 --- a/src/plugins/layout/Inspector.js +++ b/src/plugins/layout/Inspector.js @@ -109,14 +109,7 @@ export default class Inspector extends Component { 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 { } } + invalidate(ids: Array): Promise> { + if (ids.length === 0) { + return Promise.resolve([]); + } + return this.getNodes(ids, {}).then((elements: Array) => { + 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']: {