Separate document and history stores
I think it would be nice if the current DocumentStore
would be split in:
-
DocumentStore
, containing just the open document. -
HistoryStore
, containing undo and redo stacks of documents.
Let's ignore document view (focus etc) here.
I gave it a short try, but didn't yet come to a satisfactory setup. The main challenge seems to be to remove the need for bidirectional dependencies between the two stores.
Sketch setup
HistoryStore
knows about DocumentStore
, but not the other way around. Both listen for document change actions and HistoryStore
waits for DocumentStore
. It then stores a snapshot of the DocumentStore
on its undo stack.
The HistoryStore
exposes an undo object which contains a label and the complete state snapshot to revert to. The component can get this object and send it with an UNDO
action so that it can arrive at the DocumentStore
. To remove some undo/redo knowledge from the DocumentStore
it could listen to SET_DOCUMENT
actions or similar instead of UNDO
, which could be spawned with some logic in the action creator.
I guess this would work.