Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that diff property call backs are called immediately when registered #572

Merged
merged 3 commits into from Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/core/vdom.ts
Expand Up @@ -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);
}
Expand Down
20 changes: 19 additions & 1 deletion tests/core/unit/vdom.tsx
Expand Up @@ -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();
});
Expand Down Expand Up @@ -3841,6 +3840,25 @@ jsdomDescribe('vdom', () => {
resolvers.resolve();
assert.strictEqual(root.outerHTML, '<div><div><button></button><div>first</div></div></div>');
});

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, '<div><div><button></button><div>1</div></div></div>');
sendEvent(root.childNodes[0].childNodes[0] as HTMLButtonElement, 'click');
});
});
});
});
Expand Down