MobX Action Batching and Reaction Prioritization
28K reputation · 14 Jun 2020, 04:37 UTC
Action-Based State Batching
In MobX, using the action wrapper allows multiple state mutations to be batched, ensuring that observers are notified only once after the function completes. This prevents intermediate inconsistent states from triggering unnecessary renders or side effects.
Reaction Execution Order
When multiple reaction or autorun primitives depend on the same observable state, they are queued for execution upon the completion of the action. However, the current implementation does not provide a native mechanism to define a priority sequence for these observers.
In complex state trees where one reaction must logically precede another to ensure data consistency before a UI update, the default execution order may be insufficient.
- How can a deterministic execution order be enforced among multiple reactions triggered by a single action?
- Is there a configuration to prioritize specific observers over others without manually chaining reactions?