From 46cb699463320d223e92635ed935cd397a1dca5f Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Fri, 21 Apr 2023 17:36:06 +0200 Subject: [PATCH] refactor(player/DOMManager): notMountedChildren rename --- .../app/player/web/managers/DOM/VirtualDOM.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/frontend/app/player/web/managers/DOM/VirtualDOM.ts b/frontend/app/player/web/managers/DOM/VirtualDOM.ts index 47ca82989..983a3b5f1 100644 --- a/frontend/app/player/web/managers/DOM/VirtualDOM.ts +++ b/frontend/app/player/web/managers/DOM/VirtualDOM.ts @@ -49,24 +49,25 @@ export abstract class VNode { public abstract applyChanges(): void } - type VChild = VElement | VText abstract class VParent extends VNode{ + /** + */ protected children: VChild[] = [] - private childrenToMount: Set = new Set() + private notMontedChildren: Set = new Set() insertChildAt(child: VChild, index: number) { if (child.parentNode) { child.parentNode.removeChild(child) } this.children.splice(index, 0, child) - this.childrenToMount.add(child) + this.notMontedChildren.add(child) child.parentNode = this } removeChild(child: VChild) { this.children = this.children.filter(ch => ch !== child) - this.childrenToMount.delete(child) + this.notMontedChildren.delete(child) child.parentNode = null } @@ -74,13 +75,13 @@ abstract class VParent extends VNode{ let nextMounted: VChild | null = null for (let i = this.children.length-1; i >= 0; i--) { const child = this.children[i] - if (this.childrenToMount.has(child) && + if (this.notMontedChildren.has(child) && (!shouldInsert || shouldInsert(child)) // is there a better way of not-knowing about subclass logic on prioritized insertion? ) { this.node.insertBefore(child.node, nextMounted ? nextMounted.node : null) - this.childrenToMount.delete(child) + this.notMontedChildren.delete(child) } - if (!this.childrenToMount.has(child)) { + if (!this.notMontedChildren.has(child)) { nextMounted = child } } @@ -91,7 +92,7 @@ abstract class VParent extends VNode{ this.children.forEach(child => child.applyChanges()) /* Inserting */ this.mountChildren() - if (this.childrenToMount.size !== 0) { + if (this.notMontedChildren.size !== 0) { console.error("VParent: Something went wrong with children insertion") } /* Removing in-between */