TinyBase logoTinyBase

setSize

The setSize method lets you specify how many checkpoints the Checkpoints object will store.

setSize(size: number): Checkpoints
TypeDescription
sizenumber

The number of checkpoints that this Checkpoints object should hold.

returnsCheckpoints

A reference to the Checkpoints object.

If you set more checkpoints than this size, the oldest checkpoints will be pruned to make room for more recent ones.

The default size for a newly-created Checkpoints object is 100.

Example

This example creates a Store, adds a Checkpoints object, reduces the size of the Checkpoints object dramatically and then creates more than that number of checkpoints to demonstrate the oldest being pruned.

const store = createStore().setTables({pets: {fido: {views: 0}}});

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

store.setCell('pets', 'fido', 'views', 1);
checkpoints.addCheckpoint();
console.log(checkpoints.getCheckpointIds());
// -> [['0'], '1', []]

store.setCell('pets', 'fido', 'views', 2);
checkpoints.addCheckpoint();
console.log(checkpoints.getCheckpointIds());
// -> [['0', '1'], '2', []]

store.setCell('pets', 'fido', 'views', 3);
checkpoints.addCheckpoint();
console.log(checkpoints.getCheckpointIds());
// -> [['1', '2'], '3', []]