Skip to content

Commit

Permalink
fix: bumped zustand to version 4.x
Browse files Browse the repository at this point in the history
BREAKING CHANGE: require `zustand` >= `4.x`
  • Loading branch information
BowlingX committed Jun 25, 2022
1 parent 5947e52 commit 85e963f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"next": ">=11",
"react": ">=16.8",
"react-dom": ">=16.8",
"zustand": ">=3.6.0"
"zustand": ">=4"
},
"peerDependenciesMeta": {
"next": {
Expand Down Expand Up @@ -139,7 +139,7 @@
"typedoc": "^0.22.15",
"typescript": "^4.7.2",
"webpack": "^5.72.1",
"zustand": "^3.7.2"
"zustand": "^4.0.0-rc.1"
},
"resolutions": {
"lodash": "^4.17.21",
Expand Down
29 changes: 10 additions & 19 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import {
enablePatches()

export const DEFAULT_NAMESPACE = 'default'
export const StoreContext = createContext<UseBoundStore<
StoreState<any>
> | null>(null)
export const StoreContext = createContext<StoreApi<StoreState<any>> | null>(
null
)

export interface Parameter<V = any> {
readonly name: string
Expand Down Expand Up @@ -83,30 +83,22 @@ export const useGeschichte = <T extends State>(
const thisStore = converter<T>(historyInstance)
const storeWithHistory = historyManagement<T>(historyInstance)(thisStore)

const middleware = immerWithPatches<T>(
const middleware = immerWithPatches(
storeWithHistory
) as unknown as StateCreator<StoreState<T>>
) as unknown as StateCreator<StoreState<T>, any>

if (process.env.NODE_ENV === 'development' && typeof window !== 'undefined') {
return create<
StoreState<T>,
SetState<StoreState<T>>,
GetState<StoreState<T>>,
StoreApi<StoreState<T>>
>(subscribeWithSelector(devtools(middleware, { name: 'geschichte' })))
return create(
subscribeWithSelector(devtools(middleware, { name: 'geschichte' }))
)
}
return create<
StoreState<T>,
SetState<StoreState<T>>,
GetState<StoreState<T>>,
StoreApi<StoreState<T>>
>(subscribeWithSelector(middleware))
return create(subscribeWithSelector(middleware))
}

type InitialValuesProvider<T> = T | (() => T)

export const useStore = <T extends object>() => {
return useContext(StoreContext) as UseBoundStore<StoreState<T>>
return useContext(StoreContext) as UseBoundStore<StoreApi<StoreState<T>>>
}

export const useBatchQuery = <T extends State>() => {
Expand Down Expand Up @@ -158,7 +150,6 @@ export const factoryParameters = <T extends object>(

const useQuery = () => {
const useStore = useContext(StoreContext) as UseBoundStore<
StoreState<T>,
Mutate<
StoreApi<StoreState<T>>,
[['zustand/subscribeWithSelector', never]]
Expand Down
15 changes: 11 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14729,6 +14729,11 @@ urlgrey@1.0.0:
dependencies:
fast-url-parser "^1.1.3"

use-sync-external-store@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.1.0.tgz#3343c3fe7f7e404db70f8c687adf5c1652d34e82"
integrity sha512-SEnieB2FPKEVne66NpXPd1Np4R1lTNKfjuy3XdIoPQKYBAFdzbzSZlSn1KJZUiihQLQC5Znot4SBz1EOTBwQAQ==

use@^3.1.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
Expand Down Expand Up @@ -15393,10 +15398,12 @@ yocto-queue@^0.1.0:
resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b"
integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==

zustand@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-3.7.2.tgz#7b44c4f4a5bfd7a8296a3957b13e1c346f42514d"
integrity sha512-PIJDIZKtokhof+9+60cpockVOq05sJzHCriyvaLBmEJixseQ1a5Kdov6fWZfWOu5SK9c+FhH1jU0tntLxRJYMA==
zustand@^4.0.0-rc.1:
version "4.0.0-rc.1"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.0.0-rc.1.tgz#ec30a3afc03728adec7e1bd7bcc3592176372201"
integrity sha512-qgcs7zLqBdHu0PuT3GW4WCIY5SgXdsv30GQMu9Qpp1BA2aS+sNS8l4x0hWuyEhjXkN+701aGWawhKDv6oWJAcw==
dependencies:
use-sync-external-store "1.1.0"

zwitch@^1.0.0:
version "1.0.5"
Expand Down

0 comments on commit 85e963f

Please sign in to comment.