|
758 | 758 | * removing all the checkpoints it has been managing. |
759 | 759 | * |
760 | 760 | * Obviously this method should be used with caution as it destroys the |
761 | | - * ability to undo recent changes to the Store (though of course the Store |
762 | | - * itself is not reset by this method). |
| 761 | + * ability to undo or redo recent changes to the Store (though of course the |
| 762 | + * Store itself is not reset by this method). |
763 | 763 | * |
764 | 764 | * This method can be useful when a Store is being loaded via a Persister |
765 | 765 | * asynchronously after the Checkpoints object has been attached, and you |
|
807 | 807 | * @category Lifecycle |
808 | 808 | */ |
809 | 809 | /// Checkpoints.clear |
| 810 | + /** |
| 811 | + * The clearForward method resets just the 'redo' checkpoints it has been |
| 812 | + * managing. |
| 813 | + * |
| 814 | + * Obviously this method should be used with caution as it destroys the |
| 815 | + * ability to redo recent changes to the Store (though of course the Store |
| 816 | + * itself is not reset by this method). |
| 817 | + * |
| 818 | + * This method can be useful when you want to prohibit a user from redoing |
| 819 | + * changes they have undone. The 'backward' redo stack, and current checkpoint |
| 820 | + * are not affected. |
| 821 | + * @returns A reference to the Checkpoints object. |
| 822 | + * @example |
| 823 | + * This example creates a Store, a Checkpoints object, adds a listener, makes |
| 824 | + * a change and then clears the forward checkpoints. |
| 825 | + * |
| 826 | + * ```js |
| 827 | + * const store = createStore().setTables({pets: {fido: {sold: false}}}); |
| 828 | + * |
| 829 | + * const checkpoints = createCheckpoints(store); |
| 830 | + * console.log(checkpoints.getCheckpointIds()); |
| 831 | + * // -> [[], '0', []] |
| 832 | + * |
| 833 | + * const listenerId = checkpoints.addCheckpointIdsListener(() => { |
| 834 | + * console.log('checkpoints changed'); |
| 835 | + * }); |
| 836 | + * |
| 837 | + * store.setCell('pets', 'fido', 'color', 'brown'); |
| 838 | + * // -> 'checkpoints changed' |
| 839 | + * checkpoints.addCheckpoint(); |
| 840 | + * // -> 'checkpoints changed' |
| 841 | + * store.setCell('pets', 'fido', 'sold', true); |
| 842 | + * // -> 'checkpoints changed' |
| 843 | + * checkpoints.addCheckpoint(); |
| 844 | + * // -> 'checkpoints changed' |
| 845 | + * checkpoints.goBackward(); |
| 846 | + * // -> 'checkpoints changed' |
| 847 | + * |
| 848 | + * console.log(store.getTables()); |
| 849 | + * // -> {pets: {fido: {color: 'brown', sold: false}}} |
| 850 | + * console.log(checkpoints.getCheckpointIds()); |
| 851 | + * // -> [['0'], '1', ['2']] |
| 852 | + * |
| 853 | + * checkpoints.clearForward(); |
| 854 | + * // -> 'checkpoints changed' |
| 855 | + * |
| 856 | + * console.log(checkpoints.getCheckpointIds()); |
| 857 | + * // -> [['0'], '1', []] |
| 858 | + * ``` |
| 859 | + * @category Lifecycle |
| 860 | + * @since v4.5.3 |
| 861 | + */ |
| 862 | + /// Checkpoints.clearForward |
810 | 863 | /** |
811 | 864 | * The destroy method should be called when this Checkpoints object is no |
812 | 865 | * longer used. |
|
0 commit comments