diff options
| -rw-r--r-- | src/rx.ts | 49 | 
1 files changed, 49 insertions, 0 deletions
@@ -15,6 +15,7 @@ export type Html    | WithState4<any, any, any, any>    | WithState5<any, any, any, any, any>    | WithState6<any, any, any, any, any, any> +  | WithState7<any, any, any, any, any, any, any>    | Array<Html>    | Rx<Html> @@ -63,6 +64,12 @@ interface WithState6<A, B, C, D, E, F> {    getChildren: (v1: Var<A>, v2: Var<B>, v3: Var<C>, v4: Var<D>, v5: Var<E>, v6: Var<F>) => Html  } +interface WithState7<A, B, C, D, E, F, G> { +  type: 'WithState7' +  init: [A, B, C, D, E, F, G] +  getChildren: (v1: Var<A>, v2: Var<B>, v3: Var<C>, v4: Var<D>, v5: Var<E>, v6: Var<F>, v7: Var<G>) => Html +} +  export interface Attributes {    [key: string]: Rx<AttributeValue> | 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<A, B, C, D, E, F>(init: [A, B, C, D, E, F], getChildr    }  } +export function withState7<A, B, C, D, E, F, G>(init: [A, B, C, D, E, F, G], getChildren: (v1: Var<A>, v2: Var<B>, v3: Var<C>, v4: Var<D>, v5: Var<E>, v6: Var<F>, v7: Var<G>) => Html): WithState7<A, B, C, D, E, F, G> { +  return { +    type: 'WithState7', +    init, +    getChildren +  } +} +  // Rx  export type RxAble<A> = Rx<A> | 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<A, B, C, D, E, F>(x: any): x is WithState6<A, B, C, D, E,    return x != null && x.type === 'WithState6'  } +function isWithState7<A, B, C, D, E, F, G>(x: any): x is WithState7<A, B, C, D, E, F, G> { +  return x != null && x.type === 'WithState7' +} +  function appendNode(base: Element, node: Node, lastAdded?: Node) {    if (lastAdded !== undefined) {      base.insertBefore(node, lastAdded.nextSibling)  | 
