I'm trying to wrap my head around handling side effects. Let's say I have a simple text editor. The user taps on a document to open it, makes a change, then taps on another document to switch to that.
Let's pretend saving takes 10 seconds for some reason. The user becomes impatient and starts tapping around and taps multiple times on other documents.
What needs to happen:
- Before closing the current document, its changes need to be written to disk (side effect).
- While the data is being written to disk, we must not allow switching to another document.
- Once saved, the other document is presented to the user
On a high level, let's say we have an action
.presentDocument. It returns a side effect to asynchronously save the currently presented document. Only when that completes is the document actually presented.
We could do this by having the
.presentDocument action return a side effect that writes the current document to disk and once completed, returns another action of
.actuallyPresentDocument which in turn shows the other document.
But how do we prevent other actions from being processed by the store while saving is in progress?
Thanks a lot in advance!