From 989b0d6709255c4934238cd1b7c9190ffb644db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 30 Mar 2022 16:10:04 +0200 Subject: [PATCH] [REF] improve children handling in components/fibers --- src/component/component_node.ts | 22 ++++------------------ src/component/fibers.ts | 11 +++++++++-- tests/components/concurrency.test.ts | 16 ++++++++-------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/component/component_node.ts b/src/component/component_node.ts index 5f7c3a12..656d6727 100644 --- a/src/component/component_node.ts +++ b/src/component/component_node.ts @@ -116,9 +116,10 @@ export function component

( } node = new ComponentNode(C, props, ctx.app, ctx); ctx.children[key] = node; - node.initiateRender(new Fiber(node, parentFiber)); } + parentFiber.childrenMap[key] = node; + parentFiber.root!.reachedChildren.add(node); return node; } @@ -326,6 +327,7 @@ export class ComponentNode

implements VNode implements VNode 0; + this.children = this.fiber!.childrenMap; this.bdom!.patch(this!.fiber!.bdom!, hasChildren); - if (hasChildren) { - this.cleanOutdatedChildren(); - } this.fiber!.appliedToDom = true; this.fiber = null; } @@ -359,20 +359,6 @@ export class ComponentNode

implements VNode { await nextTick(); expect(fixture.innerHTML).toBe(""); expect([ - "Parent:willRender", "ChildA:willDestroy", + "Parent:willRender", "ChildA:setup", "ChildA:willStart", "ChildB:setup", @@ -696,8 +696,8 @@ test("rendering component again in next microtick", async () => { "Child:setup", "Child:willStart", "Parent:rendered", - "Parent:willRender", "Child:willDestroy", + "Parent:willRender", "Child:setup", "Child:willStart", "Parent:rendered", @@ -1725,6 +1725,7 @@ test("concurrent renderings scenario 10", async () => { expect(fixture.innerHTML).toBe("

"); expect([ "ComponentA:willRender", + "ComponentC:willDestroy", "ComponentB:willUpdateProps", "ComponentA:rendered", ]).toBeLogged(); @@ -1735,7 +1736,6 @@ test("concurrent renderings scenario 10", async () => { expect(rendered).toBe(1); expect([ "ComponentB:willRender", - "ComponentC:willDestroy", "ComponentC:setup", "ComponentC:willStart", "ComponentB:rendered", @@ -2275,11 +2275,11 @@ test("concurrent renderings scenario 16", async () => { "D:setup", "D:willStart", "C:rendered", + "D:willDestroy", "B:willRender", "C:willUpdateProps", "B:rendered", "C:willRender", - "D:willDestroy", "D:setup", "D:willStart", "C:rendered", @@ -2990,13 +2990,13 @@ test("t-key on dom node having a component", async () => { expect(fixture.innerHTML).toBe("
3
"); expect([ + "Child (2):willDestroy", "Child (3):setup", "Child (3):willStart", "Child (3):willRender", "Child (3):rendered", "Child (1):willUnmount", "Child (1):willDestroy", - "Child (2):willDestroy", "Child (3):mounted", ]).toBeLogged(); }); @@ -3048,13 +3048,13 @@ test("t-key on dynamic async component (toggler is never patched)", async () => expect(fixture.innerHTML).toBe("
3
"); expect([ + "Child (2):willDestroy", "Child (3):setup", "Child (3):willStart", "Child (3):willRender", "Child (3):rendered", "Child (1):willUnmount", "Child (1):willDestroy", - "Child (2):willDestroy", "Child (3):mounted", ]).toBeLogged(); }); @@ -3107,13 +3107,13 @@ test("t-foreach with dynamic async component", async () => { expect(fixture.innerHTML).toBe("
3
"); expect([ + "Child (2):willDestroy", "Child (3):setup", "Child (3):willStart", "Child (3):willRender", "Child (3):rendered", "Child (1):willUnmount", "Child (1):willDestroy", - "Child (2):willDestroy", "Child (3):mounted", ]).toBeLogged(); });