All files / src/store rootReducer.ts

0% Statements 0/29
0% Branches 0/8
0% Functions 0/2
0% Lines 0/29

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                                                                                                                                             
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 { TRACKER_REDO, TRACKER_UNDO } from "consts";
 
let lastEntityUndoStateTime = 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: ["@@TRACKER_INIT"],
    filter: (action, _currentState, _previousHistory) => {
      return (
        action.type.startsWith("tracker/loadSong/fulfilled") ||
        action.type.startsWith("tracker/edit") ||
        action.type.startsWith("tracker/transpose") ||
        action.type.startsWith("tracker/addSequence") ||
        action.type.startsWith("tracker/removeSequence")
      );
    },
    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;
      Iif (shouldStoreUndo) {
        lastEntityUndoStateTime = Date.now();
      }
      return shouldStoreUndo;
    },
    initTypes: ["@@redux/INIT", "@@INIT"],
  }),
  error,
  assets,
});
 
export default rootReducer;