TinyBase

clear

The clear method resets this Checkpoints object to its initial state, removing all the checkpoints it has been managing.

clear(): Checkpoints
returnsCheckpoints

A reference to the Checkpoints object.

Obviously this method should be used with caution as it destroys the ability to undo recent changes to the Store (though of course the Store itself is not reset by this method).

This method can be useful when a Store is being loaded via a Persister asynchronously after the Checkpoints object has been attached, and you don't want users to be able to undo the initial load of the data. In this you could call the clear method immediately after the initial load so that that is the baseline from which all subsequent changes are tracked.

If you are listening to

Example

This example creates a Store, a Checkpoints object, adds a listener, makes a change and then clears the checkpoints.

const store = createStore().setTables({pets: {fido: {sold: false}}});

const checkpoints = createCheckpoints(store);
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', []]

const listenerId = checkpoints.addCheckpointIdsListener(() => {
  console.log('checkpoints changed');
});

store.setCell('pets', 'fido', 'color', 'brown');
// -> 'checkpoints changed'
checkpoints.addCheckpoint();
// -> 'checkpoints changed'
store.setCell('pets', 'fido', 'sold', true);
// -> 'checkpoints changed'
checkpoints.addCheckpoint();
// -> 'checkpoints changed'

console.log(store.getTables());
// -> {pets: {fido: {sold: true, color: 'brown'}}}
console.log(checkpoints.getCheckpointIds());
// -> [['0', '1'], '2', []]

checkpoints.clear();
// -> 'checkpoints changed'

console.log(store.getTables());
// -> {pets: {fido: {sold: true, color: 'brown'}}}
console.log(checkpoints.getCheckpointIds());
// -> [[], '0', []]