git ssb

1+

Matt McKegg / mutant



Commit 408284391d679877e10234efd7de780b0d75d121

computed: fix detecting changes when nested

Matt McKegg committed on 9/14/2016, 3:21:19 PM
Parent: 16c758c23c35f83cc951a854762995cc02878257

Files changed

computed.jschanged
computed.jsView
@@ -26,9 +26,10 @@
2626 observables = [observables]
2727 }
2828 this.values = []
2929 this.releases = []
30- this.computedValue = []
30+ this.computedValue = null
31+ this.outputValue = null
3132 this.inner = null
3233 this.updating = false
3334 this.live = false
3435 this.lazy = false
@@ -128,17 +129,19 @@
128129 this.releaseInner()
129130 this.inner = this.releaseInner = null
130131 }
131132
133+ this.computedValue = newComputedValue
134+
132135 if (isObservable(newComputedValue)) {
133136 // handle returning observable from computed
134- this.computedValue = newComputedValue()
137+ this.outputValue = newComputedValue()
135138 this.inner = newComputedValue
136139 if (this.live) {
137140 this.releaseInner = this.inner(this.onInnerUpdate.bind(this, this.inner))
138141 }
139142 } else {
140- this.computedValue = newComputedValue
143+ this.outputValue = this.computedValue
141144 }
142145 return true
143146 }
144147 }
@@ -155,10 +158,10 @@
155158 }
156159 },
157160 onInnerUpdate: function (obs, value) {
158161 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
161164 this.broadcast()
162165 }
163166 }
164167 },
@@ -172,18 +175,18 @@
172175 if (!this.live || this.lazy || this.updating) {
173176 this.lazy = false
174177 this.update()
175178 if (this.inner) {
176- this.computedValue = resolve(this.inner)
179+ this.outputValue = resolve(this.inner)
177180 }
178181 }
179- return this.computedValue
182+ return this.outputValue
180183 },
181184 broadcast: function () {
182185 // cache listeners in case modified during broadcast
183186 var listeners = this.listeners.slice(0)
184187 for (var i = 0, len = listeners.length; i < len; i++) {
185- listeners[i](this.computedValue)
188+ listeners[i](this.outputValue)
186189 }
187190 }
188191 }
189192

Built with git-ssb-web