From bf93bdea48ff423d4cbb910f18c0f2c8af347ff7 Mon Sep 17 00:00:00 2001 From: Anthony Gubler Date: Tue, 5 Nov 2019 12:57:50 +0000 Subject: [PATCH 1/3] failing unit test for diff property on the first render --- tests/core/unit/vdom.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/core/unit/vdom.tsx b/tests/core/unit/vdom.tsx index 20d26aeb8..325730824 100644 --- a/tests/core/unit/vdom.tsx +++ b/tests/core/unit/vdom.tsx @@ -3841,6 +3841,29 @@ jsdomDescribe('vdom', () => { resolvers.resolve(); assert.strictEqual(root.outerHTML, '
first
'); }); + + it('should call diff property for the first render', () => { + const createWidget = create({ diffProperty }); + let counter = 0; + const Foo = createWidget(({ middleware }) => { + middleware.diffProperty('key', () => { + counter++; + }); + return v('div', [`${counter}`]); + }); + const App = createWidget(() => { + return v('div', [ + v('button', { + }), + Foo({ key: 'foo' }) + ]); + }); + const r = renderer(() => App({})); + const root = document.createElement('div'); + r.mount({ domNode: root }); + assert.strictEqual(root.outerHTML, '
1
'); + sendEvent(root.childNodes[0].childNodes[0] as HTMLButtonElement, 'click'); + }); }); }); }); From 13a9b6bc94e22d470a8bb528c6a9f592d8de2033 Mon Sep 17 00:00:00 2001 From: Anthony Gubler Date: Tue, 5 Nov 2019 13:02:16 +0000 Subject: [PATCH 2/3] Call diff properties immediately when they are registered --- src/core/vdom.ts | 1 + tests/core/unit/vdom.tsx | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/vdom.ts b/src/core/vdom.ts index 7f4a09fd7..dd694ec93 100644 --- a/src/core/vdom.ts +++ b/src/core/vdom.ts @@ -878,6 +878,7 @@ export const diffProperty = factory(({ id }) => { widgetMeta.customDiffProperties = widgetMeta.customDiffProperties || new Set(); const propertyDiffMap = widgetMeta.customDiffMap.get(id) || new Map(); if (!propertyDiffMap.has(propertyName)) { + diff({}, widgetMeta.properties); propertyDiffMap.set(propertyName, diff); widgetMeta.customDiffProperties.add(propertyName); } diff --git a/tests/core/unit/vdom.tsx b/tests/core/unit/vdom.tsx index 325730824..4469ab63d 100644 --- a/tests/core/unit/vdom.tsx +++ b/tests/core/unit/vdom.tsx @@ -3790,7 +3790,6 @@ jsdomDescribe('vdom', () => { let counter = 0; const Foo = createWidget(({ middleware }) => { middleware.diffProperty('key', (current: any, properties: any) => { - assert.deepEqual(current, { key: 'foo' }); assert.deepEqual(properties, { key: 'foo' }); middleware.invalidator(); }); From 0b2c1c6dc313c9213cbb17c68d68bbda16faf2ce Mon Sep 17 00:00:00 2001 From: Anthony Gubler Date: Tue, 5 Nov 2019 13:07:02 +0000 Subject: [PATCH 3/3] prettier --- tests/core/unit/vdom.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/core/unit/vdom.tsx b/tests/core/unit/vdom.tsx index 4469ab63d..bef7a638f 100644 --- a/tests/core/unit/vdom.tsx +++ b/tests/core/unit/vdom.tsx @@ -3851,11 +3851,7 @@ jsdomDescribe('vdom', () => { return v('div', [`${counter}`]); }); const App = createWidget(() => { - return v('div', [ - v('button', { - }), - Foo({ key: 'foo' }) - ]); + return v('div', [v('button', {}), Foo({ key: 'foo' })]); }); const r = renderer(() => App({})); const root = document.createElement('div');