batching.js (963B)
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/shared/redux/middleware/debounce.js"); 10 11 /** 12 * A enhancer for the store to handle batched actions. 13 */ 14 function enableBatching() { 15 return next => (reducer, initialState, enhancer) => { 16 function batchingReducer(state, action) { 17 switch (action.type) { 18 case BATCH_ACTIONS: 19 return action.actions.reduce(batchingReducer, state); 20 default: 21 return reducer(state, action); 22 } 23 } 24 25 if (typeof initialState === "function" && typeof enhancer === "undefined") { 26 enhancer = initialState; 27 initialState = undefined; 28 } 29 30 return next(batchingReducer, initialState, enhancer); 31 }; 32 } 33 34 module.exports = enableBatching;