goBackward
The goBackward
method moves the state of the underlying Store
back to the previous checkpoint, effectively performing an 'undo' on the Store
data.
goBackward(): Checkpoints
returns | Checkpoints | A reference to the |
---|
If there is no previous checkpoint to return to, this method has no effect.
Example
This example creates a Store
, a Checkpoints
object, makes a change and then goes backward to the state of the Store
before the change.
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']]
Since
v1.0.0