tor-browser

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

ignore.js (1328B)


      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 IGNORING = Symbol("IGNORING");
      7 const START_IGNORE_ACTION = "START_IGNORE_ACTION";
      8 
      9 /**
     10 * A middleware that prevents any action of being called once it is activated.
     11 * This is useful to apply while destroying a given panel, as it will ignore all calls
     12 * to actions, where we usually make our client -> server communications.
     13 * This middleware should be declared before any other middleware to  to effectively
     14 * ignore every actions.
     15 */
     16 function ignore({ getState }) {
     17  return next => action => {
     18    if (action.type === START_IGNORE_ACTION) {
     19      getState()[IGNORING] = true;
     20      return null;
     21    }
     22 
     23    if (getState()[IGNORING]) {
     24      // Throw to stop execution from the callsite and prevent any further code from running
     25      throw new Error(
     26        "[REDUX_MIDDLEWARE_IGNORED_REDUX_ACTION] Dispatching '" +
     27          (action.type || action) +
     28          "' action after panel's closing"
     29      );
     30    }
     31 
     32    return next(action);
     33  };
     34 }
     35 
     36 module.exports = {
     37  ignore,
     38 
     39  isIgnoringActions(state) {
     40    return state[IGNORING];
     41  },
     42 
     43  START_IGNORE_ACTION: { type: START_IGNORE_ACTION },
     44 };