From 69a51f9acd4cab983826e6707be16fad4f76743b Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 12 Apr 2025 12:39:30 +0200 Subject: Add withState7 --- src/rx.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/rx.ts') diff --git a/src/rx.ts b/src/rx.ts index 2ff8889..82e3535 100644 --- a/src/rx.ts +++ b/src/rx.ts @@ -15,6 +15,7 @@ export type Html | WithState4 | WithState5 | WithState6 + | WithState7 | Array | Rx @@ -63,6 +64,12 @@ interface WithState6 { getChildren: (v1: Var, v2: Var, v3: Var, v4: Var, v5: Var, v6: Var) => Html } +interface WithState7 { + type: 'WithState7' + init: [A, B, C, D, E, F, G] + getChildren: (v1: Var, v2: Var, v3: Var, v4: Var, v5: Var, v6: Var, v7: Var) => Html +} + export interface Attributes { [key: string]: Rx | AttributeValue } @@ -84,6 +91,9 @@ function isHtml(x: any): x is Html { || isWithState2(x) || isWithState3(x) || isWithState4(x) + || isWithState5(x) + || isWithState6(x) + || isWithState7(x) || isRx(x) || Array.isArray(x)) } @@ -178,6 +188,14 @@ export function withState6(init: [A, B, C, D, E, F], getChildr } } +export function withState7(init: [A, B, C, D, E, F, G], getChildren: (v1: Var, v2: Var, v3: Var, v4: Var, v5: Var, v6: Var, v7: Var) => Html): WithState7 { + return { + type: 'WithState7', + init, + getChildren + } +} + // Rx export type RxAble = Rx | A @@ -472,6 +490,7 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No } else if (isTag(child)) { const { tagName, attributes, children, onmount, onunmount } = child + // TODO: export svg variant of h function const s = isSvg(tagName) const childElement = s @@ -624,6 +643,32 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No remove: () => appendRes.remove(), lastAdded: appendRes.lastAdded } + } else if (isWithState7(child)) { + const { init, getChildren } = child + const [ init1, init2, init3, init4, init5, init6, init7 ] = init + const v1 = state.register(init1) + const v2 = state.register(init2) + const v3 = state.register(init3) + const v4 = state.register(init4) + const v5 = state.register(init5) + const v6 = state.register(init6) + const v7 = state.register(init7) + const children = getChildren(v1, v2, v3, v4, v5, v6, v7) + const appendRes = appendChild(state, element, children) + return { + cancel: () => { + appendRes.cancel() + state.unregister(v1) + state.unregister(v2) + state.unregister(v3) + state.unregister(v4) + state.unregister(v5) + state.unregister(v6) + state.unregister(v7) + }, + remove: () => appendRes.remove(), + lastAdded: appendRes.lastAdded + } } else if (isRx(child)) { const rxBase = document.createTextNode('') appendNode(element, rxBase, lastAdded) @@ -692,6 +737,10 @@ function isWithState6(x: any): x is WithState6(x: any): x is WithState7 { + return x != null && x.type === 'WithState7' +} + function appendNode(base: Element, node: Node, lastAdded?: Node) { if (lastAdded !== undefined) { base.insertBefore(node, lastAdded.nextSibling) -- cgit v1.2.3