I have:
specifically i'm interested in whether actions (async ones if that makes any difference) are atomic.
meaning - should i expect a single onSnapshot callback after i execute such an action?
couldn't find any specifics about it in the documentation.
sync actions are atomic
async actions are partially atomic (atomic between yields), e.g. see https://codesandbox.io/s/8l1n2l8qxj
so if you have
someFlow: flow(function*() {
self.title = "title part 1";
yield new Promise(r => setTimeout(r, 1000));
self.title += " and part 2";
})
it will generate two snapshots, one with title "title part 1" and then another with "title part 1 and part 2"
this is basically because the code above is roughly equivalent to:
someFlow: async () => {
runInAction(() => {
self.title = "title part 1";
});
await new Promise(r => setTimeout(r, 1000));
runInAction(() => {
self.title += " and part 2";
});
})
that being said there is an atomic middleware in mst-middlewares to rollback any changes if an async action throws
async and sync actions sorry
Most helpful comment
sync actions are atomic
async actions are partially atomic (atomic between yields), e.g. see https://codesandbox.io/s/8l1n2l8qxj
so if you have
it will generate two snapshots, one with title "title part 1" and then another with "title part 1 and part 2"
this is basically because the code above is roughly equivalent to: