Skip to content

Commit

Permalink
fix: onBecome(Un)Observed didn't trigger (#2076)
Browse files Browse the repository at this point in the history
  • Loading branch information
wayne-liberty authored and FredyC committed Aug 13, 2019
1 parent 9a40d66 commit 8ee9365
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/api/become-observed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export function onBecomeUnobserved(thing, arg2, arg3?): Lambda {

function interceptHook(hook: "onBecomeObserved" | "onBecomeUnobserved", thing, arg2, arg3) {
const atom: IObservable =
typeof arg2 === "string" ? getAtom(thing, arg2) : (getAtom(thing) as any)
const cb = typeof arg2 === "string" ? arg3 : arg2
typeof arg3 === "function" ? getAtom(thing, arg2) : (getAtom(thing) as any)
const cb = typeof arg3 === "function" ? arg3 : arg2
const orig = atom[hook]

if (typeof orig !== "function")
Expand Down
13 changes: 13 additions & 0 deletions test/base/become-observed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { autorun, onBecomeObserved, observable } from "../../src/mobx"

describe("become-observed", () => {
it("work on map with number as key", () => {
const oMap = observable.map()
const key = 1
oMap.set(key, observable.box("value"))
const cb = jest.fn()
onBecomeObserved(oMap, key, cb)
autorun(() => oMap.get(key))
expect(cb).toBeCalled()
})
})

0 comments on commit 8ee9365

Please sign in to comment.