Skip to content

Commit

Permalink
fix: onBecome(Un)Observed didn't trigger when using number as key of …
Browse files Browse the repository at this point in the history
…observable map.
  • Loading branch information
wayne.zhou authored and danielkcz committed Aug 12, 2019
1 parent cb07a4f commit a3ec6b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 5.13.1 / 4.13.1

* Don't use `global` and `self` keywords unless defined. Fixes [#2070](https://github.com/mobxjs/mobx/issues/2070).
* onBecome(Un)Observed didn't trigger when using number as key of observable map. Fixes [#2067](https://github.com/mobxjs/mobx/issues/2067).


# 5.13.0 / 4.13.0

Expand Down
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 listenersKey = `${hook}Listeners` as
| "onBecomeObservedListeners"
| "onBecomeUnobservedListeners"
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 a3ec6b1

Please sign in to comment.