clearForward
The clearForward method resets just the 'redo' checkpoints it has been managing.
clearForward(): Checkpoints| returns | Checkpoints | A reference to the |
|---|
Obviously this method should be used with caution as it destroys the ability to redo recent changes to the Store (though of course the Store itself is not reset by this method).
This method can be useful when you want to prohibit a user from redoing changes they have undone. The 'backward' redo stack, and current checkpoint are not affected.
Example
This example creates a Store, a Checkpoints object, adds a listener, makes a change and then clears the forward checkpoints.
import {createCheckpoints, createStore} from 'tinybase';
const store = createStore().setTables({pets: {fido: {sold: false}}});
const checkpoints = createCheckpoints(store);
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', []]
const listenerId = checkpoints.addCheckpointIdsListener(() => {
console.log('checkpoints changed');
});
store.setCell('pets', 'fido', 'color', 'brown');
// -> 'checkpoints changed'
checkpoints.addCheckpoint();
// -> 'checkpoints changed'
store.setCell('pets', 'fido', 'sold', true);
// -> 'checkpoints changed'
checkpoints.addCheckpoint();
// -> 'checkpoints changed'
checkpoints.goBackward();
// -> 'checkpoints changed'
console.log(store.getTables());
// -> {pets: {fido: {color: 'brown', sold: false}}}
console.log(checkpoints.getCheckpointIds());
// -> [['0'], '1', ['2']]
checkpoints.clearForward();
// -> 'checkpoints changed'
console.log(checkpoints.getCheckpointIds());
// -> [['0'], '1', []]
checkpoints.delListener(listenerId);
Since
v4.5.3