simple-console-logger.js (972B)
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 const { XPCOMUtils } = ChromeUtils.importESModule( 7 "resource://gre/modules/XPCOMUtils.sys.mjs" 8 ); 9 const { 10 PREFERENCES, 11 } = require("resource://devtools/client/aboutdebugging/src/constants.js"); 12 13 const lazy = {}; 14 XPCOMUtils.defineLazyPreferenceGetter( 15 lazy, 16 "shouldLog", 17 PREFERENCES.SHOW_REDUX_ACTIONS, 18 false 19 ); 20 21 const simpleConsoleLogger = store => next => action => { 22 if (!lazy.shouldLog) { 23 return next(action); 24 } 25 26 console.group(`Action: ${action.type}`); 27 console.log("Previous state:", store.getState()); 28 console.log("Dispatched action:", action); 29 30 const result = next(action); 31 32 console.log("Next state:", store.getState()); 33 console.groupEnd(); 34 35 return result; 36 }; 37 38 exports.simpleConsoleLogger = simpleConsoleLogger;