filters.js (1031B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 const constants = require("resource://devtools/client/webconsole/constants.js"); 7 8 const FilterState = overrides => 9 Object.freeze(cloneState(constants.DEFAULT_FILTERS_VALUES, overrides)); 10 11 function filters(state = FilterState(), action) { 12 switch (action.type) { 13 case constants.FILTER_TOGGLE: { 14 const { filter } = action; 15 const active = !state[filter]; 16 return cloneState(state, { [filter]: active }); 17 } 18 case constants.FILTERS_CLEAR: 19 return FilterState(); 20 case constants.FILTER_TEXT_SET: { 21 const { text } = action; 22 return cloneState(state, { [constants.FILTERS.TEXT]: text }); 23 } 24 } 25 26 return state; 27 } 28 29 function cloneState(state, overrides) { 30 return Object.assign({}, state, overrides); 31 } 32 33 exports.FilterState = FilterState; 34 exports.filters = filters;