Skip to content

Commit

Permalink
fix (#3596)
Browse files Browse the repository at this point in the history
  • Loading branch information
urugator authored Jan 7, 2023
1 parent 552c084 commit 42f8ac0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-pianos-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

fix #3595 onBecomeObserved is not called for ObservableSet
17 changes: 17 additions & 0 deletions packages/mobx/__tests__/v5/base/become-observed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,3 +509,20 @@ test("#2667", () => {
"onBecomeUnobservednew"
])
})

test("works with ObservableSet #3595", () => {
const onSetObserved = jest.fn()
const onSetUnobserved = jest.fn()

const set = observable.set()

const disposeOBO = onBecomeObserved(set, onSetObserved)
const disposeOBU = onBecomeUnobserved(set, onSetUnobserved)
const diposeAutorun = autorun(() => set.size)
diposeAutorun()
disposeOBO()
disposeOBU()

expect(onSetObserved).toBeCalledTimes(1)
expect(onSetUnobserved).toBeCalledTimes(1)
})
2 changes: 1 addition & 1 deletion packages/mobx/src/types/observableset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type ISetWillChange<T = any> =
export class ObservableSet<T = any> implements Set<T>, IInterceptable<ISetWillChange>, IListenable {
[$mobx] = ObservableSetMarker
private data_: Set<any> = new Set()
private atom_: IAtom
atom_: IAtom
changeListeners_
interceptors_
dehancer: any
Expand Down
2 changes: 1 addition & 1 deletion packages/mobx/src/types/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getAtom(thing: any, property?: PropertyKey): IDepTreeNode {
return (thing as any)[$mobx].atom_
}
if (isObservableSet(thing)) {
return (thing as any)[$mobx]
return thing.atom_
}
if (isObservableMap(thing)) {
if (property === undefined) {
Expand Down

0 comments on commit 42f8ac0

Please # to comment.