This repository was archived by the owner on Dec 9, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +35
-27
lines changed
Expand file tree Collapse file tree 4 files changed +35
-27
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export default (history) => {
99 error : ErrorReducer . reducer ,
1010 requesting : RequestingReducer . reducer ,
1111 router : connectRouter ( history ) ,
12- shows : ShowsReducer . reducer ,
12+ shows : new ShowsReducer ( ) . reducer ,
1313 } ;
1414
1515 return combineReducers ( reducerMap ) ;
Original file line number Diff line number Diff line change 11import ShowsAction from './ShowsAction' ;
2+ import BaseReducer from '../../utilities/BaseReducer' ;
23
3- export default class ShowsReducer {
4- static initialState = {
4+ export default class ShowsReducer extends BaseReducer {
5+ initialState = {
56 currentShowId : '74' ,
67 show : null ,
78 episodes : [ ] ,
89 actors : [ ] ,
910 } ;
1011
11- static reducer ( state = ShowsReducer . initialState , action ) {
12- if ( action . error ) {
13- return state ;
14- }
12+ [ ShowsAction . REQUEST_SHOW_FINISHED ] ( state , action ) {
13+ return {
14+ ...state ,
15+ show : action . payload ,
16+ } ;
17+ }
18+
19+ [ ShowsAction . REQUEST_EPISODES_FINISHED ] ( state , action ) {
20+ return {
21+ ...state ,
22+ episodes : action . payload ,
23+ } ;
24+ }
1525
16- switch ( action . type ) {
17- case ShowsAction . REQUEST_SHOW_FINISHED :
18- return {
19- ...state ,
20- show : action . payload ,
21- } ;
22- case ShowsAction . REQUEST_EPISODES_FINISHED :
23- return {
24- ...state ,
25- episodes : action . payload ,
26- } ;
27- case ShowsAction . REQUEST_CAST_FINISHED :
28- return {
29- ...state ,
30- actors : action . payload ,
31- } ;
32- default :
33- return state ;
34- }
26+ [ ShowsAction . REQUEST_CAST_FINISHED ] ( state , action ) {
27+ return {
28+ ...state ,
29+ actors : action . payload ,
30+ } ;
3531 }
3632}
Original file line number Diff line number Diff line change 1+ export default class BaseReducer {
2+ initialState = { } ;
3+
4+ reducer = ( state = this . initialState , action ) => {
5+ if ( action . error || ! this [ action . type ] ) {
6+ return state ;
7+ }
8+
9+ return this [ action . type ] ( state , action ) ;
10+ } ;
11+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { ConnectedRouter } from 'connected-react-router';
33import { Route , Switch } from 'react-router-dom' ;
44import RouteEnum from '../constants/RouteEnum' ;
55import MainNav from './components/main-nav/MainNav' ;
6+ import LoadingIndicator from './components/loading-indicator/LoadingIndicator' ;
67
78const HomePage = lazy ( ( ) => import ( './home-page/HomePage' ) ) ;
89const NotFoundPage = lazy ( ( ) => import ( './not-found-page/NotFoundPage' ) ) ;
@@ -12,7 +13,7 @@ export default class App extends React.Component {
1213 render ( ) {
1314 return (
1415 < ConnectedRouter history = { this . props . history } >
15- < Suspense fallback = { < div > Loading... </ div > } >
16+ < Suspense fallback = { < LoadingIndicator isActive = { true } / >} >
1617 < MainNav />
1718 < Switch >
1819 < Route exact = { true } path = { RouteEnum . Home } component = { HomePage } />
You can’t perform that action at this time.
0 commit comments