Skip to content

Commit 3823c42

Browse files
authored
Merge pull request #8 from treetips/feature/change_store_directory_structure
Change directory structure from redux-way to re-ducks
2 parents a31135e + 2444de4 commit 3823c42

File tree

22 files changed

+99
-105
lines changed

22 files changed

+99
-105
lines changed

components/molecules/PageHeader.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Paper, Typography } from "@material-ui/core"
22
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
33
import React from "react"
44
import { useSelector } from "react-redux"
5-
import { IInitialState } from "../../store/states"
5+
import { selectedPageSelector } from "../../store/page"
66

77
const useStyles = makeStyles((theme: Theme) =>
88
createStyles({
@@ -26,8 +26,6 @@ const useStyles = makeStyles((theme: Theme) =>
2626

2727
interface IProps {}
2828

29-
const selectedPageSelector = (state: IInitialState) => state.page.selectedPage
30-
3129
/**
3230
* Page header component
3331
* @param props IProps

components/organisms/ResponsiveDrawer.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
44
import MenuIcon from "@material-ui/icons/Menu"
55
import React, { useState } from "react"
66
import { useSelector } from "react-redux"
7-
import { IInitialState } from "../../store/states"
7+
import { selectedPageSelector } from "../../store/page"
88
import { Sidenavi } from "../organisms"
99

1010
const drawerWidth = 290
@@ -51,8 +51,6 @@ interface IProps {
5151
children: React.ReactNode
5252
}
5353

54-
const selectedPageSelector = (state: IInitialState) => state.page.selectedPage
55-
5654
/**
5755
* Responsive drawer
5856
* @see https://material-ui.com/demos/drawers/#responsive-drawer

components/organisms/Sidenavi.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
33
import SvgIcon from "@material-ui/core/SvgIcon"
44
import { useDispatch, useSelector } from "react-redux"
55
import { Page, SiteInfo } from "../../constants"
6-
import { PageActions } from "../../store/actions"
7-
import { IInitialState } from "../../store/states"
6+
import { PageActions, selectedPageSelector } from "../../store/page"
87
import { NextListItem } from "../molecules"
98

109
const useStyles = makeStyles((theme: Theme) =>
@@ -47,8 +46,6 @@ const useStyles = makeStyles((theme: Theme) =>
4746

4847
interface IProps {}
4948

50-
const selectedPageSelector = (state: IInitialState) => state.page.selectedPage
51-
5249
/**
5350
* Side navigation component
5451
* @param props IProps

components/templates/Layout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
22
import Head from "next/head"
33
import * as React from "react"
44
import { useSelector } from "react-redux"
5-
import { IInitialState } from "../../store/states"
5+
import { selectedPageSelector } from "../../store/page"
66
import { ResponsiveDrawer } from "../organisms"
77

88
const useStyles = makeStyles((theme: Theme) =>
@@ -17,8 +17,6 @@ interface IProps {
1717
children: React.ReactNode
1818
}
1919

20-
const selectedPageSelector = (state: IInitialState) => state.page.selectedPage
21-
2220
export const Layout = function(props: IProps) {
2321
const { children } = props
2422
const classes = useStyles(props)

pages/about.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { SpacingPaper } from "../components/atoms"
55
import { HeaderArticleContainer } from "../components/organisms"
66
import { Layout } from "../components/templates"
77
import { Page } from "../constants"
8-
import { IPagePayload, PageActions } from "../store/actions"
8+
import { IPagePayload, PageActions } from "../store/page"
99

1010
const useStyles = makeStyles((theme: Theme) =>
1111
createStyles({

pages/redux.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { SpacingPaper } from "../components/atoms"
1212
import { HeaderArticleContainer } from "../components/organisms"
1313
import { Layout } from "../components/templates"
1414
import { Page } from "../constants"
15-
import { CounterActions, IPagePayload, PageActions } from "../store/actions"
16-
import { IInitialState } from "../store/states"
15+
import { CounterActions, countSelector } from "../store/counter"
16+
import { IPagePayload, PageActions } from "../store/page"
1717

1818
const useStyles = makeStyles((theme: Theme) =>
1919
createStyles({
@@ -29,8 +29,6 @@ const useStyles = makeStyles((theme: Theme) =>
2929
})
3030
)
3131

32-
const countSelector = (state: IInitialState) => state.counter.count
33-
3432
function Redux() {
3533
const classes = useStyles({})
3634
const dispatch = useDispatch()

store/actions/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ export interface ICounterPayload {
77
}
88

99
export const CounterActions = {
10-
// no arguments
1110
increment: actionCreator("increment"),
1211
decrement: actionCreator("decrement"),
13-
// with arguments
1412
calculate: actionCreator<ICounterPayload>("calculate"),
1513
}

store/counter/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./actions"
2+
export * from "./selectors"
3+
export * from "./states"

store/counter/reducers.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import produce from "immer"
2+
import { reducerWithInitialState } from "typescript-fsa-reducers"
3+
import {
4+
CounterActions,
5+
CounterInitialState,
6+
ICounterPayload,
7+
ICounterState,
8+
} from "."
9+
10+
export default reducerWithInitialState(CounterInitialState)
11+
.case(
12+
CounterActions.increment,
13+
(state: Readonly<ICounterState>): ICounterState => {
14+
return produce(state, (draft: ICounterState) => {
15+
draft.count = state.count + 1
16+
})
17+
}
18+
)
19+
.case(
20+
CounterActions.decrement,
21+
(state: Readonly<ICounterState>): ICounterState => {
22+
return produce(state, (draft: ICounterState) => {
23+
draft.count = state.count - 1
24+
})
25+
}
26+
)
27+
.case(
28+
CounterActions.calculate,
29+
(
30+
state: Readonly<ICounterState>,
31+
payload: ICounterPayload
32+
): ICounterState => {
33+
const { inputNumber } = payload
34+
return produce(state, (draft: ICounterState) => {
35+
draft.count = state.count + inputNumber
36+
})
37+
}
38+
)

0 commit comments

Comments
 (0)