mirror of https://github.com/msgbyte/tailchat
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.
33 lines
726 B
TypeScript
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;
|