From e1aaa513a444a32c56a9591dd92beb24e66bcf42 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 18 Feb 2023 14:30:45 +0100 Subject: Integrate update function with Var But still don’t expose `Var`, so that it would be still passed as a Rx. --- src/rx.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/rx.ts') diff --git a/src/rx.ts b/src/rx.ts index 3f3b8d9..5028ec1 100644 --- a/src/rx.ts +++ b/src/rx.ts @@ -1,5 +1,3 @@ -// [1.1.0] 2023-02-13 - // Html export type Html @@ -24,7 +22,7 @@ interface Tag { interface WithVar { type: 'WithVar' init: A - getChildren: (v: Var, update: (f: (value: A) => A) => void) => Html + getChildren: (v: Var) => Html } interface Attributes { @@ -90,7 +88,7 @@ export function h( } } -export function withVar(init: A, getChildren: (v: Var, update: (f: (value: A) => A) => void) => Html): WithVar { +export function withVar(init: A, getChildren: (v: Var) => Html): WithVar { return { type: 'WithVar', init, @@ -115,11 +113,13 @@ export class Rx { class Var extends Rx { readonly type: 'Var' readonly id: string + readonly update: (f: (value: A) => A) => void - constructor(id: string) { + constructor(id: string, update: (v: Var) => ((f: ((value: A) => A)) => void)) { super() this.id = id this.type = 'Var' + this.update = update(this) } } @@ -172,7 +172,7 @@ class State { } register(initValue: A) { - const v = new Var(this.varCounter.toString()) + const v = new Var(this.varCounter.toString(), v => (f => this.update(v, f))) this.varCounter += BigInt(1) this.state[v.id] = { value: initValue, @@ -325,7 +325,7 @@ function appendChild(state: State, element: Element, child: Html, lastAdded?: No } else if (isWithVar(child)) { const { init, getChildren } = child const v = state.register(init) - const children = getChildren(v, f => state.update(v, f)) + const children = getChildren(v) const appendRes = appendChild(state, element, children) return { cancel: () => { -- cgit v1.2.3