skip first value from observable

This commit is contained in:
Mads Rasmussen
2023-11-24 12:55:01 +01:00
parent 237a3f277f
commit d380ee5f09

View File

@@ -26,6 +26,7 @@ export class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemModelBase>
#hasChildren = new UmbBooleanState(false);
hasChildren = this.#hasChildren.asObservable();
#hasChildrenInitValueFlag = false;
#isLoading = new UmbBooleanState(false);
isLoading = this.#isLoading.asObservable();
@@ -194,9 +195,14 @@ export class UmbTreeItemContextBase<TreeItemType extends UmbTreeItemModelBase>
const observable = await this.treeContext.childrenOf(this.unique);
// observe if any children will be added runtime to a tree item
// observe if any children will be added runtime to a tree item. Nested items/folders etc.
this.observe(observable.pipe(map((children) => children.length > 0)), (hasChildren) => {
this.#hasChildren.next(hasChildren);
// we need to skip the first value, because it will also return false until a child is in the store
// we therefor rely on the value from the tree item itself
if (this.#hasChildrenInitValueFlag === true) {
this.#hasChildren.next(hasChildren);
}
this.#hasChildrenInitValueFlag = true;
});
}