goForward
The goForward
method moves the state of the underlying Store
forwards to a future checkpoint, effectively performing an 'redo' on the Store
data.
goForward(): Checkpoints
returns | Checkpoints | A reference to the |
---|
If there is no future checkpoint to return to, this method has no effect.
Note that if you have previously used the goBackward
method to undo changes, the forwards 'redo' stack will only exist while you do not make changes to the Store
. In general the goForward
method is expected to be used to redo changes that were just undone.
Examples
This example creates a Store
, a Checkpoints
object, makes a change and then goes backward to the state of the Store
before the change. It then goes forward again to restore the state with the changes.
import {createCheckpoints, createStore} from 'tinybase';
const store = createStore().setTables({pets: {fido: {sold: false}}});
const checkpoints = createCheckpoints(store);
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', []]
store.setCell('pets', 'fido', 'sold', true);
checkpoints.addCheckpoint('sale');
console.log(checkpoints.getCheckpointIds());
// -> [['0'], '1', []]
checkpoints.goBackward();
console.log(store.getCell('pets', 'fido', 'sold'));
// -> false
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', ['1']]
checkpoints.goForward();
console.log(store.getCell('pets', 'fido', 'sold'));
// -> true
console.log(checkpoints.getCheckpointIds());
// -> [['0'], '1', []]
This example creates a Store
, a Checkpoints
object, makes a change and then goes backward to the state of the Store
before the change. It makes a new change, the redo stack disappears, and then the attempt to forward again has no effect.
import {createCheckpoints, createStore} from 'tinybase';
const store = createStore().setTables({pets: {fido: {sold: false}}});
const checkpoints = createCheckpoints(store);
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', []]
store.setCell('pets', 'fido', 'sold', true);
checkpoints.addCheckpoint('sale');
console.log(checkpoints.getCheckpointIds());
// -> [['0'], '1', []]
checkpoints.goBackward();
console.log(store.getCell('pets', 'fido', 'sold'));
// -> false
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', ['1']]
store.setCell('pets', 'fido', 'color', 'brown');
console.log(checkpoints.getCheckpointIds());
// -> [['0'], undefined, []]
checkpoints.goForward();
console.log(store.getCell('pets', 'fido', 'sold'));
// -> false
console.log(checkpoints.getCheckpointIds());
// -> [['0'], undefined, []]
// The original change cannot be redone.
Since
v1.0.0