refactor(ui): refactor persist config

Add more structure around persist configs to avoid bugs from typos and misplaced persist denylists.
This commit is contained in:
psychedelicious
2024-02-03 20:18:13 +11:00
committed by Kent Keirsey
parent 0976ddba23
commit c1300fa8b1
24 changed files with 175 additions and 189 deletions

View File

@ -1,3 +0,0 @@
import type { SystemState } from './types';
export const systemPersistDenylist: (keyof SystemState)[] = ['isConnected', 'denoiseProgress', 'status'];

View File

@ -1,7 +1,7 @@
import type { UseToastOptions } from '@invoke-ai/ui-library';
import type { PayloadAction } from '@reduxjs/toolkit';
import { createSlice, isAnyOf } from '@reduxjs/toolkit';
import type { RootState } from 'app/store/store';
import type { PersistConfig, RootState } from 'app/store/store';
import { calculateStepPercentage } from 'features/system/util/calculateStepPercentage';
import { makeToast } from 'features/system/util/makeToast';
import { t } from 'i18next';
@ -207,3 +207,10 @@ export const migrateSystemState = (state: any): any => {
}
return state;
};
export const systemPersistConfig: PersistConfig<SystemState> = {
name: systemSlice.name,
initialState: initialSystemState,
migrate: migrateSystemState,
persistDenylist: ['isConnected', 'denoiseProgress', 'status'],
};