File tree 4 files changed +37
-27
lines changed 4 files changed +37
-27
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export default (history) => {
9
9
error : ErrorReducer . reducer ,
10
10
requesting : RequestingReducer . reducer ,
11
11
router : connectRouter ( history ) ,
12
- shows : ShowsReducer . reducer ,
12
+ shows : new ShowsReducer ( ) . reducer ,
13
13
} ;
14
14
15
15
return combineReducers ( reducerMap ) ;
Original file line number Diff line number Diff line change 1
1
import ShowsAction from './ShowsAction' ;
2
+ import BaseReducer from '../../utilities/BaseReducer' ;
2
3
3
- export default class ShowsReducer {
4
- static initialState = {
4
+ export default class ShowsReducer extends BaseReducer {
5
+ initialState = {
5
6
currentShowId : '74' ,
6
7
show : null ,
7
8
episodes : [ ] ,
8
9
actors : [ ] ,
9
10
} ;
10
11
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
+ }
15
25
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
+ } ;
35
31
}
36
32
}
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
+ const handler = this [ action . type ] ;
6
+
7
+ if ( ! handler || action . error ) {
8
+ return state ;
9
+ }
10
+
11
+ return handler ( state , action ) ;
12
+ } ;
13
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { ConnectedRouter } from 'connected-react-router';
3
3
import { Route , Switch } from 'react-router-dom' ;
4
4
import RouteEnum from '../constants/RouteEnum' ;
5
5
import MainNav from './components/main-nav/MainNav' ;
6
+ import LoadingIndicator from './components/loading-indicator/LoadingIndicator' ;
6
7
7
8
const HomePage = lazy ( ( ) => import ( './home-page/HomePage' ) ) ;
8
9
const NotFoundPage = lazy ( ( ) => import ( './not-found-page/NotFoundPage' ) ) ;
@@ -12,7 +13,7 @@ export default class App extends React.Component {
12
13
render ( ) {
13
14
return (
14
15
< ConnectedRouter history = { this . props . history } >
15
- < Suspense fallback = { < div > Loading... </ div > } >
16
+ < Suspense fallback = { < LoadingIndicator isActive = { true } / >} >
16
17
< MainNav />
17
18
< Switch >
18
19
< Route exact = { true } path = { RouteEnum . Home } component = { HomePage } />
You can’t perform that action at this time.
0 commit comments