Skip to content

Commit

Permalink
fix: removed deprecated usage of equalityFn, adjusted import (now f…
Browse files Browse the repository at this point in the history
…rom `zustand/traditional`) fixes #139

BREAKING CHANGE: Now requires minimum `zustand` `^4.4.0`
  • Loading branch information
BowlingX committed Aug 12, 2023
1 parent cf2676e commit 1e96120
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 32 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"next": ">=11",
"react": ">=16.8",
"react-dom": ">=16.8",
"zustand": ">=4"
"zustand": ">=4.4.0"
},
"peerDependenciesMeta": {
"next": {
Expand All @@ -114,8 +114,8 @@
"@storybook/builder-webpack5": "^6.5.15",
"@storybook/manager-webpack5": "^6.5.15",
"@storybook/react": "^6.5.15",
"@testing-library/dom": "^9.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.2.5",
Expand Down Expand Up @@ -153,7 +153,7 @@
"typedoc": "^0.23.24",
"typescript": "^4.9.4",
"webpack": "^5.75.0",
"zustand": "^4.3.8"
"zustand": "^4.4.1"
},
"resolutions": {
"lodash": "^4.17.21",
Expand Down
22 changes: 11 additions & 11 deletions src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import {
useMemo,
useState,
} from 'react'
import { create, Mutate, StateCreator, StoreApi, UseBoundStore } from 'zustand'
import { Mutate, StateCreator, StoreApi, UseBoundStore } from 'zustand'
// tslint:disable-next-line:no-submodule-imports
import { devtools, subscribeWithSelector } from 'zustand/middleware'
// tslint:disable-next-line:no-submodule-imports
import { createWithEqualityFn } from 'zustand/traditional'

const memoizeOne = memoizeOneImport.default || memoizeOneImport

Expand Down Expand Up @@ -82,11 +84,12 @@ export const useGeschichte = <T extends object>(
) as unknown as StateCreator<StoreState<T>, any>

if (process.env.NODE_ENV !== 'production' && typeof window !== 'undefined') {
return create(
subscribeWithSelector(devtools(middleware, { name: 'geschichte' }))
return createWithEqualityFn(
subscribeWithSelector(devtools(middleware, { name: 'geschichte' })),
shallow
)
}
return create(subscribeWithSelector(middleware))
return createWithEqualityFn(subscribeWithSelector(middleware), shallow)
}

type InitialValuesProvider<T> = T | (() => T)
Expand All @@ -108,13 +111,10 @@ export const useStore = <T extends object>() => {

export const useBatchQuery = <T extends object>() => {
const store = useStore<T>()
return store(
({ batchPushState, batchReplaceState }) => ({
batchPushState,
batchReplaceState,
}),
shallow
)
return store(({ batchPushState, batchReplaceState }) => ({
batchPushState,
batchReplaceState,
}))
}

export const factoryParameters = <T extends object>(
Expand Down
Loading

0 comments on commit 1e96120

Please sign in to comment.