-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring for separation of concerns #26
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
57a868c
good bye
test-user-jinma-ml 5a53bd0
initialize with vite
test-user-jinma-ml e258b82
add simple pages
test-user-jinma-ml 51de226
introduce msw
test-user-jinma-ml cf8fbf4
adjust mock api response
test-user-jinma-ml d5668bd
rename to http
test-user-jinma-ml a7e6255
implement auth hook
test-user-jinma-ml 4e75e63
adapting to the existing style
test-user-jinma-ml 6ea1cc5
adjusting layouts with routes
test-user-jinma-ml 6d695f8
add delay to mock response
test-user-jinma-ml 842067f
render error message
test-user-jinma-ml b85d330
npx npm-check-updates -u
jinmayamashita 415e4c0
example useMutation hook
jinmayamashita 11b92de
update user type
jinmayamashita 7172283
try use constate
jinmayamashita b29e2dc
add separate components
jinmayamashita 0786075
add storybook
jinmayamashita e8b699a
try testing button with storybook
jinmayamashita 03b7b25
introduce i18next
jinmayamashita a520ee9
specify the version of node
jinmayamashita d3f4fba
add type check script
jinmayamashita 06908af
adjust demo styles
jinmayamashita d7acb04
count component to simply
jinmayamashita dc95587
use lazy loads
jinmayamashita fd316ca
try to zustand
jinmayamashita 91c4b73
use css modules with classNames
jinmayamashita 5f94e94
Update __mocks__/api/login.ts
jinmayamashita 08f9c22
Update src/pages/NotFound.tsx
jinmayamashita 544abba
Update src/routes.tsx
jinmayamashita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useCountStore } from "@/stores/countStore"; | ||
|
||
const Count = () => { | ||
const count = useCountStore((state) => state.curr); | ||
return <p>You clicked {count}</p>; | ||
}; | ||
|
||
const UndoCountButton: React.FC = () => { | ||
const undo = useCountStore((state) => state.undo); | ||
const hasPrev = useCountStore((state) => state.hasPrev()); | ||
|
||
return ( | ||
<button onClick={undo} disabled={!hasPrev}> | ||
undo | ||
</button> | ||
); | ||
}; | ||
|
||
const RedoCountButton: React.FC = () => { | ||
const redo = useCountStore((state) => state.redo); | ||
const hasNext = useCountStore((state) => state.hasNext()); | ||
|
||
return ( | ||
<button onClick={redo} disabled={!hasNext}> | ||
redo | ||
</button> | ||
); | ||
}; | ||
|
||
const SetCountButton: React.FC = ({}) => { | ||
const getCount = useCountStore((state) => state.getCurr); | ||
const set = useCountStore((state) => state.set); | ||
|
||
return ( | ||
<> | ||
<button onClick={() => set(getCount() - 1)}>-</button> | ||
<button onClick={() => set(getCount() + 1)}>+</button> | ||
</> | ||
); | ||
}; | ||
|
||
const ResetCountButton: React.FC = ({}) => { | ||
const reset = useCountStore((state) => state.reset); | ||
|
||
return <button onClick={() => reset(0)}>reset to 0</button>; | ||
}; | ||
|
||
const StateHistoryCount = () => ( | ||
<> | ||
<Count /> | ||
<SetCountButton /> | ||
<UndoCountButton /> | ||
<RedoCountButton /> | ||
<ResetCountButton /> | ||
</> | ||
); | ||
|
||
export default StateHistoryCount; |
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,55 @@ | ||
import create from "zustand"; | ||
|
||
type State = { prev: number[]; curr: number; next: number[] }; | ||
|
||
type Selectors = { | ||
getCurr: () => State["curr"]; | ||
hasPrev: () => boolean; | ||
hasNext: () => boolean; | ||
}; | ||
|
||
type Actions = { | ||
undo: () => void; | ||
redo: () => void; | ||
set: (value: State["curr"]) => void; | ||
reset: (value: State["curr"]) => void; | ||
}; | ||
|
||
type Store = State & Selectors & Actions; | ||
export const useCountStore = create<Store>((set, get) => ({ | ||
// state | ||
prev: [], | ||
curr: 0, | ||
next: [], | ||
|
||
// selectors | ||
getCurr: () => get().curr, | ||
hasPrev: () => get().prev.length > 0, | ||
hasNext: () => get().next.length > 0, | ||
|
||
// actions | ||
undo: () => | ||
set((state) => ({ | ||
prev: state.prev.slice(0, state.prev.length - 1), | ||
curr: state.prev[state.prev.length - 1], | ||
next: [state.curr, ...state.next], | ||
})), | ||
redo: () => | ||
set((state) => ({ | ||
prev: [...state.prev, state.curr], | ||
curr: state.next[0], | ||
next: state.next.slice(1), | ||
})), | ||
set: (newCurr) => | ||
set((state) => ({ | ||
prev: [...state.prev, state.curr], | ||
curr: newCurr, | ||
next: [], | ||
})), | ||
reset: (newCurr) => | ||
set({ | ||
prev: [], | ||
curr: newCurr, | ||
next: [], | ||
}), | ||
})); |
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ export type Path = | |
| "/home" | ||
| "/profile" | ||
| "/count" | ||
| "/setcount"; | ||
| "/setcount" | ||
| "/count_with_history"; |
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 |
---|---|---|
|
@@ -12176,6 +12176,11 @@ 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== | ||
|
||
[email protected]: | ||
version "3.7.1" | ||
resolved "https://registry.yarnpkg.com/zustand/-/zustand-3.7.1.tgz#7388f0a7175a6c2fd9a2880b383a4bf6cdf6b7c6" | ||
integrity sha512-wHBCZlKj+bg03/hP+Tzv24YhnqqP8MCeN9ECPDXoF01062SIbnfl3j9O0znkDw1lNTY0a8WN3F///a0UhhaEqg== | ||
|
||
zwitch@^1.0.0: | ||
version "1.0.5" | ||
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying out a counter with redo/undo functionality in zustand.
re-render appears to be prevented 👀
Kapture.2022-03-02.at.11.35.28.mp4