mobx-utils icon indicating copy to clipboard operation
mobx-utils copied to clipboard

Deepobserve does not observe changes in set

Open hkvoch opened this issue 6 years ago • 1 comments

I'm trying to use deepObserve() with an object that has an ObservableSet field but the changes in this field are not reported.

class Foo {
  @observable barSet = new Set()
}

const foo = new Foo
deepObserve(foo, () => {
  console.log('foo changed')
})
foo.barSet.add('bar') // "foo changed" is not logged to the console

Is this something that is supported? I looked into the deepObserve code and found that it uses this function:

function isRecursivelyObservable(thing: any) {
    return isObservableObject(thing) || isObservableArray(thing) || isObservableMap(thing)
}

to determine whether an object can be observed but the isObservableSet check is missing.

hkvoch avatar Nov 29 '19 15:11 hkvoch

Looks like this was build before observable sets were introduced indeed!

Feel free to submit a PR with test and fix.

We might need to double check if the peerDep on MobX needs to be bumped for this (or null check the presence of isObservableSet).

On Fri, Nov 29, 2019 at 3:53 PM Jan Kvoch [email protected] wrote:

I'm trying to use deepObserve() with an object that has an ObservableSet field but the changes in this field are not reported.

class Foo { @observable barSet = new Set() } const foo = new FoodeepObserve(foo, () => { console.log('foo changed') })foo.barSet.add('bar') // "foo changed" is not logged to the console

Is this something that is supported? I looked into the deepObserve code and found that it uses this function:

function isRecursivelyObservable(thing: any) { return isObservableObject(thing) || isObservableArray(thing) || isObservableMap(thing) }

to determine whether an object can be observed but the isObservableSet check is missing.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mobxjs/mobx-utils/issues/229?email_source=notifications&email_token=AAN4NBCHOXHRNF7SXXOO2XLQWE3JFA5CNFSM4JTBFVGKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4H45NCPA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAN4NBC4FCBQQ2TWVJAPQYLQWE3JFANCNFSM4JTBFVGA .

mweststrate avatar Nov 29 '19 16:11 mweststrate