From c6ac1ec310db17b517c5b978752c22de5b4de3f5 Mon Sep 17 00:00:00 2001
From: Joris
Date: Mon, 17 Mar 2025 14:08:59 +0100
Subject: Update only if still available
---
src/rx.ts | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
(limited to 'src')
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(v: Var, 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(v: Var, notify: (value: A) => void): Cancelable {
--
cgit v1.2.3