All files / src/store rootReducer.ts

91.89% Statements 34/37
52.63% Branches 10/19
100% Functions 2/2
91.89% Lines 34/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 952x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 2x   2x   2x                                     10x                 10x   10x 10x                                         5x   5x 1x   5x                 2x  
import { combineReducers } from "redux";
import undoable from "redux-undo";
import console from "./features/console/consoleState";
import music from "./features/music/musicState";
import assets from "./features/assets/assetsState";
import entities from "./features/entities/entitiesState";
import document from "./features/document/documentState";
import editor from "./features/editor/editorState";
import settings from "./features/settings/settingsState";
import metadata from "./features/metadata/metadataState";
import engine from "./features/engine/engineState";
import error from "./features/error/errorState";
import navigation from "./features/navigation/navigationState";
import clipboard from "./features/clipboard/clipboardState";
import sprite from "./features/sprite/spriteState";
import scriptEventDefs from "./features/scriptEventDefs/scriptEventDefsState";
import tracker from "./features/tracker/trackerState";
import trackerDocument from "./features/trackerDocument/trackerDocumentState";
import debug from "./features/debugger/debuggerState";
import webTemplates from "./features/webTemplates/webTemplatesState";
import { TRACKER_REDO, TRACKER_UNDO } from "consts";
 
let lastEntityUndoStateTime = 0;
let lastTrackerUndoStateTime = 0;
 
const UNDO_THROTTLE = 300;
 
const rootReducer = combineReducers({
  editor,
  console,
  music,
  navigation,
  document,
  engine,
  clipboard,
  sprite,
  scriptEventDefs,
  debug,
  tracker,
  trackerDocument: undoable(trackerDocument, {
    limit: 20,
    initTypes: [
      "trackerDocument/loadSong/pending",
      "trackerDocument/unloadSong",
    ],
    filter: (action, currentState, previousHistory) => {
      Iif (
        action.type.startsWith("trackerDocument/loadSong/fulfilled") ||
        action.type.startsWith("trackerDocument/addSequence") ||
        action.type.startsWith("trackerDocument/removeSequence")
      ) {
        return true;
      }
 
      const shouldStoreUndo =
        currentState !== previousHistory.present &&
        Date.now() > lastTrackerUndoStateTime + UNDO_THROTTLE;
      Eif (!shouldStoreUndo) {
        return false;
      }
      lastTrackerUndoStateTime = Date.now();
 
      return (
        action.type.startsWith("trackerDocument/") &&
        !action.type.startsWith("trackerDocument/loadSong") &&
        !action.type.startsWith("trackerDocument/saveSong") &&
        !action.type.startsWith("trackerDocument/addNewSong") &&
        !action.type.startsWith("trackerDocument/requestAddNewSong") &&
        !action.type.startsWith("trackerDocument/setSongFilename")
      );
    },
    ignoreInitialState: true,
    undoType: TRACKER_UNDO,
    redoType: TRACKER_REDO,
  }),
  project: undoable(combineReducers({ entities, settings, metadata }), {
    limit: 20,
    filter: (_action, currentState, previousHistory) => {
      const shouldStoreUndo =
        currentState !== previousHistory.present &&
        Date.now() > lastEntityUndoStateTime + UNDO_THROTTLE;
      if (shouldStoreUndo) {
        lastEntityUndoStateTime = Date.now();
      }
      return shouldStoreUndo;
    },
    initTypes: ["@@redux/INIT", "@@INIT"],
  }),
  error,
  assets,
  webTemplates,
});
 
export default rootReducer;