sort.js (1233B)
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 5 "use strict"; 6 7 const { 8 SORT_BY, 9 RESET_COLUMNS, 10 } = require("resource://devtools/client/netmonitor/src/constants.js"); 11 12 function Sort() { 13 return { 14 // null means: sort by "waterfall", but don't highlight the table header 15 type: null, 16 ascending: true, 17 }; 18 } 19 20 function sortReducer(state = new Sort(), action) { 21 switch (action.type) { 22 case SORT_BY: { 23 if (action.sortType != null && action.sortType == state.type) { 24 return { 25 ...state, 26 ascending: !state.ascending, 27 }; 28 } 29 if (state.type == action.sortType && state.ascending) { 30 return state; 31 } 32 return { 33 ...state, 34 type: action.sortType, 35 ascending: true, 36 }; 37 } 38 39 case RESET_COLUMNS: { 40 if (state.type == null && state.ascending === true) { 41 return state; 42 } 43 return { 44 ...state, 45 type: null, 46 ascending: true, 47 }; 48 } 49 50 default: 51 return state; 52 } 53 } 54 55 module.exports = { 56 Sort, 57 sortReducer, 58 };