You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/redux/slices/cache.ts

33 lines
726 B
TypeScript

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { UserBaseInfo } from '../../model/user';
import _set from 'lodash/set';
interface CacheState {
user: Record<string, UserBaseInfo>;
}
export type CacheKey = keyof CacheState;
const initialState: CacheState = { user: {} };
const cacheSlice = createSlice({
name: 'cache',
initialState,
reducers: {
setCache(
state,
action: PayloadAction<{
scope: CacheKey;
id: string;
data: unknown;
}>
) {
const { scope, id, data } = action.payload;
_set(state, [scope, id], data);
},
},
});
export const cacheActions = cacheSlice.actions;
export const cacheReducer = cacheSlice.reducer;