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

Typed children for function-based widgets #544

Merged
merged 16 commits into from
Oct 1, 2019
Merged
Prev Previous commit
Next Next commit
address pull request feedback
  • Loading branch information
agubler committed Sep 30, 2019
commit b2860f44d3ebd51fc016decc9339eedd63e8e5c5
10 changes: 5 additions & 5 deletions src/core/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ function updateAttributes(
export function w<W extends WidgetBaseTypes>(
node: WNode<W>,
properties: Partial<W['properties']>,
children?: W['properties'] extends { children: any } ? W['properties']['children'] : W['children']
children?: W['properties'] extends { __children__: any } ? W['properties']['__children__'] : W['children']
): WNode<W>;
export function w<W extends WidgetBaseTypes>(
widgetConstructor: WNodeFactory<W>,
properties: WithOptional<W['properties'], 'children'>,
children?: W['properties'] extends { children: any } ? W['properties']['children'] : W['children']
properties: WithOptional<W['properties'], '__children__'>,
children?: W['properties'] extends { __children__: any } ? W['properties']['__children__'] : W['children']
): WNode<W>;
export function w<W extends WidgetBaseTypes>(
widgetConstructor: Constructor<W> | RegistryLabel | LazyDefine<W>,
Expand All @@ -334,8 +334,8 @@ export function w<W extends WidgetBaseTypes>(
properties: W['properties'],
children?: any
): WNode<W> {
if ((properties as any).children) {
delete (properties as any).children;
if ((properties as any).__children__) {
delete (properties as any).__children__;
}

if (isWNodeFactory<W>(widgetConstructorOrNode)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/core/unit/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3458,12 +3458,12 @@ jsdomDescribe('vdom', () => {
return foo;
});
const r = renderer(() =>
v('div', [Foo({ foo: 'foo' }, (foo) => v('div', [foo])), Foo({ foo: 'foo' })])
v('div', [w(Foo, { foo: 'foo' }, (foo) => foo), Foo({ foo: 'foo' }, (foo) => v('div', [foo])), Foo({ foo: 'foo' })])
);
const root = document.createElement('div');
r.mount({ domNode: root });
resolvers.resolve();
assert.strictEqual(root.outerHTML, '<div><div><div>foo</div>foo</div></div>');
assert.strictEqual(root.outerHTML, '<div><div>foo<div>foo</div>foo</div></div>');
});

describe('core middleware', () => {
Expand Down