-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor stores to use Zustand's slice pattern (#771)
* refactor: Convert individual stores to Zustand's slice pattern * refactor: Refactor MatchingPairs.stories.js and add Decorator to preset store * fix: Fix MatchingPairs tests * fix: Refactor Final.test.js to mock useBoundStore and fix formatting * refactor: Rename decorators from Decorator to StoreDecorator in MatchingPairs.stories.js
- Loading branch information
1 parent
171611f
commit 5cb2e02
Showing
10 changed files
with
85 additions
and
76 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
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 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,15 +1,11 @@ | ||
module.exports = { | ||
useSessionStore: (fn) => { | ||
const methods = { | ||
useBoundStore: () => { | ||
return { | ||
setError: jest.fn(), | ||
setParticipant: jest.fn(), | ||
setSession: jest.fn(), | ||
session: {id: 1} | ||
} | ||
return fn(methods); | ||
}, | ||
useParticipantStore: () => { | ||
return {id: 1} | ||
}, | ||
useErrorStore: () => { | ||
return {setError: jest.fn()} | ||
participant: { id: 1 }, | ||
session: { id: 1 } | ||
} | ||
} | ||
}; |
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,17 +1,25 @@ | ||
import { create } from "zustand"; | ||
|
||
// Stores | ||
export const useErrorStore = create((set) => ({ | ||
export const createErrorSlice = (set) => ({ | ||
error: null, | ||
setError: (error) => set((state) => ({error})) | ||
})); | ||
setError: (error) => set(() => ({ error })) | ||
}); | ||
|
||
export const useParticipantStore = create((set) => ({ | ||
export const createParticipantSlice = (set) => ({ | ||
participant: null, | ||
setParticipant: (participant) => set((state) => ({participant})) | ||
})); | ||
setParticipant: (participant) => set(() => ({ participant })) | ||
}); | ||
|
||
export const useSessionStore = create((set) => ({ | ||
export const createSessionSlice = (set) => ({ | ||
session: null, | ||
setSession: (session) => set((state) => ({session})) | ||
})); | ||
setSession: (session) => set(() => ({ session })) | ||
}); | ||
|
||
export const useBoundStore = create((...args) => ({ | ||
...createErrorSlice(...args), | ||
...createParticipantSlice(...args), | ||
...createSessionSlice(...args) | ||
})); | ||
|
||
export default useBoundStore; |