-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(BSR) refactor(Zustand): rewrite createStore (#7501)
* feat: add modal logic + a start of architecture * feat: remove created modal manager + rename createStore => createConfiguredStore * feat: replace createConfiguredStore by createStore * refactor: take reviews
- Loading branch information
1 parent
0a3218e
commit 614e12a
Showing
12 changed files
with
147 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 8 additions & 7 deletions
15
src/features/identityCheck/pages/profile/store/cityStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import { SuggestedCity } from 'libs/place/types' | ||
import { createActions } from 'libs/store/createActions' | ||
import { createStore } from 'libs/store/createStore' | ||
|
||
type State = { city: SuggestedCity | null } | ||
|
||
const defaultState: State = { city: null } | ||
|
||
const useCityStore = createStore({ | ||
const cityStore = createStore({ | ||
name: 'profile-city', | ||
defaultState, | ||
actions: (set) => ({ | ||
setCity: (city: SuggestedCity) => set({ city }), | ||
resetCity: () => set(defaultState), | ||
}), | ||
options: { | ||
persist: true, | ||
}, | ||
}) | ||
|
||
export const useCity = () => useCityStore((state) => state.city) | ||
const useCityStore = cityStore.useStore | ||
export const cityActions = cityStore.actions | ||
|
||
export const cityActions = createActions(useCityStore, (set) => ({ | ||
setCity: (city: SuggestedCity) => set({ city }), | ||
resetCity: () => set(defaultState), | ||
})) | ||
export const useCity = () => useCityStore((state) => state.city) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { StoreApi, UseBoundStore } from 'zustand' | ||
|
||
export type AnyFunction = (...args: never) => unknown | ||
export type CurriedAnyFunction<State> = (...args: never) => (state: State) => unknown | ||
type Options = { | ||
persist?: boolean | ||
} | ||
type StoreType<State> = UseBoundStore<StoreApi<State>> | ||
export type StoreConfig< | ||
State, | ||
Actions extends Record<string, AnyFunction>, | ||
Selectors extends Record<string, CurriedAnyFunction<State>>, | ||
> = { | ||
name: string | ||
defaultState: State | ||
actions?: (setState: StoreType<State>['setState']) => Actions | ||
selectors?: Selectors | ||
options?: Options | ||
} | ||
export type Store< | ||
State, | ||
Actions extends Record<string, AnyFunction>, | ||
Selectors extends Record<string, CurriedAnyFunction<State>>, | ||
> = { | ||
useStore: UseBoundStore<StoreApi<State>> | ||
actions: Actions | ||
selectors: Selectors | ||
select: <T>(selector: (state: State) => T) => T | ||
} |