tor-browser

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

batching.js (816B)


      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  BATCH_ACTIONS,
      9 } = require("resource://devtools/client/netmonitor/src/constants.js");
     10 
     11 /**
     12 * A reducer to handle batched actions. For each action in the BATCH_ACTIONS array,
     13 * the reducer is called successively on the array of batched actions, resulting in
     14 * only one state update.
     15 */
     16 function batchingReducer(nextReducer) {
     17  return function reducer(state, action) {
     18    switch (action.type) {
     19      case BATCH_ACTIONS:
     20        return action.actions.reduce(reducer, state);
     21      default:
     22        return nextReducer(state, action);
     23    }
     24  };
     25 }
     26 
     27 module.exports = batchingReducer;