./src/
actions/index.js
reducers/index.js
./src/ducks/
ui/
index.js
data/
items.js
itemsIds.js
index.js
index.js
- create file
src/ducks/index.js
- add there
import * as ui from './ui';
- create file
src/ducks/ui/index.js
- start with namespace
ui-duck
(we will rename it later) - define its shape with prop-types
- define defaultState
- add root selector and selectors for
isDarkTheme
anditemsToShow
- checkpoint
- add two action types
- add two action creators
- add reducer to handle both action types
- dont forget to separate
rawReducer
and namespacedreducer
- in
src/reducers/index.js
exportuiReducer
anddataReducer
- in
src/index.js
import it instead ofrootReducer
- define local
rootReducer
and combineuiReducer
anddataReducer
- does everything work?
import * as ducks from './ducks'
- spread
ducks.ui.reducer
intorootReducer
- did state change?
- if you click
toggleTheme
button does bothui
andui-duck
state change?
- in
src/components/page/index.js
import * as ducks from '../ducks'
- change
mapStateToProps
to utiliseducks.ui.selectors
to selectisDarkTheme
- does toggling theme still work?
- in
src/components/header/index.js
import * as ducks from '../ducks'
- change
mapDispatchToProps
to utiliseducks.ui.actions
- does toggling theme still work?
- in
/src/components/page-news-list/index.js
import * as ducks from '../ducks'
- change
mapStateToProps
to utiliseducks.ui.selectors
to selectitemsToShow
- does
itemsToShow
still being taken care of?
- remove old
uiReducer
from therootReducer
- rename namespace in ui duck from
ui-test
toui
- state should return to
{ ui: {}, data: {} }
- create
src/ducks/data/itemsIds.js
- start with namespace
itemsIds
- define its shape with prop-types
- define defaultState
- add root selector and selectors for
ids
,isLoading
anderror
- checkpoint
- add three action types
- add 4 action creators
- add reducer to handle all action types
- dont forget to separate
rawReducer
and namespacedreducer
- create
src/ducks/data/items.js
- start with namespace
items
- define its shape with prop-types
- define defaultState
- add root selector and selectors for
rootItem
,item
,isLoading
anderror
,error
- checkpoint
- add three action types
- add 4 action creators
- add reducer to handle all action types
- dont forget to separate
rawReducer
and namespacedreducer
- create file
src/utils/ducks.js
and updatesrc/utils/index.js
according to the slide #25 - create file
src/ducks/data/index.js
and combineitems
anditemsIds
subducks as stated in a slide #26 - have a temporary namespace
data-duck
(we will change it later)
- in
src/index.js
- spread
ducks.data.reducer
intorootReducer
- did state change?
- if you open
/
route does bothdata
anddata-duck
state change? - if you open
/item/17252585
route does bothdata
anddata-duck
state change?
- in
src/components/news-item/index.js
import * as ducks from '../../ducks'
- change
mapStateToProps
to utilise relevant selector fromducks.data.items.selectors
- change
mapDispatchToProps
to utilise relevant action fromducks.data.items.actions
- in
src/components/page-news-list/index.js
import * as ducks from '../../ducks'
- change
mapStateToProps
to utilise relevant selector fromducks.data.itemsIds.selectors
- change
mapDispatchToProps
to utilise relevant action fromducks.data.itemsIds.actions
- remove old
dataReducer
from therootReducer
- rename namespace in data duck from
data-duck
todata
- state should return to
{ ui: {}, data: {} }
- remove all imports of standalone
actions
andreducers
files. - remove files itself
- does it still work?