Skip to content

Commit

Permalink
Allow numbers in vdom (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
maier49 authored Jun 29, 2020
1 parent 9e7cf35 commit e548f88
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/core/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,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 @@ -391,12 +391,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 @@ -1399,7 +1405,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 @@ -101,7 +101,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

0 comments on commit e548f88

Please sign in to comment.