diff options
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 { |