Commit 408284391d679877e10234efd7de780b0d75d121
computed: fix detecting changes when nested
Matt McKegg committed on 9/14/2016, 3:21:19 PMParent: 16c758c23c35f83cc951a854762995cc02878257
Files changed
computed.js | changed |
computed.js | ||
---|---|---|
@@ -26,9 +26,10 @@ | ||
26 | 26 | observables = [observables] |
27 | 27 | } |
28 | 28 | this.values = [] |
29 | 29 | this.releases = [] |
30 | - this.computedValue = [] | |
30 | + this.computedValue = null | |
31 | + this.outputValue = null | |
31 | 32 | this.inner = null |
32 | 33 | this.updating = false |
33 | 34 | this.live = false |
34 | 35 | this.lazy = false |
@@ -128,17 +129,19 @@ | ||
128 | 129 | this.releaseInner() |
129 | 130 | this.inner = this.releaseInner = null |
130 | 131 | } |
131 | 132 | |
133 | + this.computedValue = newComputedValue | |
134 | + | |
132 | 135 | if (isObservable(newComputedValue)) { |
133 | 136 | // handle returning observable from computed |
134 | - this.computedValue = newComputedValue() | |
137 | + this.outputValue = newComputedValue() | |
135 | 138 | this.inner = newComputedValue |
136 | 139 | if (this.live) { |
137 | 140 | this.releaseInner = this.inner(this.onInnerUpdate.bind(this, this.inner)) |
138 | 141 | } |
139 | 142 | } else { |
140 | - this.computedValue = newComputedValue | |
143 | + this.outputValue = this.computedValue | |
141 | 144 | } |
142 | 145 | return true |
143 | 146 | } |
144 | 147 | } |
@@ -155,10 +158,10 @@ | ||
155 | 158 | } |
156 | 159 | }, |
157 | 160 | onInnerUpdate: function (obs, value) { |
158 | 161 | if (obs === this.inner) { |
159 | - if (!isSame(value, this.computedValue, this.comparer)) { | |
160 | - this.computedValue = value | |
162 | + if (!isSame(value, this.outputValue, this.comparer)) { | |
163 | + this.outputValue = value | |
161 | 164 | this.broadcast() |
162 | 165 | } |
163 | 166 | } |
164 | 167 | }, |
@@ -172,18 +175,18 @@ | ||
172 | 175 | if (!this.live || this.lazy || this.updating) { |
173 | 176 | this.lazy = false |
174 | 177 | this.update() |
175 | 178 | if (this.inner) { |
176 | - this.computedValue = resolve(this.inner) | |
179 | + this.outputValue = resolve(this.inner) | |
177 | 180 | } |
178 | 181 | } |
179 | - return this.computedValue | |
182 | + return this.outputValue | |
180 | 183 | }, |
181 | 184 | broadcast: function () { |
182 | 185 | // cache listeners in case modified during broadcast |
183 | 186 | var listeners = this.listeners.slice(0) |
184 | 187 | for (var i = 0, len = listeners.length; i < len; i++) { |
185 | - listeners[i](this.computedValue) | |
188 | + listeners[i](this.outputValue) | |
186 | 189 | } |
187 | 190 | } |
188 | 191 | } |
189 | 192 |
Built with git-ssb-web