history.js 861 B

123456789101112131415161718192021222324
  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. const flags = require("devtools/shared/flags");
  6. /**
  7. * A middleware that stores every action coming through the store in the passed
  8. * in logging object. Should only be used for tests, as it collects all
  9. * action information, which will cause memory bloat.
  10. */
  11. exports.history = (log = []) => ({ dispatch, getState }) => {
  12. if (!flags.testing) {
  13. console.warn("Using history middleware stores all actions in state for " +
  14. "testing and devtools is not currently running in test " +
  15. "mode. Be sure this is intentional.");
  16. }
  17. return next => action => {
  18. log.push(action);
  19. next(action);
  20. };
  21. };