Preventing unnecessary re-renders across the app

This commit is contained in:
blessedcoolant 2022-11-02 03:50:56 +13:00 committed by Lincoln Stein
parent 9bafda6a15
commit 4e911566c3
6 changed files with 33 additions and 7 deletions

View File

@ -28,12 +28,18 @@ import { RootState } from '../../app/store';
import { setShouldConfirmOnDelete, SystemState } from '../system/systemSlice';
import * as InvokeAI from '../../app/invokeai';
import { useHotkeys } from 'react-hotkeys-hook';
import _ from 'lodash';
const systemSelector = createSelector(
(state: RootState) => state.system,
(system: SystemState) => {
const { shouldConfirmOnDelete, isConnected, isProcessing } = system;
return { shouldConfirmOnDelete, isConnected, isProcessing };
},
{
memoizeOptions: {
resultEqualityCheck: _.isEqual,
},
}
);
interface DeleteImageModalProps {

View File

@ -4,6 +4,7 @@ import { activeTabNameSelector } from '../options/optionsSelectors';
import { OptionsState } from '../options/optionsSlice';
import { SystemState } from '../system/systemSlice';
import { GalleryState } from './gallerySlice';
import _ from 'lodash';
export const imageGallerySelector = createSelector(
[
@ -43,6 +44,11 @@ export const imageGallerySelector = createSelector(
currentCategory,
galleryWidth,
};
},
{
memoizeOptions: {
resultEqualityCheck: _.isEqual,
},
}
);
@ -65,5 +71,10 @@ export const hoverableImageSelector = createSelector(
galleryImageMinimumWidth: gallery.galleryImageMinimumWidth,
activeTabName,
};
},
{
memoizeOptions: {
resultEqualityCheck: _.isEqual,
},
}
);

View File

@ -7,7 +7,7 @@ import { setHeight } from '../optionsSlice';
import { fontSize } from './MainOptions';
export default function MainHeight() {
const { height } = useAppSelector((state: RootState) => state.options);
const height = useAppSelector((state: RootState) => state.options.height);
const activeTabName = useAppSelector(activeTabNameSelector);
const dispatch = useAppDispatch();

View File

@ -2,14 +2,14 @@ import React, { ChangeEvent } from 'react';
import { WIDTHS } from '../../../app/constants';
import { RootState, useAppDispatch, useAppSelector } from '../../../app/store';
import IAISelect from '../../../common/components/IAISelect';
import { tabMap } from '../../tabs/InvokeTabs';
import { activeTabNameSelector } from '../optionsSelectors';
import { setWidth } from '../optionsSlice';
import { fontSize } from './MainOptions';
export default function MainWidth() {
const { width, activeTab } = useAppSelector(
(state: RootState) => state.options
);
const width = useAppSelector((state: RootState) => state.options.width);
const activeTabName = useAppSelector(activeTabNameSelector);
const dispatch = useAppDispatch();
const handleChangeWidth = (e: ChangeEvent<HTMLSelectElement>) =>
@ -17,7 +17,7 @@ export default function MainWidth() {
return (
<IAISelect
isDisabled={tabMap[activeTab] === 'inpainting'}
isDisabled={activeTabName === 'inpainting'}
label="Width"
value={width}
flexGrow={1}

View File

@ -5,7 +5,9 @@ import { RootState, useAppDispatch, useAppSelector } from '../../../app/store';
import { clearInitialImage } from '../../options/optionsSlice';
export default function InitImagePreview() {
const { initialImage } = useAppSelector((state: RootState) => state.options);
const initialImage = useAppSelector(
(state: RootState) => state.options.initialImage
);
const dispatch = useAppDispatch();

View File

@ -1,3 +1,5 @@
import _ from 'lodash';
const inpaintingCanvasStatusIconsSelector = createSelector(
(state: RootState) => state.inpainting,
(inpainting: InpaintingState) => {
@ -14,6 +16,11 @@ const inpaintingCanvasStatusIconsSelector = createSelector(
shouldLockBoundingBox,
shouldShowBoundingBox,
};
},
{
memoizeOptions: {
resultEqualityCheck: _.isEqual,
},
}
);