Crates.io | serdo |
lib.rs | serdo |
version | 0.1.5 |
source | src |
created_at | 2022-10-22 23:48:34.949576 |
updated_at | 2024-10-11 00:52:48.395905 |
description | Serializable do/undo library. |
homepage | https://github.com/ruimo/serdo |
repository | https://github.com/ruimo/serdo |
max_upload_size | |
id | 694969 |
size | 113,862 |
Serializable do/undo library.
Fig. 1 illustrates the architecture. The application calls do() with undo information.
Fig. 1 Abstract
Serdo stores changes against the model. This unit of change is called 'Command'. Let's think about a tiny calculator that can add numbers.
flowchart LR;
State0["State0 (=0)"]-- "Command0 (add 2)" -->State1["State1 (=2)"];
State1-- "Command1 (add 3)" -->State2["State2 (=5)"];
State2-- "Command2 (add 4)" -->State3["State3 (=9)"];
Latest["Latest value = 9"]-..->State3;
Fig. 1.1.1 Command
Fig. 1.1.1 illustrates commands. In this example, there are three commands applied. Each command adds 2, 3, and 4 respectively. States are values at certain points of model. If the initial state of model is zero, the latest value will be 9.
If you perform undo, the latest command 'Command2' is canceled and the model state is back to the state just after the 'Command1' was applied. The latest pointer will be updated to point 'State2' and the value will be 5 (Fig. 1.1.2).
flowchart LR;
State0["State0 (=0)"]-- "Command0 (add 2)" -->State1["State1 (=2)"];
State1-- "Command1 (add 3)" -->State2["State2 (=5)"];
State2-- "Command2 (add 4)" -->State3["State3 (=9)"];
Latest["Latest value = 5"]-.->State2;
Fig. 1.1.2 After undo performed
At the state of Fig. 1.1.2, you can perform redo to proceed to 'State3' or you can perform undo to back further to 'State0'. In both cases, the latest pointer will be updated to 'State3' or 'State0' respectively.
What about new command is added after undo is performed? If you add another command, Command 3 that adds 100, at this point, the State 3 is re-created for the command Fig. 1.1.3.
flowchart LR;
State0["State0 (=0)"]-- "Command0 (add 2)" -->State1["State1 (=2)"];
State1-- "Command1 (add 3)" -->State2["State2 (=5)"];
State2-- "Command3 (add 100)" -->State3["State3 (=105)"];
Latest["Latest value = 105"]-.->State3;
Fig. 1.1.3 Add an command (Command 3) after undo.
Undo limit can be specified. If the undo limit is specified, the oldest command will be removed when the number of commands becomes more than the limit.
The InMemoryUndoStore
is an undo store that holds commands in memory whereas the SqliteUndoStore
holds commands in a SQLite db.