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-v6 #131

Merged
merged 1 commit into from Dec 18, 2020
Merged

mobx-v6 #131

merged 1 commit into from Dec 18, 2020

Conversation

OmerGronich
Copy link
Contributor

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

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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kubk

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.
Copy link
Contributor

@kubk kubk Dec 18, 2020

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

Copy link
Contributor Author

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.
Copy link
Contributor

@kubk kubk Dec 18, 2020

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 👍

@adamkleingit adamkleingit merged commit 88eac17 into mobxjs:master Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants