git ssb

1+

Matt McKegg / mutant



Commit 60937d3f4651c570a60de8a1e7b59f63e3ebc276

computed: fix updating of inner values for non-live mode

since ef9e5ab9d31b22070e49efa9d5db1f9b8f20b572
Matt McKegg committed on 6/27/2017, 5:13:41 AM
Parent: 47af4cfff131b656d6f418cd79de17a67d34fd4e

Files changed

computed.jschanged
test/computed.jschanged
computed.jsView
@@ -84,11 +84,16 @@
8484 }
8585 if (this.inner) {
8686 this.releaseInner = this.inner(this.onInnerUpdate.bind(this, this.inner))
8787 }
88 +
8889 this.live = true
89- this.update()
9090
91 + if (!this.update() && this.inner) {
92 + // no change, but make sure that inner value is up to date
93 + this.onInnerUpdate(this.inner, resolve(this.inner))
94 + }
95 +
9196 if (this.opts && this.opts.onListen) {
9297 var release = this.opts.onListen()
9398 if (typeof release === 'function') {
9499 this.releases.push(release)
test/computed.jsView
@@ -44,4 +44,16 @@
4444
4545 t.deepEqual(resolve(final), 200)
4646 t.end()
4747 })
48 +
49 +test('computed inner update in non-live mode', function (t) {
50 + var innerValue = Value(1)
51 + var value = Value(innerValue)
52 + var obs = computed(value, x => x)
53 + t.deepEqual(obs(), 1)
54 + setImmediate(() => {
55 + innerValue.set(2)
56 + t.deepEqual(obs(), 2)
57 + t.end()
58 + })
59 +})

Built with git-ssb-web