aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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 {