refactor(ui): refactor reducer list

Instead of manually naming reducers, use each slice's `name` property. Makes typos impossible.
This commit is contained in:
psychedelicious 2024-02-03 20:30:18 +11:00 committed by Kent Keirsey
parent c1300fa8b1
commit d713620d9e
20 changed files with 48 additions and 84 deletions

View File

@ -3,27 +3,28 @@ import { autoBatchEnhancer, combineReducers, configureStore } from '@reduxjs/too
import { logger } from 'app/logging/logger';
import { idbKeyValDriver } from 'app/store/enhancers/reduxRemember/driver';
import { errorHandler } from 'app/store/enhancers/reduxRemember/errors';
import canvasReducer, { canvasPersistConfig } from 'features/canvas/store/canvasSlice';
import changeBoardModalReducer from 'features/changeBoardModal/store/slice';
import controlAdaptersReducer, {
import { canvasPersistConfig, canvasSlice } from 'features/canvas/store/canvasSlice';
import { changeBoardModalSlice } from 'features/changeBoardModal/store/slice';
import {
controlAdaptersPersistConfig,
controlAdaptersSlice,
} from 'features/controlAdapters/store/controlAdaptersSlice';
import deleteImageModalReducer from 'features/deleteImageModal/store/slice';
import dynamicPromptsReducer, { dynamicPromptsPersistConfig } from 'features/dynamicPrompts/store/dynamicPromptsSlice';
import galleryReducer, { galleryPersistConfig } from 'features/gallery/store/gallerySlice';
import hrfReducer, { hrfPersistConfig } from 'features/hrf/store/hrfSlice';
import loraReducer, { loraPersistConfig } from 'features/lora/store/loraSlice';
import modelmanagerReducer, { modelManagerPersistConfig } from 'features/modelManager/store/modelManagerSlice';
import nodesReducer, { nodesPersistConfig } from 'features/nodes/store/nodesSlice';
import nodeTemplatesReducer from 'features/nodes/store/nodeTemplatesSlice';
import workflowReducer, { workflowPersistConfig } from 'features/nodes/store/workflowSlice';
import generationReducer, { generationPersistConfig } from 'features/parameters/store/generationSlice';
import postprocessingReducer, { postprocessingPersistConfig } from 'features/parameters/store/postprocessingSlice';
import queueReducer from 'features/queue/store/queueSlice';
import sdxlReducer, { sdxlPersistConfig } from 'features/sdxl/store/sdxlSlice';
import configReducer from 'features/system/store/configSlice';
import systemReducer, { systemPersistConfig } from 'features/system/store/systemSlice';
import uiReducer, { uiPersistConfig } from 'features/ui/store/uiSlice';
import { deleteImageModalSlice } from 'features/deleteImageModal/store/slice';
import { dynamicPromptsPersistConfig, dynamicPromptsSlice } from 'features/dynamicPrompts/store/dynamicPromptsSlice';
import { galleryPersistConfig, gallerySlice } from 'features/gallery/store/gallerySlice';
import { hrfPersistConfig, hrfSlice } from 'features/hrf/store/hrfSlice';
import { loraPersistConfig, loraSlice } from 'features/lora/store/loraSlice';
import { modelManagerPersistConfig, modelManagerSlice } from 'features/modelManager/store/modelManagerSlice';
import { nodesPersistConfig, nodesSlice } from 'features/nodes/store/nodesSlice';
import { nodesTemplatesSlice } from 'features/nodes/store/nodeTemplatesSlice';
import { workflowPersistConfig, workflowSlice } from 'features/nodes/store/workflowSlice';
import { generationPersistConfig, generationSlice } from 'features/parameters/store/generationSlice';
import { postprocessingPersistConfig, postprocessingSlice } from 'features/parameters/store/postprocessingSlice';
import { queueSlice } from 'features/queue/store/queueSlice';
import { sdxlPersistConfig, sdxlSlice } from 'features/sdxl/store/sdxlSlice';
import { configSlice } from 'features/system/store/configSlice';
import { systemPersistConfig, systemSlice } from 'features/system/store/systemSlice';
import { uiPersistConfig, uiSlice } from 'features/ui/store/uiSlice';
import { diff } from 'jsondiffpatch';
import { defaultsDeep, keys, omit, pick } from 'lodash-es';
import dynamicMiddlewares from 'redux-dynamic-middlewares';
@ -39,26 +40,27 @@ import { actionSanitizer } from './middleware/devtools/actionSanitizer';
import { actionsDenylist } from './middleware/devtools/actionsDenylist';
import { stateSanitizer } from './middleware/devtools/stateSanitizer';
import { listenerMiddleware } from './middleware/listenerMiddleware';
const allReducers = {
canvas: canvasReducer,
gallery: galleryReducer,
generation: generationReducer,
nodes: nodesReducer,
nodeTemplates: nodeTemplatesReducer,
postprocessing: postprocessingReducer,
system: systemReducer,
config: configReducer,
ui: uiReducer,
controlAdapters: controlAdaptersReducer,
dynamicPrompts: dynamicPromptsReducer,
deleteImageModal: deleteImageModalReducer,
changeBoardModal: changeBoardModalReducer,
lora: loraReducer,
modelmanager: modelmanagerReducer,
sdxl: sdxlReducer,
queue: queueReducer,
workflow: workflowReducer,
hrf: hrfReducer,
[canvasSlice.name]: canvasSlice.reducer,
[gallerySlice.name]: gallerySlice.reducer,
[generationSlice.name]: generationSlice.reducer,
[nodesSlice.name]: nodesSlice.reducer,
[nodesTemplatesSlice.name]: nodesTemplatesSlice.reducer,
[postprocessingSlice.name]: postprocessingSlice.reducer,
[systemSlice.name]: systemSlice.reducer,
[configSlice.name]: configSlice.reducer,
[uiSlice.name]: uiSlice.reducer,
[controlAdaptersSlice.name]: controlAdaptersSlice.reducer,
[dynamicPromptsSlice.name]: dynamicPromptsSlice.reducer,
[deleteImageModalSlice.name]: deleteImageModalSlice.reducer,
[changeBoardModalSlice.name]: changeBoardModalSlice.reducer,
[loraSlice.name]: loraSlice.reducer,
[modelManagerSlice.name]: modelManagerSlice.reducer,
[sdxlSlice.name]: sdxlSlice.reducer,
[queueSlice.name]: queueSlice.reducer,
[workflowSlice.name]: workflowSlice.reducer,
[hrfSlice.name]: hrfSlice.reducer,
[api.reducerPath]: api.reducer,
};

View File

@ -719,8 +719,6 @@ export const {
scaledBoundingBoxDimensionsReset,
} = canvasSlice.actions;
export default canvasSlice.reducer;
export const selectCanvasSlice = (state: RootState) => state.canvas;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -5,7 +5,7 @@ import type { ImageDTO } from 'services/api/types';
import { initialState } from './initialState';
const changeBoardModal = createSlice({
export const changeBoardModalSlice = createSlice({
name: 'changeBoardModal',
initialState,
reducers: {
@ -22,8 +22,6 @@ const changeBoardModal = createSlice({
},
});
export const { isModalOpenChanged, imagesToChangeSelected, changeBoardReset } = changeBoardModal.actions;
export default changeBoardModal.reducer;
export const { isModalOpenChanged, imagesToChangeSelected, changeBoardReset } = changeBoardModalSlice.actions;
export const selectChangeBoardModalSlice = (state: RootState) => state.changeBoardModal;

View File

@ -424,8 +424,6 @@ export const {
controlAdapterModelCleared,
} = controlAdaptersSlice.actions;
export default controlAdaptersSlice.reducer;
export const isAnyControlAdapterAdded = isAnyOf(
controlAdapterAdded,
controlAdapterAddedFromImage,

View File

@ -5,7 +5,7 @@ import type { ImageDTO } from 'services/api/types';
import { initialDeleteImageState } from './initialState';
const deleteImageModal = createSlice({
export const deleteImageModalSlice = createSlice({
name: 'deleteImageModal',
initialState: initialDeleteImageState,
reducers: {
@ -22,8 +22,6 @@ const deleteImageModal = createSlice({
},
});
export const { isModalOpenChanged, imagesToDeleteSelected, imageDeletionCanceled } = deleteImageModal.actions;
export default deleteImageModal.reducer;
export const { isModalOpenChanged, imagesToDeleteSelected, imageDeletionCanceled } = deleteImageModalSlice.actions;
export const selectDeleteImageModalSlice = (state: RootState) => state.deleteImageModal;

View File

@ -74,8 +74,6 @@ export const {
seedBehaviourChanged,
} = dynamicPromptsSlice.actions;
export default dynamicPromptsSlice.reducer;
export const selectDynamicPromptsSlice = (state: RootState) => state.dynamicPrompts;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -109,8 +109,6 @@ export const {
moreImagesLoaded,
} = gallerySlice.actions;
export default gallerySlice.reducer;
const isAnyBoardDeleted = isAnyOf(
imagesApi.endpoints.deleteBoard.matchFulfilled,
imagesApi.endpoints.deleteBoardAndImages.matchFulfilled

View File

@ -37,8 +37,6 @@ export const hrfSlice = createSlice({
export const { setHrfEnabled, setHrfStrength, setHrfMethod } = hrfSlice.actions;
export default hrfSlice.reducer;
export const selectHrfSlice = (state: RootState) => state.hrf;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -81,8 +81,6 @@ export const {
loraRecalled,
} = loraSlice.actions;
export default loraSlice.reducer;
export const selectLoraSlice = (state: RootState) => state.lora;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -29,8 +29,6 @@ export const modelManagerSlice = createSlice({
export const { setSearchFolder, setAdvancedAddScanModel } = modelManagerSlice.actions;
export default modelManagerSlice.reducer;
export const selectModelManagerSlice = (state: RootState) => state.modelmanager;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -9,7 +9,7 @@ export const initialNodeTemplatesState: NodeTemplatesState = {
templates: {},
};
const nodesTemplatesSlice = createSlice({
export const nodesTemplatesSlice = createSlice({
name: 'nodeTemplates',
initialState: initialNodeTemplatesState,
reducers: {
@ -21,6 +21,4 @@ const nodesTemplatesSlice = createSlice({
export const { nodeTemplatesBuilt } = nodesTemplatesSlice.actions;
export default nodesTemplatesSlice.reducer;
export const selectNodeTemplatesSlice = (state: RootState) => state.nodeTemplates;

View File

@ -139,7 +139,7 @@ const fieldValueReducer = <T extends FieldValue>(
input.value = result.data;
};
const nodesSlice = createSlice({
export const nodesSlice = createSlice({
name: 'nodes',
initialState: initialNodesState,
reducers: {
@ -852,8 +852,6 @@ export const isAnyNodeOrEdgeMutation = isAnyOf(
edgeAdded
);
export default nodesSlice.reducer;
export const selectNodesSlice = (state: RootState) => state.nodes;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -27,7 +27,7 @@ export const initialWorkflowState: WorkflowState = {
...blankWorkflow,
};
const workflowSlice = createSlice({
export const workflowSlice = createSlice({
name: 'workflow',
initialState: initialWorkflowState,
reducers: {
@ -119,8 +119,6 @@ export const {
workflowSaved,
} = workflowSlice.actions;
export default workflowSlice.reducer;
export const selectWorkflowSlice = (state: RootState) => state.workflow;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -299,8 +299,6 @@ export const {
export const { selectOptimalDimension } = generationSlice.selectors;
export default generationSlice.reducer;
export const selectGenerationSlice = (state: RootState) => state.generation;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -35,8 +35,6 @@ export const postprocessingSlice = createSlice({
export const { esrganModelNameChanged } = postprocessingSlice.actions;
export default postprocessingSlice.reducer;
export const selectPostprocessingSlice = (state: RootState) => state.postprocessing;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -53,6 +53,4 @@ export const {
resumeProcessorOnEnqueueChanged,
} = queueSlice.actions;
export default queueSlice.reducer;
export const selectQueueSlice = (state: RootState) => state.queue;

View File

@ -36,7 +36,7 @@ export const initialSDXLState: SDXLState = {
refinerStart: 0.8,
};
const sdxlSlice = createSlice({
export const sdxlSlice = createSlice({
name: 'sdxl',
initialState: initialSDXLState,
reducers: {
@ -86,8 +86,6 @@ export const {
setRefinerStart,
} = sdxlSlice.actions;
export default sdxlSlice.reducer;
export const selectSdxlSlice = (state: RootState) => state.sdxl;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */

View File

@ -177,6 +177,4 @@ export const configSlice = createSlice({
export const { configChanged } = configSlice.actions;
export default configSlice.reducer;
export const selectConfigSlice = (state: RootState) => state.config;

View File

@ -194,8 +194,6 @@ export const {
setShouldEnableInformationalPopovers,
} = systemSlice.actions;
export default systemSlice.reducer;
const isAnyServerError = isAnyOf(socketInvocationError, socketSessionRetrievalError, socketInvocationRetrievalError);
export const selectSystemSlice = (state: RootState) => state.system;

View File

@ -57,8 +57,6 @@ export const {
expanderStateChanged,
} = uiSlice.actions;
export default uiSlice.reducer;
export const selectUiSlice = (state: RootState) => state.ui;
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */