Skip to content

Commit e9b84b7

Browse files
authored
Merge pull request #109 from kmiyauchi/master
Performance tuning
2 parents 5784c4a + c972174 commit e9b84b7

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/util/visibilityFilter/reducer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@ var visibilityFilterReducer = exports.visibilityFilterReducer = function visibil
1111
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
1212
var action = arguments[1];
1313

14-
var _state = JSON.parse(JSON.stringify(state));
14+
var _state = void 0;
1515
switch (action.type) {
1616
case 'RESET_FILTER':
1717
return defaultState;
1818
case 'REFYDRATE_FILTER':
1919
return action.visibilityFilter;
2020
case 'CHANGE_TERM':
21+
_state = JSON.parse(JSON.stringify(state));
2122
_state.term.q = action.term;
2223
return _state;
2324
case 'TOGGLE_FILTER':
2425
{
26+
_state = JSON.parse(JSON.stringify(state));
2527
if (!_state[action.key]) return _state;
2628

2729
if (!_state[action.key][action.filter.key]) _state[action.key][action.filter.key] = [];
@@ -36,13 +38,15 @@ var visibilityFilterReducer = exports.visibilityFilterReducer = function visibil
3638
return _state;
3739
}
3840
case 'CHANGE_FILTER':
41+
_state = JSON.parse(JSON.stringify(state));
3942
if (!_state[action.key]) return _state;
4043
action.filter.forEach(function (a) {
4144
_state[action.key][a.key] = a.value;
4245
// if (!a.value || a.value.length === 0) delete _state[action.key][a.key];
4346
});
4447
return _state;
4548
case 'SELECT_PROVINCE':
49+
_state = JSON.parse(JSON.stringify(state));
4650
_state.category = { province: [action.province] };
4751
return _state;
4852
default:

src/util/visibilityFilter/reducer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
*/
44
const defaultState = { category: {}, sort: { order: 'desc' }, term: { q: '' } };
55
export const visibilityFilterReducer = (state = defaultState, action) => {
6-
const _state = JSON.parse(JSON.stringify(state));
6+
let _state;
77
switch (action.type) {
88
case 'RESET_FILTER':
99
return defaultState;
1010
case 'REFYDRATE_FILTER':
1111
return action.visibilityFilter;
1212
case 'CHANGE_TERM':
13+
_state = JSON.parse(JSON.stringify(state));
1314
_state.term.q = action.term;
1415
return _state;
1516
case 'TOGGLE_FILTER': {
17+
_state = JSON.parse(JSON.stringify(state));
1618
if (!_state[action.key]) return _state;
1719

1820
if (!_state[action.key][action.filter.key])
@@ -30,13 +32,15 @@ export const visibilityFilterReducer = (state = defaultState, action) => {
3032
return _state;
3133
}
3234
case 'CHANGE_FILTER':
35+
_state = JSON.parse(JSON.stringify(state));
3336
if (!_state[action.key]) return _state;
3437
action.filter.forEach(a => {
3538
_state[action.key][a.key] = a.value;
3639
// if (!a.value || a.value.length === 0) delete _state[action.key][a.key];
3740
});
3841
return _state;
3942
case 'SELECT_PROVINCE':
43+
_state = JSON.parse(JSON.stringify(state));
4044
_state.category = { province: [action.province] };
4145
return _state;
4246
default:

0 commit comments

Comments
 (0)