getCheckpoint
The getCheckpoint
method fetches the label for a checkpoint, if it had been provided at the time of the addCheckpoint
method or set subsequently with the setCheckpoint
method.
getCheckpoint(checkpointId: string): undefined | string
Type | Description | |
---|---|---|
checkpointId | string | The |
returns | undefined | string | A string label for the requested checkpoint, an empty string if it was never set, or |
If the checkpoint has had no label provided, this method will return an empty string.
Examples
This example creates a Store
, adds a Checkpoints
object, and sets a checkpoint with a label, before retrieving it again.
import {createCheckpoints, createStore} from 'tinybase';
const store = createStore().setTables({pets: {fido: {sold: false}}});
const checkpoints = createCheckpoints(store);
store.setCell('pets', 'fido', 'sold', true);
console.log(checkpoints.addCheckpoint('sale'));
// -> '1'
console.log(checkpoints.getCheckpoint('1'));
// -> 'sale'
This example creates a Store
, adds a Checkpoints
object, and sets a checkpoint without a label, setting it subsequently. A non-existent checkpoint return an undefined
label.
import {createCheckpoints, createStore} from 'tinybase';
const store = createStore().setTables({pets: {fido: {sold: false}}});
const checkpoints = createCheckpoints(store);
store.setCell('pets', 'fido', 'sold', true);
checkpoints.addCheckpoint();
console.log(checkpoints.getCheckpoint('1'));
// -> ''
checkpoints.setCheckpoint('1', 'sold');
console.log(checkpoints.getCheckpoint('1'));
// -> 'sold'
console.log(checkpoints.getCheckpoint('2'));
// -> undefined
Since
v1.0.0