From 806a5e7b3008a92bc08b3469dc144f3b4b12fd01 Mon Sep 17 00:00:00 2001 From: Strider Date: Mon, 9 Oct 2017 02:17:58 +0300 Subject: [PATCH 1/2] h: reduce duplication, by bringing VNodes and VNodesSparse types. --- src/h.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/h.ts b/src/h.ts index 5e46b4b..469dd0b 100644 --- a/src/h.ts +++ b/src/h.ts @@ -1,13 +1,15 @@ import {vnode, VNode, VNodeData} from './vnode'; +export type VNodes = Array; +export type VNodesSparse = Array; import * as is from './is'; -function addNS(data: any, children: Array | undefined, sel: string | undefined): void { +function addNS(data: any, children: VNodes | undefined, sel: string | undefined): void { data.ns = 'http://www.w3.org/2000/svg'; if (sel !== 'foreignObject' && children !== undefined) { for (let i = 0; i < children.length; ++i) { let childData = children[i].data; if (childData !== undefined) { - addNS(childData, (children[i] as VNode).children as Array, children[i].sel); + addNS(childData, (children[i] as VNode).children as VNodes, children[i].sel); } } } @@ -16,9 +18,9 @@ function addNS(data: any, children: Array | undefined, sel: string | unde export function h(sel: string): VNode; export function h(sel: string, data: VNodeData): VNode; export function h(sel: string, text: string): VNode; -export function h(sel: string, children: Array): VNode; +export function h(sel: string, children: VNodesSparse): VNode; export function h(sel: string, data: VNodeData, text: string): VNode; -export function h(sel: string, data: VNodeData, children: Array): VNode; +export function h(sel: string, data: VNodeData, children: VNodesSparse): VNode; export function h(sel: any, b?: any, c?: any): VNode { var data: VNodeData = {}, children: any, text: any, i: number; if (c !== undefined) { From 17a6d312bb5f6bfacf3dac8d0501eae830b16dcc Mon Sep 17 00:00:00 2001 From: Strider Date: Mon, 9 Oct 2017 02:18:55 +0300 Subject: [PATCH 2/2] h: allow VNodesSparse to accept single VNode, because underlying mechanism actually allows it. --- src/h.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/h.ts b/src/h.ts index 469dd0b..c334b29 100644 --- a/src/h.ts +++ b/src/h.ts @@ -1,6 +1,6 @@ import {vnode, VNode, VNodeData} from './vnode'; export type VNodes = Array; -export type VNodesSparse = Array; +export type VNodesSparse = VNode | Array; import * as is from './is'; function addNS(data: any, children: VNodes | undefined, sel: string | undefined): void {