setSize
The setSize
method lets you specify how many checkpoints the Checkpoints
object will store.
setSize(size: number): Checkpoints
Type | Description | |
---|---|---|
size | number | The number of checkpoints that this |
returns | Checkpoints | A reference to the |
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.
import {createCheckpoints, createStore} from 'tinybase';
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', []]
Since
v1.0.0