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-v6 #131
mobx-v6 #131
Conversation
updated version of mobx to v6.0.4 fixed mobx-angular test files to new syntax supplied example app with new mobx6 decorator-less syntax
[Read More](https://michel.codes/blogs/mobx6) | ||
|
||
- In order to use MobX 6 with decorators `makeObservable(this)` should be added to the constructor, and "useDefineForClassFields": true should be added to tsconfig.json. | ||
- Note that for decorator-less syntax, `makeAutoObservable` does not work with @Injectable stores |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe why it doesn't work with @Injectable and what to use instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still haven't figured out what exactly causes this issue. MobX alerts that makeAutoObservable cannot be used on classes that have super or are subclassed.
For some reason, it considers classes decorated with the @Injectable to be super/subclassed. Need to dig a little deeper to understand this.
For now the more explicit makeObservable, works fine in @Injectable stores.
In order to become compatible with modern ES standards, decorators are not used by default in MobX v6. It still supports decorators, but they are not recommended for greenfield projects and require some extra setup as opposed to previous versions. | ||
[Read More](https://michel.codes/blogs/mobx6) | ||
|
||
- In order to use MobX 6 with decorators `makeObservable(this)` should be added to the constructor, and "useDefineForClassFields": true should be added to tsconfig.json. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I think the link to the whole migration guide could be included here: https://mobx.js.org/migrating-from-4-or-5.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea
@@ -164,6 +164,17 @@ class Store { | |||
} | |||
``` | |||
|
|||
## MobX v6 | |||
|
|||
In order to become compatible with modern ES standards, decorators are not used by default in MobX v6. It still supports decorators, but they are not recommended for greenfield projects and require some extra setup as opposed to previous versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decorators do require extra setup for React/Vue projects, but in Angular decorators are enabled by default. But I agree about the general recommendation to avoid decorators 👍
added explanation of MobX 6 to README.md
updated version of mobx to v6.0.4
fixed mobx-angular test files to new syntax
supplied example app with new mobx6 decorator-less syntax