Skip to content

Commit bbf7c65

Browse files
authored
Store: Remove simple createReducer usage (#36745)
* Remove createReducer from local-pickup * Remove createReducer from flat-rate * Remove createReducer from shipping-classes * Remove createReducer from free-shipping * Wrap with withoutPersistence
1 parent 93cdbe8 commit bbf7c65

File tree

4 files changed

+58
-73
lines changed

4 files changed

+58
-73
lines changed
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
/** @format */
2-
31
/**
42
* Internal dependencies
53
*/
6-
import { createReducer } from 'state/utils';
4+
import { withoutPersistence } from 'state/utils';
75
import {
86
WOOCOMMERCE_SHIPPING_CLASSES_REQUEST,
97
WOOCOMMERCE_SHIPPING_CLASSES_REQUEST_SUCCESS,
108
} from 'woocommerce/state/action-types';
119
import { LOADING } from 'woocommerce/state/constants';
1210

13-
const reducers = {};
14-
15-
reducers[ WOOCOMMERCE_SHIPPING_CLASSES_REQUEST ] = () => {
16-
return LOADING;
17-
};
18-
19-
reducers[ WOOCOMMERCE_SHIPPING_CLASSES_REQUEST_SUCCESS ] = ( state, { data } ) => {
20-
return data;
21-
};
22-
23-
export default createReducer( {}, reducers );
11+
export default withoutPersistence( function( state = {}, action ) {
12+
switch ( action.type ) {
13+
case WOOCOMMERCE_SHIPPING_CLASSES_REQUEST:
14+
return LOADING;
15+
case WOOCOMMERCE_SHIPPING_CLASSES_REQUEST_SUCCESS:
16+
return action.data;
17+
}
18+
return state;
19+
} );
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/** @format */
2-
31
/**
42
* Internal dependencies
53
*/
6-
7-
import { createReducer } from 'state/utils';
4+
import { withoutPersistence } from 'state/utils';
85
import {
96
WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_TAXABLE,
107
WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_COST,
@@ -15,20 +12,20 @@ const initialState = {
1512
cost: 5,
1613
};
1714

18-
const reducer = {};
15+
export default withoutPersistence( function( state = initialState, action ) {
16+
switch ( action.type ) {
17+
case WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_TAXABLE:
18+
return {
19+
...state,
20+
tax_status: action.isTaxable ? 'taxable' : 'none',
21+
};
1922

20-
reducer[ WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_TAXABLE ] = ( state, { isTaxable } ) => {
21-
return {
22-
...state,
23-
tax_status: isTaxable ? 'taxable' : 'none',
24-
};
25-
};
26-
27-
reducer[ WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_COST ] = ( state, { cost } ) => {
28-
return {
29-
...state,
30-
cost,
31-
};
32-
};
23+
case WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_COST:
24+
return {
25+
...state,
26+
cost: action.cost,
27+
};
28+
}
3329

34-
export default createReducer( initialState, reducer );
30+
return state;
31+
} );
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/** @format */
2-
31
/**
42
* Internal dependencies
53
*/
6-
7-
import { createReducer } from 'state/utils';
4+
import { withoutPersistence } from 'state/utils';
85
import {
96
WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_CONDITION,
107
WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_MIN_COST,
@@ -15,20 +12,19 @@ const initialState = {
1512
min_amount: 0,
1613
};
1714

18-
const reducer = {};
19-
20-
reducer[ WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_CONDITION ] = ( state, { condition } ) => {
21-
return {
22-
...state,
23-
requires: condition,
24-
};
25-
};
26-
27-
reducer[ WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_MIN_COST ] = ( state, { cost } ) => {
28-
return {
29-
...state,
30-
min_amount: cost,
31-
};
32-
};
15+
export default withoutPersistence( function( state = initialState, action ) {
16+
switch ( action.type ) {
17+
case WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_CONDITION:
18+
return {
19+
...state,
20+
requires: action.condition,
21+
};
3322

34-
export default createReducer( initialState, reducer );
23+
case WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_MIN_COST:
24+
return {
25+
...state,
26+
min_amount: action.cost,
27+
};
28+
}
29+
return state;
30+
} );
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
/** @format */
2-
31
/**
42
* Internal dependencies
53
*/
6-
7-
import { createReducer } from 'state/utils';
4+
import { withoutPersistence } from 'state/utils';
85
import {
96
WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_TAXABLE,
107
WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_COST,
@@ -15,20 +12,19 @@ const initialState = {
1512
cost: 0,
1613
};
1714

18-
const reducer = {};
19-
20-
reducer[ WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_TAXABLE ] = ( state, { isTaxable } ) => {
21-
return {
22-
...state,
23-
tax_status: isTaxable ? 'taxable' : 'none',
24-
};
25-
};
26-
27-
reducer[ WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_COST ] = ( state, { cost } ) => {
28-
return {
29-
...state,
30-
cost,
31-
};
32-
};
15+
export default withoutPersistence( function( state = initialState, action ) {
16+
switch ( action.type ) {
17+
case WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_TAXABLE:
18+
return {
19+
...state,
20+
tax_status: action.isTaxable ? 'taxable' : 'none',
21+
};
3322

34-
export default createReducer( initialState, reducer );
23+
case WOOCOMMERCE_SHIPPING_ZONE_METHOD_SET_COST:
24+
return {
25+
...state,
26+
cost: action.cost,
27+
};
28+
}
29+
return state;
30+
} );

0 commit comments

Comments
 (0)