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

Allow numbers in vdom #781

Merged
merged 1 commit into from
Jun 29, 2020
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
2 changes: 1 addition & 1 deletion src/core/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export interface WNode<W extends WidgetBaseTypes = any> {
/**
* union type for all possible return types from render
*/
export type DNode<W extends WidgetBaseTypes = any> = VNode | WNode<W> | undefined | null | string | boolean;
export type DNode<W extends WidgetBaseTypes = any> = VNode | WNode<W> | undefined | null | string | boolean | number;

/**
* Property Change record for specific property diff functions
Expand Down
12 changes: 9 additions & 3 deletions src/core/vdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,18 @@ export function isWNode<W extends WidgetBaseTypes = any>(child: any): child is W

export function isVNode(child: DNode): child is VNode {
return Boolean(
child && child !== true && typeof child !== 'string' && (child.type === VNODE || child.type === DOMVNODE)
child &&
child !== true &&
typeof child !== 'number' &&
typeof child !== 'string' &&
(child.type === VNODE || child.type === DOMVNODE)
);
}

export function isDomVNode(child: DNode): child is DomVNode {
return Boolean(child && child !== true && typeof child !== 'string' && child.type === DOMVNODE);
return Boolean(
child && child !== true && typeof child !== 'number' && typeof child !== 'string' && child.type === DOMVNODE
);
}

export function isElementNode(value: any): value is Element {
Expand Down Expand Up @@ -1301,7 +1307,7 @@ export function renderer(renderer: () => RenderResult): Renderer {
if (!renderedItem || renderedItem === true) {
continue;
}
if (typeof renderedItem === 'string') {
if (typeof renderedItem === 'string' || typeof renderedItem === 'number') {
renderedItem = toTextVNode(renderedItem);
}
const owningNode = _nodeToWrapperMap.get(renderedItem);
Expand Down
2 changes: 1 addition & 1 deletion src/testing/assertRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function format(nodes: DNode | DNode[], depth = 0): string {
str = `${str}\n${getTabs(depth)}`;
}

if (typeof node === 'string') {
if (typeof node === 'string' || typeof node === 'number') {
return `${str}${node}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/testing/harness/support/assertRender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function formatDNodes(nodes: DNode | DNode[], depth: number = 0): string
}
result = `${result}${tabs}`;

if (typeof node === 'string') {
if (typeof node === 'string' || typeof node === 'number') {
return `${result}"${node}"`;
}

Expand Down