Skip to content

Commit

Permalink
Don't pass undefined to custom equality checks on becoming observed a…
Browse files Browse the repository at this point in the history
…gain
  • Loading branch information
Chris Doble committed Oct 19, 2017
1 parent ea6c823 commit 89959b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/computedvalue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva

onBecomeUnobserved() {
clearObserving(this)
this.value = undefined
this.value = new CaughtException(null)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/errorhandling.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ test("peeking inside autorun doesn't bork (global) state", t => {
t.equal(b.diffValue, 0)
t.equal(b.lowestObserverState, 0)
t.equal(b.unboundDepsCount, 1)
t.equal(b.value, undefined)
t.notEqual(b.value, 3)
t.equal(b.isComputing, false)

t.equal(c.dependenciesState, -1)
Expand Down
9 changes: 7 additions & 2 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1853,7 +1853,7 @@ test("computed equals function only invoked when necessary", t => {
)

const values = []
const disposeAutorun = mobx.autorun(() => values.push(combinedToLowerCase.get()))
let disposeAutorun = mobx.autorun(() => values.push(combinedToLowerCase.get()))

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

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

t.deepEqual(values, ["ab", "cb", "de", "df", "df"])

disposeAutorun()

Expand Down

0 comments on commit 89959b0

Please sign in to comment.