Skip to content

Commit 89959b0

Browse files
author
Chris Doble
committed
Don't pass undefined to custom equality checks on becoming observed again
1 parent ea6c823 commit 89959b0

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/core/computedvalue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
110110

111111
onBecomeUnobserved() {
112112
clearObserving(this)
113-
this.value = undefined
113+
this.value = new CaughtException(null)
114114
}
115115

116116
/**

test/errorhandling.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ test("peeking inside autorun doesn't bork (global) state", t => {
682682
t.equal(b.diffValue, 0)
683683
t.equal(b.lowestObserverState, 0)
684684
t.equal(b.unboundDepsCount, 1)
685-
t.equal(b.value, undefined)
685+
t.notEqual(b.value, 3)
686686
t.equal(b.isComputing, false)
687687

688688
t.equal(c.dependenciesState, -1)

test/observables.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ test("computed equals function only invoked when necessary", t => {
18531853
)
18541854

18551855
const values = []
1856-
const disposeAutorun = mobx.autorun(() => values.push(combinedToLowerCase.get()))
1856+
let disposeAutorun = mobx.autorun(() => values.push(combinedToLowerCase.get()))
18571857

18581858
// No comparison should be made on the first value
18591859
t.deepEqual(comparisons, [])
@@ -1879,7 +1879,12 @@ test("computed equals function only invoked when necessary", t => {
18791879
right.set("F")
18801880
t.deepEqual(comparisons, [{ from: "ab", to: "cb" }, { from: "de", to: "df" }])
18811881

1882-
t.deepEqual(values, ["ab", "cb", "de", "df"])
1882+
// Becoming unobserved, then observed won't cause a comparison
1883+
disposeAutorun()
1884+
disposeAutorun = mobx.autorun(() => values.push(combinedToLowerCase.get()));
1885+
t.deepEqual(comparisons, [{ from: "ab", to: "cb" }, { from: "de", to: "df" }])
1886+
1887+
t.deepEqual(values, ["ab", "cb", "de", "df", "df"])
18831888

18841889
disposeAutorun()
18851890

0 commit comments

Comments
 (0)