🍜 undo/redo middleware for zustand. <700 bytes
850 B --> 852 B
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.19...v2.0.0-beta.20
857 B --> 850 B
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.18...v2.0.0-beta.19
877 B --> 857 B (Shave 20 bytes)
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.17...v2.0.0-beta.18
888 B --> 877 B (save 11 bytes)
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.16...v2.0.0-beta.17
Wrap temporal store from @SugarF0x
wrapTemporal?: (storeInitializer: StateCreator<TemporalStateWithInternals<TState>, [StoreMutatorIdentifier, unknown][], []>) => StateCreator<TemporalStateWithInternals<TState>, [StoreMutatorIdentifier, unknown][], [StoreMutatorIdentifier, unknown][]>
You can wrap the temporal store with your own middleware. This is useful if you want to add additional functionality to the temporal store. For example, you can add persist
middleware to the temporal store to persist the past and future states to local storage.
Note: The
temporal
middleware can be added to thetemporal
store. This way, you could track the history of the history. 🤯
import { persist } from 'zustand/middleware'
const withTemporal = temporal<MyState>(
(set) => ({ ... }),
{
wrapTemporal: (storeInitializer) => persist(storeInitializer, { name: 'temporal-persist' }),
},
);
Size 865 B --> 888 B (increase 23 B)
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.15...v2.0.0-beta.16
New feature!
pastStates?: Partial<PartialTState>[]
futureStates?: Partial<PartialTState>[]
You can initialize the temporal store with past and future states. This is useful when you want to load a previous state from a database or initialize the store with a default state. By default, the temporal store is initialized with an empty array of past and future states.
Note: The
pastStates
andfutureStates
do not respect the limit set in the options. If you want to limit the number of past and future states, you must do so manually prior to initializing the store.
const withTemporal = temporal<MyState>(
(set) => ({ ... }),
{
pastStates: [{ field1: 'value1' }, { field1: 'value2' }],
futureStates: [{ field1: 'value3' }, { field1: 'value4' }],
},
);
Related https://github.com/charkour/zundo/issues/75
847 B --> 865 B (increase 18 bytes)
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.14...v2.0.0-beta.15
Reduce package size by 21 bytes. 868 B --> 847 B
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.13...v2.0.0-beta.14
7.3% smaller by shaving 69 bytes. Add better React tests 937 bytes --> 868 bytes
This a potentially breaking change for those who rely on internal properties.
// Before
myStore.temporal.getState().__interal.onSave
// After
myStore.temporal.getState().__onSave
// Before
myStore.temporal.getState().__interal.handleuserSet
// After
myStore.temporal.getState().__handleUserSet
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.12...v2.0.0-beta.13
962 B --> 937 B (25 bytes)
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.11...v2.0.0-beta.12
Full Changelog: https://github.com/charkour/zundo/compare/v2.0.0-beta.10...v2.0.0-beta.11