From af06b6ac86d9eccaaebfaa3f66840149cda0b77f Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 31 Aug 2025 14:23:52 +0200 Subject: Use Rx 3.1.0 Adds support to get current value of Vars. --- frontend/ts/src/lib/rx.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/frontend/ts/src/lib/rx.ts b/frontend/ts/src/lib/rx.ts index 5edd3c1..b532842 100644 --- a/frontend/ts/src/lib/rx.ts +++ b/frontend/ts/src/lib/rx.ts @@ -1,4 +1,4 @@ -// Rx 3.0.0 +// Rx 3.1.0 // Html @@ -266,16 +266,22 @@ export function pure(value: A): Rx { return new Pure(value) } -class Var extends Rx { +export class Var extends Rx { readonly type: 'Var' readonly id: string readonly update: (f: (value: A) => A) => void + readonly now: () => A - constructor(id: string, update: (v: Var) => ((f: ((value: A) => A)) => void)) { + constructor( + id: string, + update: (v: Var) => ((f: ((value: A) => A)) => void), + now: (v: Var) => (() => A) + ) { super() this.id = id this.type = 'Var' this.update = update(this) + this.now = now(this) } } @@ -350,7 +356,11 @@ class State { } register(initValue: A) { - const v = new Var(this.varCounter.toString(), v => (f => this.update(v, f))) + const v = new Var( + this.varCounter.toString(), + v => (f => this.update(v, f)), + v => () => this.get(v) + ) this.varCounter += BigInt(1) this.state[v.id] = { value: initValue, -- cgit v1.2.3