tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

message-cache-clearing.js (1358B)


      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  MESSAGES_CLEAR,
      9 } = require("resource://devtools/client/webconsole/constants.js");
     10 
     11 /**
     12 * This enhancer is responsible for clearing the messages caches using the
     13 * webconsoleFront when the user clear the messages (either by direct UI action, or via
     14 * `console.clear()`).
     15 */
     16 function enableMessagesCacheClearing(webConsoleUI) {
     17  return next => (reducer, initialState, enhancer) => {
     18    function messagesCacheClearingEnhancer(state, action) {
     19      const storeHadMessages =
     20        state?.messages?.mutableMessagesById &&
     21        state.messages.mutableMessagesById.size > 0;
     22      state = reducer(state, action);
     23 
     24      if (storeHadMessages && webConsoleUI && action.type === MESSAGES_CLEAR) {
     25        webConsoleUI.clearMessagesCache();
     26 
     27        // cleans up all the network data provider internal state
     28        webConsoleUI.networkDataProvider?.destroy();
     29 
     30        if (webConsoleUI.hud?.toolbox) {
     31          webConsoleUI.hud.toolbox.setErrorCount(0);
     32        }
     33      }
     34      return state;
     35    }
     36 
     37    return next(messagesCacheClearingEnhancer, initialState, enhancer);
     38  };
     39 }
     40 
     41 module.exports = enableMessagesCacheClearing;