From 8b84a732436fc6c84ce4b912b548648eb91c9312 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 19 Feb 2023 13:16:53 +0100 Subject: Rename withVar to withState --- src/rx.ts | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/rx.ts') diff --git a/src/rx.ts b/src/rx.ts index 5028ec1..ea4f6a4 100644 --- a/src/rx.ts +++ b/src/rx.ts @@ -1,14 +1,16 @@ +// Rx 1.0.1 + // Html export type Html - = false - | undefined - | string - | number - | Tag - | WithVar + = false + | undefined + | string + | number + | Tag + | WithState | Array - | Rx + | Rx interface Tag { type: 'Tag' @@ -19,8 +21,8 @@ interface Tag { onunmount?: (element: Element) => void } -interface WithVar { - type: 'WithVar' +interface WithState { + type: 'WithState' init: A getChildren: (v: Var) => Html } @@ -40,8 +42,8 @@ type AttributeValue function isHtml(x: any): x is Html { return (typeof x === 'string' || typeof x === 'number' - || isTag(x) - || isWithVar(x) + || isTag(x) + || isWithState(x) || isRx(x) || Array.isArray(x)) } @@ -88,9 +90,9 @@ export function h( } } -export function withVar(init: A, getChildren: (v: Var) => Html): WithVar { +export function withState(init: A, getChildren: (v: Var) => Html): WithState { return { - type: 'WithVar', + type: 'WithState', init, getChildren } @@ -322,7 +324,7 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No remove: () => element.removeChild(childElement), lastAdded: childElement, } - } else if (isWithVar(child)) { + } else if (isWithState(child)) { const { init, getChildren } = child const v = state.register(init) const children = getChildren(v) @@ -374,8 +376,8 @@ function isTag(x: any): x is Tag { return x !== undefined && x.type === "Tag" } -function isWithVar(x: any): x is WithVar { - return x !== undefined && x.type === "WithVar" +function isWithState(x: any): x is WithState { + return x !== undefined && x.type === "WithState" } function appendNode(base: Element, node: Node, lastAdded?: Node) { -- cgit v1.2.3