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

[mobx ^2.5.0] mobx.observable property inside of mobx.extendObservable doesn't return an ObservableValue instance #558

Closed
pnpetrov opened this issue Sep 15, 2016 · 3 comments
Labels

Comments

@pnpetrov
Copy link

pnpetrov commented Sep 15, 2016

Hello,

I have a store with a state object inside of it. I want to extend the state with some observable primitive values.

this.state = {};
mobx.extendObservable(this.state, {
  title: mobx.observable('hello')
});

With mobx v2.4.4 this.state.title is of type ObservableValue so I can attach some observers. But with mobx v2.5.0 this.state.title is not an observable value anymore.

mobx.observable(<scalar_value>) still returns an ObservableValue instance but it behaves differently if I use it inside of mobx.extendObservable.

Here is an example with mobx v.2.4.4: https://jsfiddle.net/ppetrov/emrLLhk7/

EDIT: mobx v2.5.0 example: https://jsfiddle.net/ppetrov/4wocz8y4/

@andykog
Copy link
Member

andykog commented Sep 17, 2016

@nikolovp, thanks for reporting. As a quick workaround you can use:

mobx.extendObservable(this.state, {
  title: mobx.asReference(mobx.observable('hello'))
});

Or, obviously, that could be rewritten like this: https://jsfiddle.net/Sl1v3r/rg0oqkod/

@mweststrate, converting ObservableValue to a plain value is not the desired behaviour, right?

@mweststrate
Copy link
Member

Ah this is a bug indeed I think, introduced here (the idea was that this is consistent with computed, but that is actually another use case, and getters are now the idiomatic way). I'll revert the behavior.

@mweststrate
Copy link
Member

Fix will be part of 2.5.2

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

No branches or pull requests

3 participants