aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rx.ts14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/rx.ts b/src/rx.ts
index 958abcb..df69d31 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -270,12 +270,18 @@ 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,