diff options
Diffstat (limited to 'src/rx.ts')
-rw-r--r-- | src/rx.ts | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -1,5 +1,3 @@ -// [1.1.0] 2023-02-13 - // Html export type Html @@ -24,7 +22,7 @@ interface Tag { interface WithVar<A> { type: 'WithVar' init: A - getChildren: (v: Var<A>, update: (f: (value: A) => A) => void) => Html + getChildren: (v: Var<A>) => Html } interface Attributes { @@ -90,7 +88,7 @@ export function h( } } -export function withVar<A>(init: A, getChildren: (v: Var<A>, update: (f: (value: A) => A) => void) => Html): WithVar<A> { +export function withVar<A>(init: A, getChildren: (v: Var<A>) => Html): WithVar<A> { return { type: 'WithVar', init, @@ -115,11 +113,13 @@ export class Rx<A> { class Var<A> extends Rx<A> { readonly type: 'Var' readonly id: string + readonly update: (f: (value: A) => A) => void - constructor(id: string) { + constructor(id: string, update: (v: Var<A>) => ((f: ((value: A) => A)) => void)) { super() this.id = id this.type = 'Var' + this.update = update(this) } } @@ -172,7 +172,7 @@ class State { } register<A>(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: () => { |