Skip to content

How does @action actually work? #884

Answered by amondnet
thphuccoder asked this question in Q&A
Discussion options

You must be logged in to vote

@thphuc

I have used MobX for years. Today I read the document again, the action session: https://mobx.netlify.app/api/action

I think I am confused about how the action works to "batch" observables.

Changes to the observables are only notified at the end of the action
I think the documentation is misleading.

According to the docs, that behavior is intended.

mobxjs/mobx#3144
mobxjs/mobx#3144 (comment)

There is nothing like async transaction. Create a local temporal object/variable that is modified by the individual async tasks and write the result to actual observables at the end of async flow.

In essence, asynchronous processes don't need any special treatment in MobX, as all reaction…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by amondnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants