Commit 60937d3f4651c570a60de8a1e7b59f63e3ebc276
computed: fix updating of inner values for non-live mode
since ef9e5ab9d31b22070e49efa9d5db1f9b8f20b572Matt McKegg committed on 6/27/2017, 5:13:41 AM
Parent: 47af4cfff131b656d6f418cd79de17a67d34fd4e
Files changed
computed.js | changed |
test/computed.js | changed |
computed.js | ||
---|---|---|
@@ -84,11 +84,16 @@ | ||
84 | 84 … | } |
85 | 85 … | if (this.inner) { |
86 | 86 … | this.releaseInner = this.inner(this.onInnerUpdate.bind(this, this.inner)) |
87 | 87 … | } |
88 … | + | |
88 | 89 … | this.live = true |
89 | - this.update() | |
90 | 90 … | |
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 … | + | |
91 | 96 … | if (this.opts && this.opts.onListen) { |
92 | 97 … | var release = this.opts.onListen() |
93 | 98 … | if (typeof release === 'function') { |
94 | 99 … | this.releases.push(release) |
test/computed.js | ||
---|---|---|
@@ -44,4 +44,16 @@ | ||
44 | 44 … | |
45 | 45 … | t.deepEqual(resolve(final), 200) |
46 | 46 … | t.end() |
47 | 47 … | }) |
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