mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Preventing unnecessary re-renders across the app
This commit is contained in:
parent
9bafda6a15
commit
4e911566c3
@ -28,12 +28,18 @@ import { RootState } from '../../app/store';
|
|||||||
import { setShouldConfirmOnDelete, SystemState } from '../system/systemSlice';
|
import { setShouldConfirmOnDelete, SystemState } from '../system/systemSlice';
|
||||||
import * as InvokeAI from '../../app/invokeai';
|
import * as InvokeAI from '../../app/invokeai';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
const systemSelector = createSelector(
|
const systemSelector = createSelector(
|
||||||
(state: RootState) => state.system,
|
(state: RootState) => state.system,
|
||||||
(system: SystemState) => {
|
(system: SystemState) => {
|
||||||
const { shouldConfirmOnDelete, isConnected, isProcessing } = system;
|
const { shouldConfirmOnDelete, isConnected, isProcessing } = system;
|
||||||
return { shouldConfirmOnDelete, isConnected, isProcessing };
|
return { shouldConfirmOnDelete, isConnected, isProcessing };
|
||||||
|
},
|
||||||
|
{
|
||||||
|
memoizeOptions: {
|
||||||
|
resultEqualityCheck: _.isEqual,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
interface DeleteImageModalProps {
|
interface DeleteImageModalProps {
|
||||||
|
@ -4,6 +4,7 @@ import { activeTabNameSelector } from '../options/optionsSelectors';
|
|||||||
import { OptionsState } from '../options/optionsSlice';
|
import { OptionsState } from '../options/optionsSlice';
|
||||||
import { SystemState } from '../system/systemSlice';
|
import { SystemState } from '../system/systemSlice';
|
||||||
import { GalleryState } from './gallerySlice';
|
import { GalleryState } from './gallerySlice';
|
||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
export const imageGallerySelector = createSelector(
|
export const imageGallerySelector = createSelector(
|
||||||
[
|
[
|
||||||
@ -43,6 +44,11 @@ export const imageGallerySelector = createSelector(
|
|||||||
currentCategory,
|
currentCategory,
|
||||||
galleryWidth,
|
galleryWidth,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
memoizeOptions: {
|
||||||
|
resultEqualityCheck: _.isEqual,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -65,5 +71,10 @@ export const hoverableImageSelector = createSelector(
|
|||||||
galleryImageMinimumWidth: gallery.galleryImageMinimumWidth,
|
galleryImageMinimumWidth: gallery.galleryImageMinimumWidth,
|
||||||
activeTabName,
|
activeTabName,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
memoizeOptions: {
|
||||||
|
resultEqualityCheck: _.isEqual,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -7,7 +7,7 @@ import { setHeight } from '../optionsSlice';
|
|||||||
import { fontSize } from './MainOptions';
|
import { fontSize } from './MainOptions';
|
||||||
|
|
||||||
export default function MainHeight() {
|
export default function MainHeight() {
|
||||||
const { height } = useAppSelector((state: RootState) => state.options);
|
const height = useAppSelector((state: RootState) => state.options.height);
|
||||||
const activeTabName = useAppSelector(activeTabNameSelector);
|
const activeTabName = useAppSelector(activeTabNameSelector);
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@ import React, { ChangeEvent } from 'react';
|
|||||||
import { WIDTHS } from '../../../app/constants';
|
import { WIDTHS } from '../../../app/constants';
|
||||||
import { RootState, useAppDispatch, useAppSelector } from '../../../app/store';
|
import { RootState, useAppDispatch, useAppSelector } from '../../../app/store';
|
||||||
import IAISelect from '../../../common/components/IAISelect';
|
import IAISelect from '../../../common/components/IAISelect';
|
||||||
import { tabMap } from '../../tabs/InvokeTabs';
|
import { activeTabNameSelector } from '../optionsSelectors';
|
||||||
import { setWidth } from '../optionsSlice';
|
import { setWidth } from '../optionsSlice';
|
||||||
import { fontSize } from './MainOptions';
|
import { fontSize } from './MainOptions';
|
||||||
|
|
||||||
export default function MainWidth() {
|
export default function MainWidth() {
|
||||||
const { width, activeTab } = useAppSelector(
|
const width = useAppSelector((state: RootState) => state.options.width);
|
||||||
(state: RootState) => state.options
|
const activeTabName = useAppSelector(activeTabNameSelector);
|
||||||
);
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
const handleChangeWidth = (e: ChangeEvent<HTMLSelectElement>) =>
|
const handleChangeWidth = (e: ChangeEvent<HTMLSelectElement>) =>
|
||||||
@ -17,7 +17,7 @@ export default function MainWidth() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<IAISelect
|
<IAISelect
|
||||||
isDisabled={tabMap[activeTab] === 'inpainting'}
|
isDisabled={activeTabName === 'inpainting'}
|
||||||
label="Width"
|
label="Width"
|
||||||
value={width}
|
value={width}
|
||||||
flexGrow={1}
|
flexGrow={1}
|
||||||
|
@ -5,7 +5,9 @@ import { RootState, useAppDispatch, useAppSelector } from '../../../app/store';
|
|||||||
import { clearInitialImage } from '../../options/optionsSlice';
|
import { clearInitialImage } from '../../options/optionsSlice';
|
||||||
|
|
||||||
export default function InitImagePreview() {
|
export default function InitImagePreview() {
|
||||||
const { initialImage } = useAppSelector((state: RootState) => state.options);
|
const initialImage = useAppSelector(
|
||||||
|
(state: RootState) => state.options.initialImage
|
||||||
|
);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
const inpaintingCanvasStatusIconsSelector = createSelector(
|
const inpaintingCanvasStatusIconsSelector = createSelector(
|
||||||
(state: RootState) => state.inpainting,
|
(state: RootState) => state.inpainting,
|
||||||
(inpainting: InpaintingState) => {
|
(inpainting: InpaintingState) => {
|
||||||
@ -14,6 +16,11 @@ const inpaintingCanvasStatusIconsSelector = createSelector(
|
|||||||
shouldLockBoundingBox,
|
shouldLockBoundingBox,
|
||||||
shouldShowBoundingBox,
|
shouldShowBoundingBox,
|
||||||
};
|
};
|
||||||
|
},
|
||||||
|
{
|
||||||
|
memoizeOptions: {
|
||||||
|
resultEqualityCheck: _.isEqual,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user