aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris Guyonvarch2025-08-31 14:23:52 +0200
committerJoris Guyonvarch2025-08-31 14:24:03 +0200
commitaf06b6ac86d9eccaaebfaa3f66840149cda0b77f (patch)
tree39a3db460d9a802bb614ea69c86376ace2cfca7a
parent8255e9432874b5374c3b365560a6adb5d80ef844 (diff)
Use Rx 3.1.0
Adds support to get current value of Vars.
-rw-r--r--frontend/ts/src/lib/rx.ts18
1 files 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<A>(value: A): Rx<A> {
return new Pure(value)
}
-class Var<A> extends Rx<A> {
+export class Var<A> extends Rx<A> {
readonly type: 'Var'
readonly id: string
readonly update: (f: (value: A) => A) => void
+ readonly now: () => A
- constructor(id: string, update: (v: Var<A>) => ((f: ((value: A) => A)) => void)) {
+ constructor(
+ id: string,
+ update: (v: Var<A>) => ((f: ((value: A) => A)) => void),
+ now: (v: Var<A>) => (() => A)
+ ) {
super()
this.id = id
this.type = 'Var'
this.update = update(this)
+ this.now = now(this)
}
}
@@ -350,7 +356,11 @@ class State {
}
register<A>(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,