-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
@action decorators on fields do not convert the field value into action #3879
Comments
You still have to call There is a tool to help you with migration: And also eslint rule |
@urugator not according to the docs when using modern decorators. https://mobx.js.org/enabling-decorators.html#enabling-decorators |
I see. I am not completely up to date with these, just slapped the makeObservable in the stackblitz and seemed to work. There was a discussion about this, dunno what the resolution was: |
Thanks for the link, I fully agree with this comment #3638 (comment)
In the current state, it's just confusing. If I find the decision of not supporting Is it possible to just support the
As for the limitations and potential issues on reassigning the value on @action fields, as @Amareis also mentioned, it's the same as reassigning @action methods #3638 (comment) |
@Obi-Dann I've been out of the MobX code base for a bit, but from a JS stand point, field decorators cannot augment the value of the field. They're annotation only. It's not the same as re-assigning methods. So JS-wise the only way to achieve Now, with newer changes to the decorator spec ( It'd be up to @mweststrate (or anyone more current in MobX) to make this call. I know our original thought was to lean more in to the modern JS design and (going forward) limit I agree that the docs I wrote probably didn't state this as sharply as they could have. |
@Matchlighter If I read the spec correctly, field decorators can augment the value of the field Not sure it's always been the case, but it's definitely possible now and actually works In terms of the behavior, the logic converting a function into an action would run once during the initialization. The logic would not run if the value is reassigned. It's pretty much the same as using
Found an additional discrepancy when running the code above, calling In terms of the using the field vs |
Let me revisit this when I find a bigger chunk of time. Also in combination with #3882. I have a vague mental note that at the time of writing there was an issue in the transpiler with the addInitializers. |
@mweststrate I've got a PR with the fix for this issue #3883 |
Hi @mweststrate, any chance we can get this issue solved? I tested PR #3883 on the project I work and it works perfectly. I also created PR #3902 to handle one extra edge case |
Hi @mweststrate, just wanted to kindly remind you to review PR #3902 whenever you get a chance. Thanks! |
Do we have tests for inheritance with modern decorators? |
@urugator If there were tests for such for legacy decorators - yes. I pretty much just duplicated the whole decorators test file and ported it to use 2022.3 decorators. |
Hi @urugator please find updated doc in my PR |
@Matchlighter We do, but they are here: |
EDIT: this issue happens when using modern decorators
Intended outcome:
or
mobx
action
decorator should not implement a decorator forfield
if it's not supposed to workActual outcome:
this test above fails, the fn
x
is not an actionHow to reproduce the issue:
Link to stackblitz with replication https://stackblitz.com/edit/vitejs-vite-hdtz1l?file=src%2Fmobx.test.ts
Versions
mobx 6.12.3
Not sure why code in the 2022.3 decorator is marked as backwards/legacy and how it's supposed to work?
It looks like it should be returning
return _createAction
or do more stuff inaddInitializer
to actually wrap the declared fn into an action?mobx/packages/mobx/src/types/actionannotation.ts
Lines 77 to 82 in bc1a775
The text was updated successfully, but these errors were encountered: