-
Hi We're developing an Editable Canvas feature in our app using The Composable Architecture (TCA), where users can interact with the canvas in various ways (e.g., adding images, text, stickers, or deleting elements). Each user action triggers a reducer; while some actions are straightforward and executed in a single step, others depend on side effects such as fetching UI data from a server or retrieving assets and fonts. We aim to implement an Undo/Redo mechanism to enhance user experience. Our initial strategy involves saving a snapshot of the canvas state after every user action, allowing us to restore the state for Undo/Redo functionality. To avoid relying on developers to manually call a save action after each state change—which could lead to oversight and data loss in our Undo/Redo system—we've designed a top-level reducer that automatically creates a state snapshot after every action is processed. However, we've encountered a challenge in determining when a user-initiated state change, especially those involving side effects, is fully completed. For instance, adjusting an element's position on the canvas is straightforward: we execute an action that updates the state, and then we can immediately capture a snapshot. But when selecting a new layout, which involves fetching layout data from a server as a side effect, our system inadvertently captures two snapshots: one before the side effect is resolved and another after, unnecessarily duplicating state changes related to a single user action. In TCA, when writing tests, there's a mechanism to ensure that all side effects or actions related to an initial user action are accounted for. Is there a similar approach or another strategy we can adopt to consolidate related state changes into a single snapshot for our Undo/Redo feature? Thank you for your assistance, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Anyone? Impossible is also an helpful answer. |
Beta Was this translation helpful? Give feedback.
-
Thanks again for your time @mbrandonw
In that case we want to snapshot the state after the final data is updated. and we will be happy to avoid manually send a snapshot action where needed as this is fragile in our 20 iOS developers team. They can forget adding it, or worse, add it at the end of an action which is final in one flow but not for a different flow. Thanks for you patient and help |
Beta Was this translation helpful? Give feedback.
Hi @shannoga, I'm sorry but I do not think there is any magical solution to this. The logic guiding when a snapshot should and should not be made appears to be quite subtle and nuanced, and so it seems like no matter what you need to do work to determine when it is appropriate to snapshot.