PistonDevelopers / editor

Editor interface
MIT License
4 stars 1 forks source link

Transactional state #13

Open bvssvni opened 9 years ago

bvssvni commented 9 years ago

Because of https://github.com/PistonDevelopers/editor/issues/11, actions have side effects in the editor state that must be reversible if there is an error.

For example, when attempting to delete a point that referenced from an edge object, there are several possible deletion strategies:

  1. Cascade the deletion such that any edge referencing the point also gets deleted
  2. Cancel the deletion
  3. Garbage collect the point which leaves an invisible copy of it in memory

Therefore, the editor might choose to interrupt an action and roll back to previous state.

bvssvni commented 9 years ago

One idea is to use an undo/redo history that allows partial logging through sub actions. Each sub action is reversible. When an error occurs, the action returns Err(()) and the code that calls the action rolls back the sub actions from the incomplete undo action.