Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepObserve doesn't respect mobx's observer decorator variants #312

Open
TomasChmelik opened this issue Jan 6, 2023 · 0 comments
Open

Comments

@TomasChmelik
Copy link

TomasChmelik commented Jan 6, 2023

deepObserve observes everything deeply even if property is decorated by @observable.ref or @observable.shallow.

import {observable, makeObserable} from 'mobx'
import {deepObserve} from 'mobx-utils'

class Entity {
    @observable.ref byRef?: Entity
    @observable property = 0

    constructor() {
        makeObserable(this)
    }
}

const entity = new Entity()
const dispose = deepObserve(entity, () => console.log('Change'))

entity.byRef = new Entity() // Outputs "Change" to console (expected)
entity.byRef.property++ // Outputs "Change" to console (unexpected)

dispose()
import {observable} from 'mobx'
import {deepObserve} from 'mobx-utils'

class Entity {
    @observable.shallow shallow: Entity[] = []
    @observable property = 0

    constructor() {
        makeObserable(this)
    }
}

const entity = new Entity()
const dispose = deepObserve(entity, () => console.log('Change'))

entity.shallow.push(new Entity()) // Outputs "Change" to console (expected)
entity.shallow[0].property++ // Outputs "Change" to console (unexpected)

dispose()

MobX version: 6.3.5
MobX-utils version: 6.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant