1
1
import { combineReducers , composeReducers , Action } from '@bigcommerce/data-store' ;
2
2
3
3
import { clearErrorReducer } from '../common/error' ;
4
+ import { arrayReplace , objectSet } from '../common/utility' ;
4
5
5
6
import Country from './country' ;
6
7
import { CountryActionType , LoadCountriesAction } from './country-actions' ;
@@ -25,7 +26,7 @@ function dataReducer(
25
26
) : Country [ ] | undefined {
26
27
switch ( action . type ) {
27
28
case CountryActionType . LoadCountriesSucceeded :
28
- return action . payload || [ ] ;
29
+ return arrayReplace ( data , action . payload ) ;
29
30
30
31
default :
31
32
return data ;
@@ -39,10 +40,10 @@ function errorsReducer(
39
40
switch ( action . type ) {
40
41
case CountryActionType . LoadCountriesRequested :
41
42
case CountryActionType . LoadCountriesSucceeded :
42
- return { ... errors , loadError : undefined } ;
43
+ return objectSet ( errors , ' loadError' , undefined ) ;
43
44
44
45
case CountryActionType . LoadCountriesFailed :
45
- return { ... errors , loadError : action . payload } ;
46
+ return objectSet ( errors , ' loadError' , action . payload ) ;
46
47
47
48
default :
48
49
return errors ;
@@ -55,11 +56,11 @@ function statusesReducer(
55
56
) : CountryStatusesState {
56
57
switch ( action . type ) {
57
58
case CountryActionType . LoadCountriesRequested :
58
- return { ... statuses , isLoading : true } ;
59
+ return objectSet ( statuses , ' isLoading' , true ) ;
59
60
60
61
case CountryActionType . LoadCountriesSucceeded :
61
62
case CountryActionType . LoadCountriesFailed :
62
- return { ... statuses , isLoading : false } ;
63
+ return objectSet ( statuses , ' isLoading' , false ) ;
63
64
64
65
default :
65
66
return statuses ;
0 commit comments