diff options
author | Joris | 2025-03-17 14:08:59 +0100 |
---|---|---|
committer | Joris | 2025-03-17 14:08:59 +0100 |
commit | c6ac1ec310db17b517c5b978752c22de5b4de3f5 (patch) | |
tree | 154c69e7691b3fd5f56fbc9296a1a8139665f977 /src | |
parent | 1435f9e28aff7ab791c29f7d3017fa5baae2649b (diff) |
Update only if still available
Diffstat (limited to 'src')
-rw-r--r-- | src/rx.ts | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -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 { |