-
Since
There is another undocumented way. Custom scheduler: import { configure } from 'mobx';
export const configureBatching = () => {
setTimeout(() => {
configure({
enforceActions: 'never',
reactionScheduler: (f) => {
setTimeout(f, 1);
},
});
}, 1);
}; It configures MobX to auto batch all sync mutations without using action/runInAction. It will result in 2 rerenders instead of 4 in such code: class Store {
...
async someMethod() {
this.foo = ...
this.bar = ...
await someAsyncOperation();
this.foo = ...
this.bar = ...
}
} So it is very similar to an action. What do you think about this approach? Are there any drawbacks or pitfalls? I've been using this approach for a few weeks and haven't found any issues. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
We have considered auto-commiting actions with |
Beta Was this translation helpful? Give feedback.
We have considered auto-commiting actions with
setImmediate
/Promise.resolve().then()
/etc , but concluded it doesn't play well with mobx's completely synchronous nature.Any kind of delay would make the whole thing harder to reason about and could introduce race conditions.