mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
refactor(ui): refactor reducer list
Instead of manually naming reducers, use each slice's `name` property. Makes typos impossible.
This commit is contained in:
parent
c1300fa8b1
commit
d713620d9e
@ -3,27 +3,28 @@ import { autoBatchEnhancer, combineReducers, configureStore } from '@reduxjs/too
|
|||||||
import { logger } from 'app/logging/logger';
|
import { logger } from 'app/logging/logger';
|
||||||
import { idbKeyValDriver } from 'app/store/enhancers/reduxRemember/driver';
|
import { idbKeyValDriver } from 'app/store/enhancers/reduxRemember/driver';
|
||||||
import { errorHandler } from 'app/store/enhancers/reduxRemember/errors';
|
import { errorHandler } from 'app/store/enhancers/reduxRemember/errors';
|
||||||
import canvasReducer, { canvasPersistConfig } from 'features/canvas/store/canvasSlice';
|
import { canvasPersistConfig, canvasSlice } from 'features/canvas/store/canvasSlice';
|
||||||
import changeBoardModalReducer from 'features/changeBoardModal/store/slice';
|
import { changeBoardModalSlice } from 'features/changeBoardModal/store/slice';
|
||||||
import controlAdaptersReducer, {
|
import {
|
||||||
controlAdaptersPersistConfig,
|
controlAdaptersPersistConfig,
|
||||||
|
controlAdaptersSlice,
|
||||||
} from 'features/controlAdapters/store/controlAdaptersSlice';
|
} from 'features/controlAdapters/store/controlAdaptersSlice';
|
||||||
import deleteImageModalReducer from 'features/deleteImageModal/store/slice';
|
import { deleteImageModalSlice } from 'features/deleteImageModal/store/slice';
|
||||||
import dynamicPromptsReducer, { dynamicPromptsPersistConfig } from 'features/dynamicPrompts/store/dynamicPromptsSlice';
|
import { dynamicPromptsPersistConfig, dynamicPromptsSlice } from 'features/dynamicPrompts/store/dynamicPromptsSlice';
|
||||||
import galleryReducer, { galleryPersistConfig } from 'features/gallery/store/gallerySlice';
|
import { galleryPersistConfig, gallerySlice } from 'features/gallery/store/gallerySlice';
|
||||||
import hrfReducer, { hrfPersistConfig } from 'features/hrf/store/hrfSlice';
|
import { hrfPersistConfig, hrfSlice } from 'features/hrf/store/hrfSlice';
|
||||||
import loraReducer, { loraPersistConfig } from 'features/lora/store/loraSlice';
|
import { loraPersistConfig, loraSlice } from 'features/lora/store/loraSlice';
|
||||||
import modelmanagerReducer, { modelManagerPersistConfig } from 'features/modelManager/store/modelManagerSlice';
|
import { modelManagerPersistConfig, modelManagerSlice } from 'features/modelManager/store/modelManagerSlice';
|
||||||
import nodesReducer, { nodesPersistConfig } from 'features/nodes/store/nodesSlice';
|
import { nodesPersistConfig, nodesSlice } from 'features/nodes/store/nodesSlice';
|
||||||
import nodeTemplatesReducer from 'features/nodes/store/nodeTemplatesSlice';
|
import { nodesTemplatesSlice } from 'features/nodes/store/nodeTemplatesSlice';
|
||||||
import workflowReducer, { workflowPersistConfig } from 'features/nodes/store/workflowSlice';
|
import { workflowPersistConfig, workflowSlice } from 'features/nodes/store/workflowSlice';
|
||||||
import generationReducer, { generationPersistConfig } from 'features/parameters/store/generationSlice';
|
import { generationPersistConfig, generationSlice } from 'features/parameters/store/generationSlice';
|
||||||
import postprocessingReducer, { postprocessingPersistConfig } from 'features/parameters/store/postprocessingSlice';
|
import { postprocessingPersistConfig, postprocessingSlice } from 'features/parameters/store/postprocessingSlice';
|
||||||
import queueReducer from 'features/queue/store/queueSlice';
|
import { queueSlice } from 'features/queue/store/queueSlice';
|
||||||
import sdxlReducer, { sdxlPersistConfig } from 'features/sdxl/store/sdxlSlice';
|
import { sdxlPersistConfig, sdxlSlice } from 'features/sdxl/store/sdxlSlice';
|
||||||
import configReducer from 'features/system/store/configSlice';
|
import { configSlice } from 'features/system/store/configSlice';
|
||||||
import systemReducer, { systemPersistConfig } from 'features/system/store/systemSlice';
|
import { systemPersistConfig, systemSlice } from 'features/system/store/systemSlice';
|
||||||
import uiReducer, { uiPersistConfig } from 'features/ui/store/uiSlice';
|
import { uiPersistConfig, uiSlice } from 'features/ui/store/uiSlice';
|
||||||
import { diff } from 'jsondiffpatch';
|
import { diff } from 'jsondiffpatch';
|
||||||
import { defaultsDeep, keys, omit, pick } from 'lodash-es';
|
import { defaultsDeep, keys, omit, pick } from 'lodash-es';
|
||||||
import dynamicMiddlewares from 'redux-dynamic-middlewares';
|
import dynamicMiddlewares from 'redux-dynamic-middlewares';
|
||||||
@ -39,26 +40,27 @@ import { actionSanitizer } from './middleware/devtools/actionSanitizer';
|
|||||||
import { actionsDenylist } from './middleware/devtools/actionsDenylist';
|
import { actionsDenylist } from './middleware/devtools/actionsDenylist';
|
||||||
import { stateSanitizer } from './middleware/devtools/stateSanitizer';
|
import { stateSanitizer } from './middleware/devtools/stateSanitizer';
|
||||||
import { listenerMiddleware } from './middleware/listenerMiddleware';
|
import { listenerMiddleware } from './middleware/listenerMiddleware';
|
||||||
|
|
||||||
const allReducers = {
|
const allReducers = {
|
||||||
canvas: canvasReducer,
|
[canvasSlice.name]: canvasSlice.reducer,
|
||||||
gallery: galleryReducer,
|
[gallerySlice.name]: gallerySlice.reducer,
|
||||||
generation: generationReducer,
|
[generationSlice.name]: generationSlice.reducer,
|
||||||
nodes: nodesReducer,
|
[nodesSlice.name]: nodesSlice.reducer,
|
||||||
nodeTemplates: nodeTemplatesReducer,
|
[nodesTemplatesSlice.name]: nodesTemplatesSlice.reducer,
|
||||||
postprocessing: postprocessingReducer,
|
[postprocessingSlice.name]: postprocessingSlice.reducer,
|
||||||
system: systemReducer,
|
[systemSlice.name]: systemSlice.reducer,
|
||||||
config: configReducer,
|
[configSlice.name]: configSlice.reducer,
|
||||||
ui: uiReducer,
|
[uiSlice.name]: uiSlice.reducer,
|
||||||
controlAdapters: controlAdaptersReducer,
|
[controlAdaptersSlice.name]: controlAdaptersSlice.reducer,
|
||||||
dynamicPrompts: dynamicPromptsReducer,
|
[dynamicPromptsSlice.name]: dynamicPromptsSlice.reducer,
|
||||||
deleteImageModal: deleteImageModalReducer,
|
[deleteImageModalSlice.name]: deleteImageModalSlice.reducer,
|
||||||
changeBoardModal: changeBoardModalReducer,
|
[changeBoardModalSlice.name]: changeBoardModalSlice.reducer,
|
||||||
lora: loraReducer,
|
[loraSlice.name]: loraSlice.reducer,
|
||||||
modelmanager: modelmanagerReducer,
|
[modelManagerSlice.name]: modelManagerSlice.reducer,
|
||||||
sdxl: sdxlReducer,
|
[sdxlSlice.name]: sdxlSlice.reducer,
|
||||||
queue: queueReducer,
|
[queueSlice.name]: queueSlice.reducer,
|
||||||
workflow: workflowReducer,
|
[workflowSlice.name]: workflowSlice.reducer,
|
||||||
hrf: hrfReducer,
|
[hrfSlice.name]: hrfSlice.reducer,
|
||||||
[api.reducerPath]: api.reducer,
|
[api.reducerPath]: api.reducer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -719,8 +719,6 @@ export const {
|
|||||||
scaledBoundingBoxDimensionsReset,
|
scaledBoundingBoxDimensionsReset,
|
||||||
} = canvasSlice.actions;
|
} = canvasSlice.actions;
|
||||||
|
|
||||||
export default canvasSlice.reducer;
|
|
||||||
|
|
||||||
export const selectCanvasSlice = (state: RootState) => state.canvas;
|
export const selectCanvasSlice = (state: RootState) => state.canvas;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -5,7 +5,7 @@ import type { ImageDTO } from 'services/api/types';
|
|||||||
|
|
||||||
import { initialState } from './initialState';
|
import { initialState } from './initialState';
|
||||||
|
|
||||||
const changeBoardModal = createSlice({
|
export const changeBoardModalSlice = createSlice({
|
||||||
name: 'changeBoardModal',
|
name: 'changeBoardModal',
|
||||||
initialState,
|
initialState,
|
||||||
reducers: {
|
reducers: {
|
||||||
@ -22,8 +22,6 @@ const changeBoardModal = createSlice({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { isModalOpenChanged, imagesToChangeSelected, changeBoardReset } = changeBoardModal.actions;
|
export const { isModalOpenChanged, imagesToChangeSelected, changeBoardReset } = changeBoardModalSlice.actions;
|
||||||
|
|
||||||
export default changeBoardModal.reducer;
|
|
||||||
|
|
||||||
export const selectChangeBoardModalSlice = (state: RootState) => state.changeBoardModal;
|
export const selectChangeBoardModalSlice = (state: RootState) => state.changeBoardModal;
|
||||||
|
@ -424,8 +424,6 @@ export const {
|
|||||||
controlAdapterModelCleared,
|
controlAdapterModelCleared,
|
||||||
} = controlAdaptersSlice.actions;
|
} = controlAdaptersSlice.actions;
|
||||||
|
|
||||||
export default controlAdaptersSlice.reducer;
|
|
||||||
|
|
||||||
export const isAnyControlAdapterAdded = isAnyOf(
|
export const isAnyControlAdapterAdded = isAnyOf(
|
||||||
controlAdapterAdded,
|
controlAdapterAdded,
|
||||||
controlAdapterAddedFromImage,
|
controlAdapterAddedFromImage,
|
||||||
|
@ -5,7 +5,7 @@ import type { ImageDTO } from 'services/api/types';
|
|||||||
|
|
||||||
import { initialDeleteImageState } from './initialState';
|
import { initialDeleteImageState } from './initialState';
|
||||||
|
|
||||||
const deleteImageModal = createSlice({
|
export const deleteImageModalSlice = createSlice({
|
||||||
name: 'deleteImageModal',
|
name: 'deleteImageModal',
|
||||||
initialState: initialDeleteImageState,
|
initialState: initialDeleteImageState,
|
||||||
reducers: {
|
reducers: {
|
||||||
@ -22,8 +22,6 @@ const deleteImageModal = createSlice({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const { isModalOpenChanged, imagesToDeleteSelected, imageDeletionCanceled } = deleteImageModal.actions;
|
export const { isModalOpenChanged, imagesToDeleteSelected, imageDeletionCanceled } = deleteImageModalSlice.actions;
|
||||||
|
|
||||||
export default deleteImageModal.reducer;
|
|
||||||
|
|
||||||
export const selectDeleteImageModalSlice = (state: RootState) => state.deleteImageModal;
|
export const selectDeleteImageModalSlice = (state: RootState) => state.deleteImageModal;
|
||||||
|
@ -74,8 +74,6 @@ export const {
|
|||||||
seedBehaviourChanged,
|
seedBehaviourChanged,
|
||||||
} = dynamicPromptsSlice.actions;
|
} = dynamicPromptsSlice.actions;
|
||||||
|
|
||||||
export default dynamicPromptsSlice.reducer;
|
|
||||||
|
|
||||||
export const selectDynamicPromptsSlice = (state: RootState) => state.dynamicPrompts;
|
export const selectDynamicPromptsSlice = (state: RootState) => state.dynamicPrompts;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -109,8 +109,6 @@ export const {
|
|||||||
moreImagesLoaded,
|
moreImagesLoaded,
|
||||||
} = gallerySlice.actions;
|
} = gallerySlice.actions;
|
||||||
|
|
||||||
export default gallerySlice.reducer;
|
|
||||||
|
|
||||||
const isAnyBoardDeleted = isAnyOf(
|
const isAnyBoardDeleted = isAnyOf(
|
||||||
imagesApi.endpoints.deleteBoard.matchFulfilled,
|
imagesApi.endpoints.deleteBoard.matchFulfilled,
|
||||||
imagesApi.endpoints.deleteBoardAndImages.matchFulfilled
|
imagesApi.endpoints.deleteBoardAndImages.matchFulfilled
|
||||||
|
@ -37,8 +37,6 @@ export const hrfSlice = createSlice({
|
|||||||
|
|
||||||
export const { setHrfEnabled, setHrfStrength, setHrfMethod } = hrfSlice.actions;
|
export const { setHrfEnabled, setHrfStrength, setHrfMethod } = hrfSlice.actions;
|
||||||
|
|
||||||
export default hrfSlice.reducer;
|
|
||||||
|
|
||||||
export const selectHrfSlice = (state: RootState) => state.hrf;
|
export const selectHrfSlice = (state: RootState) => state.hrf;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -81,8 +81,6 @@ export const {
|
|||||||
loraRecalled,
|
loraRecalled,
|
||||||
} = loraSlice.actions;
|
} = loraSlice.actions;
|
||||||
|
|
||||||
export default loraSlice.reducer;
|
|
||||||
|
|
||||||
export const selectLoraSlice = (state: RootState) => state.lora;
|
export const selectLoraSlice = (state: RootState) => state.lora;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -29,8 +29,6 @@ export const modelManagerSlice = createSlice({
|
|||||||
|
|
||||||
export const { setSearchFolder, setAdvancedAddScanModel } = modelManagerSlice.actions;
|
export const { setSearchFolder, setAdvancedAddScanModel } = modelManagerSlice.actions;
|
||||||
|
|
||||||
export default modelManagerSlice.reducer;
|
|
||||||
|
|
||||||
export const selectModelManagerSlice = (state: RootState) => state.modelmanager;
|
export const selectModelManagerSlice = (state: RootState) => state.modelmanager;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -9,7 +9,7 @@ export const initialNodeTemplatesState: NodeTemplatesState = {
|
|||||||
templates: {},
|
templates: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const nodesTemplatesSlice = createSlice({
|
export const nodesTemplatesSlice = createSlice({
|
||||||
name: 'nodeTemplates',
|
name: 'nodeTemplates',
|
||||||
initialState: initialNodeTemplatesState,
|
initialState: initialNodeTemplatesState,
|
||||||
reducers: {
|
reducers: {
|
||||||
@ -21,6 +21,4 @@ const nodesTemplatesSlice = createSlice({
|
|||||||
|
|
||||||
export const { nodeTemplatesBuilt } = nodesTemplatesSlice.actions;
|
export const { nodeTemplatesBuilt } = nodesTemplatesSlice.actions;
|
||||||
|
|
||||||
export default nodesTemplatesSlice.reducer;
|
|
||||||
|
|
||||||
export const selectNodeTemplatesSlice = (state: RootState) => state.nodeTemplates;
|
export const selectNodeTemplatesSlice = (state: RootState) => state.nodeTemplates;
|
||||||
|
@ -139,7 +139,7 @@ const fieldValueReducer = <T extends FieldValue>(
|
|||||||
input.value = result.data;
|
input.value = result.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
const nodesSlice = createSlice({
|
export const nodesSlice = createSlice({
|
||||||
name: 'nodes',
|
name: 'nodes',
|
||||||
initialState: initialNodesState,
|
initialState: initialNodesState,
|
||||||
reducers: {
|
reducers: {
|
||||||
@ -852,8 +852,6 @@ export const isAnyNodeOrEdgeMutation = isAnyOf(
|
|||||||
edgeAdded
|
edgeAdded
|
||||||
);
|
);
|
||||||
|
|
||||||
export default nodesSlice.reducer;
|
|
||||||
|
|
||||||
export const selectNodesSlice = (state: RootState) => state.nodes;
|
export const selectNodesSlice = (state: RootState) => state.nodes;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -27,7 +27,7 @@ export const initialWorkflowState: WorkflowState = {
|
|||||||
...blankWorkflow,
|
...blankWorkflow,
|
||||||
};
|
};
|
||||||
|
|
||||||
const workflowSlice = createSlice({
|
export const workflowSlice = createSlice({
|
||||||
name: 'workflow',
|
name: 'workflow',
|
||||||
initialState: initialWorkflowState,
|
initialState: initialWorkflowState,
|
||||||
reducers: {
|
reducers: {
|
||||||
@ -119,8 +119,6 @@ export const {
|
|||||||
workflowSaved,
|
workflowSaved,
|
||||||
} = workflowSlice.actions;
|
} = workflowSlice.actions;
|
||||||
|
|
||||||
export default workflowSlice.reducer;
|
|
||||||
|
|
||||||
export const selectWorkflowSlice = (state: RootState) => state.workflow;
|
export const selectWorkflowSlice = (state: RootState) => state.workflow;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -299,8 +299,6 @@ export const {
|
|||||||
|
|
||||||
export const { selectOptimalDimension } = generationSlice.selectors;
|
export const { selectOptimalDimension } = generationSlice.selectors;
|
||||||
|
|
||||||
export default generationSlice.reducer;
|
|
||||||
|
|
||||||
export const selectGenerationSlice = (state: RootState) => state.generation;
|
export const selectGenerationSlice = (state: RootState) => state.generation;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -35,8 +35,6 @@ export const postprocessingSlice = createSlice({
|
|||||||
|
|
||||||
export const { esrganModelNameChanged } = postprocessingSlice.actions;
|
export const { esrganModelNameChanged } = postprocessingSlice.actions;
|
||||||
|
|
||||||
export default postprocessingSlice.reducer;
|
|
||||||
|
|
||||||
export const selectPostprocessingSlice = (state: RootState) => state.postprocessing;
|
export const selectPostprocessingSlice = (state: RootState) => state.postprocessing;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -53,6 +53,4 @@ export const {
|
|||||||
resumeProcessorOnEnqueueChanged,
|
resumeProcessorOnEnqueueChanged,
|
||||||
} = queueSlice.actions;
|
} = queueSlice.actions;
|
||||||
|
|
||||||
export default queueSlice.reducer;
|
|
||||||
|
|
||||||
export const selectQueueSlice = (state: RootState) => state.queue;
|
export const selectQueueSlice = (state: RootState) => state.queue;
|
||||||
|
@ -36,7 +36,7 @@ export const initialSDXLState: SDXLState = {
|
|||||||
refinerStart: 0.8,
|
refinerStart: 0.8,
|
||||||
};
|
};
|
||||||
|
|
||||||
const sdxlSlice = createSlice({
|
export const sdxlSlice = createSlice({
|
||||||
name: 'sdxl',
|
name: 'sdxl',
|
||||||
initialState: initialSDXLState,
|
initialState: initialSDXLState,
|
||||||
reducers: {
|
reducers: {
|
||||||
@ -86,8 +86,6 @@ export const {
|
|||||||
setRefinerStart,
|
setRefinerStart,
|
||||||
} = sdxlSlice.actions;
|
} = sdxlSlice.actions;
|
||||||
|
|
||||||
export default sdxlSlice.reducer;
|
|
||||||
|
|
||||||
export const selectSdxlSlice = (state: RootState) => state.sdxl;
|
export const selectSdxlSlice = (state: RootState) => state.sdxl;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
@ -177,6 +177,4 @@ export const configSlice = createSlice({
|
|||||||
|
|
||||||
export const { configChanged } = configSlice.actions;
|
export const { configChanged } = configSlice.actions;
|
||||||
|
|
||||||
export default configSlice.reducer;
|
|
||||||
|
|
||||||
export const selectConfigSlice = (state: RootState) => state.config;
|
export const selectConfigSlice = (state: RootState) => state.config;
|
||||||
|
@ -194,8 +194,6 @@ export const {
|
|||||||
setShouldEnableInformationalPopovers,
|
setShouldEnableInformationalPopovers,
|
||||||
} = systemSlice.actions;
|
} = systemSlice.actions;
|
||||||
|
|
||||||
export default systemSlice.reducer;
|
|
||||||
|
|
||||||
const isAnyServerError = isAnyOf(socketInvocationError, socketSessionRetrievalError, socketInvocationRetrievalError);
|
const isAnyServerError = isAnyOf(socketInvocationError, socketSessionRetrievalError, socketInvocationRetrievalError);
|
||||||
|
|
||||||
export const selectSystemSlice = (state: RootState) => state.system;
|
export const selectSystemSlice = (state: RootState) => state.system;
|
||||||
|
@ -57,8 +57,6 @@ export const {
|
|||||||
expanderStateChanged,
|
expanderStateChanged,
|
||||||
} = uiSlice.actions;
|
} = uiSlice.actions;
|
||||||
|
|
||||||
export default uiSlice.reducer;
|
|
||||||
|
|
||||||
export const selectUiSlice = (state: RootState) => state.ui;
|
export const selectUiSlice = (state: RootState) => state.ui;
|
||||||
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||||
|
Loading…
Reference in New Issue
Block a user