addCheckpointIdsListener
The addCheckpointIdsListener
method registers a listener function with the Checkpoints
object that will be called whenever its set of checkpoints changes.
addCheckpointIdsListener(listener: CheckpointIdsListener): string
Type | Description | |
---|---|---|
listener | CheckpointIdsListener | The function that will be called whenever the checkpoints change. |
returns | string | A unique |
The provided listener is a CheckpointIdsListener
function, and will be called with a reference to the Checkpoints
object.
Example
This example creates a Store
, a Checkpoints
object, and then registers a listener that responds to any changes to the 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('Checkpoint Ids changed');
console.log(checkpoints.getCheckpointIds());
});
store.setCell('pets', 'fido', 'species', 'dog');
// -> 'Checkpoint Ids changed'
// -> [['0'], undefined, []]
checkpoints.addCheckpoint();
// -> 'Checkpoint Ids changed'
// -> [['0'], '1', []]
checkpoints.goBackward();
// -> 'Checkpoint Ids changed'
// -> [[], '0', ['1']]
checkpoints.goForward();
// -> 'Checkpoint Ids changed'
// -> [['0'], '1', []]
checkpoints.delListener(listenerId);
Since
v1.0.0