core-plugin-api: make useElementFilter filter for undefined component data instead of falsy

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-06-16 17:42:06 +02:00
parent d00a3fcd95
commit 4d63ce7c1b
@@ -88,19 +88,21 @@ class ElementCollection {
const selection = selectChildren(
this.node,
this.featureFlagsApi,
node => Boolean(getComponentData(node, query.key)),
node => getComponentData(node, query.key) !== undefined,
query.withStrictError,
);
return new ElementCollection(selection, this.featureFlagsApi);
}
findComponentData<T>(query: { key: string }): T[] {
const selection = selectChildren(this.node, this.featureFlagsApi, node =>
Boolean(getComponentData(node, query.key)),
const selection = selectChildren(
this.node,
this.featureFlagsApi,
node => getComponentData(node, query.key) !== undefined,
);
return selection
.map(node => getComponentData<T>(node, query.key))
.filter((data: T | undefined): data is T => Boolean(data));
.filter((data: T | undefined): data is T => data !== undefined);
}
getElements<Props extends { [name: string]: unknown }>(): Array<