@@ -33,6 +33,20 @@ import {Store} from './store.d';
3333 */
3434export type CheckpointIds = [ Ids , Id | undefined , Ids ] ;
3535
36+ /**
37+ * The CheckpointCallback type describes a function that takes a Checkpoint's
38+ * Id.
39+ *
40+ * A CheckpointCallback is provided when using the forEachCheckpoint method,
41+ * so that you can do something based on every Checkpoint in the Checkpoints
42+ * object. See that method for specific examples.
43+ *
44+ * @param checkpointId The Id of the Checkpoint that the callback can operate
45+ * on.
46+ * @category Callback
47+ */
48+ export type CheckpointCallback = ( checkpointId : Id , label ?: string ) => void ;
49+
3650/**
3751 * The CheckpointIdsListener type describes a function that is used to listen to
3852 * changes to the checkpoint Ids in a Checkpoints object.
@@ -353,6 +367,36 @@ export interface Checkpoints {
353367 */
354368 getCheckpointIds ( ) : CheckpointIds ;
355369
370+ /**
371+ * The forEachCheckpoint method takes a function that it will then call for
372+ * each Checkpoint in a specified Checkpoints object.
373+ *
374+ * This method is useful for iterating over the structure of the Checkpoints
375+ * object in a functional style. The `checkpointCallback` parameter is a
376+ * CheckpointCallback function that will be called with the Id of each
377+ * Checkpoint.
378+ *
379+ * @param checkpointCallback The function that should be called for every
380+ * Checkpoint.
381+ * @example
382+ * This example iterates over each Checkpoint in a Checkpoints object.
383+ *
384+ * ```js
385+ * const store = createStore().setTables({pets: {fido: {sold: false}}});
386+ * const checkpoints = createCheckpoints(store);
387+ * store.setCell('pets', 'fido', 'sold', true);
388+ * checkpoints.addCheckpoint('sale');
389+ *
390+ * checkpoints.forEachCheckpoint((checkpointId, label) => {
391+ * console.log(`${checkpointId}:${label}`);
392+ * });
393+ * // -> '0:'
394+ * // -> '1:sale'
395+ * ```
396+ * @category Iterator
397+ */
398+ forEachCheckpoint ( checkpointCallback : CheckpointCallback ) : void ;
399+
356400 /**
357401 * The hasCheckpoint method returns a boolean indicating whether a given
358402 * Checkpoint exists in the Checkpoints object.
0 commit comments