Skip to content

Commit

Permalink
chore: align to new Zustand interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sohrab- committed Apr 24, 2023
1 parent a9a4e2f commit 11108b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/hooks/useConfigStore.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import produce from "immer";
import { PersistentState } from "types/state";
import { DEFAULT_PERSISTENT_STATE } from "utils/state";
import create from "zustand";
import { persist } from "zustand/middleware";
import shallow from "zustand/shallow";
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
import { shallow } from "zustand/shallow";

/**
* Provides access to the LocalStorage Zustand store
Expand All @@ -19,6 +19,7 @@ export const useConfigStore = create<PersistentState>()(
{
name: "bcsol-config",
version: 1,
storage: createJSONStorage(() => localStorage),
}
)
);
Expand Down
23 changes: 13 additions & 10 deletions src/hooks/useSessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {
DEFAULT_SESSION_STATE_WITH_UNDO,
DEFAULT_SESSION_STATE_WITHOUT_UNDO,
} from "utils/state";
import create from "zustand";
import { persist, subscribeWithSelector } from "zustand/middleware";
import shallow from "zustand/shallow";
import { create } from "zustand";
import {
createJSONStorage,
persist,
subscribeWithSelector,
} from "zustand/middleware";
import { shallow } from "zustand/shallow";

// TODO implement undo/redo once this is resolved: https://github.com/charkour/zundo/issues/38

Expand All @@ -23,12 +27,11 @@ export const useSessionStoreWithUndo = create<SessionStateWithUndo>()(
}),
{
name: "bscol-with-undo",
getStorage: () => sessionStorage,
serialize: ({ state, ...theRest }) =>
JSON.stringify({
...theRest,
state: { ...state, lastUpdatedAt: new Date().getTime() },
}),
storage: createJSONStorage(() => sessionStorage),
partialize: (state) => ({
...state,
lastUpdatedAt: new Date().getTime(),
}),
}
)
);
Expand All @@ -50,7 +53,7 @@ export const useSessionStoreWithoutUndo = create<SessionStateWithoutUndo>()(
})),
{
name: "bscol-without-undo",
getStorage: () => sessionStorage,
storage: createJSONStorage(() => sessionStorage),
}
)
);
Expand Down

0 comments on commit 11108b6

Please sign in to comment.