Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/widget-core/tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export function tsx(tag: any, properties = {}, ...children: any[]): DNode {
properties = properties === null ? {} : properties;
if (typeof tag === 'string') {
return v(tag, properties, children);
} else if (tag.type === 'registry' && (properties as any).__autoRegistryItem) {
const name = (properties as any).__autoRegistryItem;
delete (properties as any).__autoRegistryItem;
return w(name, properties, children);
} else if (tag.type === REGISTRY_ITEM) {
const registryItem = new tag();
return w(registryItem.name, properties, children);
Expand Down
8 changes: 8 additions & 0 deletions tests/widget-core/unit/tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ registerSuite('tsx', {
assert.deepEqual(node.properties, { hello: 'world' } as any);
assert.deepEqual(node.children, ['child']);
},
'tsx generate a WNode from a registry type'() {
const node: WNode = tsx({ type: 'registry' }, { hello: 'world', __autoRegistryItem: 'foo' }, [
'child'
]) as WNode;
assert.deepEqual(node.widgetConstructor, 'foo');
assert.deepEqual(node.properties, { hello: 'world' } as any);
assert.deepEqual(node.children, ['child']);
},
'children arrays are spread correctly'() {
const node: VNode = tsx('div', { hello: 'world' }, ['child', ['child-2', ['child-3']]]) as VNode;
assert.deepEqual(node.tag, 'div');
Expand Down