Edit, view, and save are different operations
For a menu/editor:
View: calculate/display from current data; no mutation.
Edit: mutate a runtime/cache value and mark dirty.
Save: validate and commit dirty state on an explicit action.
Cancel: restore the cached original or discard dirty changes.
int value;
int original_value;
int dirty;
int editor_open;
function editor_enter() {
original_value = value;
dirty = FALSE;
editor_open = TRUE;
}
function editor_change(delta) {
value = value + delta;
if(value < 0) value = 0;
if(value > 100) value = 100;
dirty = TRUE;
}
function editor_cancel() {
value = original_value;
dirty = FALSE;
editor_open = FALSE;
}This prevents merely opening a page from changing persistence.
Last updated

