setCheckpoint
The setCheckpoint
method updates the label for a checkpoint in the Checkpoints
object after it has been created.
setCheckpoint(
checkpointId: string,
label: string,
): Checkpoints
Type | Description | |
---|---|---|
checkpointId | string | The |
label | string | A label to describe the actions leading up to this checkpoint or left undefined if you want to clear the current label. |
returns | Checkpoints | A reference to the |
The label
parameter can be used to describe the actions that changed the Store
before the given checkpoint. This can be useful for interfaces that let users 'Undo [last action]'.
Generally you will provide the label
parameter when the addCheckpoint
method is called. Use this setCheckpoint
method only when you need to change the label at a later point.
You cannot add a label to a checkpoint that does not yet exist.
Example
This example creates a Store
, adds a Checkpoints
object, and sets two checkpoints, one with a label, which are both then re-labelled.
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', 'species', 'dog');
checkpoints.addCheckpoint();
store.setCell('pets', 'fido', 'sold', true);
checkpoints.addCheckpoint('sale');
console.log(checkpoints.getCheckpoint('1'));
// -> ''
console.log(checkpoints.getCheckpoint('2'));
// -> 'sale'
checkpoints.setCheckpoint('1', 'identified');
checkpoints.setCheckpoint('2', '');
console.log(checkpoints.getCheckpoint('1'));
// -> 'identified'
console.log(checkpoints.getCheckpoint('2'));
// -> ''
checkpoints.setCheckpoint('3', 'unknown');
console.log(checkpoints.getCheckpoint('3'));
// -> undefined
Since
v1.0.0