Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restructure __internals to shave bytes; add react tests #82

Merged
merged 12 commits into from
Apr 22, 2023
Prev Previous commit
Next Next commit
shave 3 bytes: don't re-create object
  • Loading branch information
charkour committed Apr 22, 2023
commit 245f961adba918b47ea3de8d2efacd16d7bd4ebd
2 changes: 1 addition & 1 deletion packages/zundo/__tests__/createVanillaTemporal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('createVanillaTemporal', () => {
};
});

const temporalStore = createVanillaTemporal(store.setState, store.getState);
const temporalStore = createVanillaTemporal(store.setState, store.getState, (state) => state);
const { undo, redo, clear, pastStates, futureStates } =
temporalStore.getState();
it('should have the objects defined', () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/zundo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ const zundoImpl =
type TState = ReturnType<typeof config>;
type StoreAddition = StoreApi<TemporalState<TState>>;

const temporalStore = createVanillaTemporal<TState>(set, get, {
partialize,
...restOptions,
});
const temporalStore = createVanillaTemporal<TState>(set, get, partialize, restOptions);

const store = _store as Mutate<
StoreApi<TState>,
Expand Down
6 changes: 2 additions & 4 deletions packages/zundo/src/temporal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import type {
export const createVanillaTemporal = <TState>(
userSet: StoreApi<TState>['setState'],
userGet: StoreApi<TState>['getState'],
{ partialize, equality, onSave, limit } = {} as Omit<
WithRequired<ZundoOptions<TState>, 'partialize'>,
'handleSet'
>,
partialize: (state: TState) => TState,
{ equality, onSave, limit } = {} as Omit<ZundoOptions<TState>, 'handleSet'>,
) => {
return createStore<TemporalStateWithInternals<TState>>()((set, get) => {
return {
Expand Down