aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2025-03-17 14:08:59 +0100
committerJoris2025-03-17 14:08:59 +0100
commitc6ac1ec310db17b517c5b978752c22de5b4de3f5 (patch)
tree154c69e7691b3fd5f56fbc9296a1a8139665f977 /src
parent1435f9e28aff7ab791c29f7d3017fa5baae2649b (diff)
Update only if still available
Diffstat (limited to 'src')
-rw-r--r--src/rx.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/rx.ts b/src/rx.ts
index 42680c5..61a7e7f 100644
--- a/src/rx.ts
+++ b/src/rx.ts
@@ -261,14 +261,16 @@ class State {
}
update<A>(v: Var<A>, f: (value: A) => A) {
- const value = f(this.state[v.id].value)
- this.state[v.id].value = value
- this.state[v.id].subscribers.forEach(notify => {
- // Don’t notify if it has been removed from a precedent notifier
- if (this.state[v.id].subscribers.indexOf(notify) !== -1) {
- notify(value)
- }
- })
+ if (v.id in this.state) {
+ const value = f(this.state[v.id].value)
+ this.state[v.id].value = value
+ this.state[v.id].subscribers.forEach(notify => {
+ // Don’t notify if it has been removed from a precedent notifier
+ if (this.state[v.id].subscribers.indexOf(notify) !== -1) {
+ notify(value)
+ }
+ })
+ }
}
subscribe<A>(v: Var<A>, notify: (value: A) => void): Cancelable {