feat: refactor the cache

This commit is contained in:
zerosoul
2022-03-04 10:15:30 +08:00
parent b6b0a0c5ef
commit acd007fb71
28 changed files with 622 additions and 341 deletions
+12 -6
View File
@@ -4,15 +4,20 @@ const channelsSlice = createSlice({
name: `channels`,
initialState,
reducers: {
clearChannels() {
return initialState;
},
setChannels(state, action) {
console.log("set channels store", state);
const chs = action.payload || [];
return Object.fromEntries(
chs.map((c) => {
const { gid, ...rest } = c;
return [gid, rest];
})
);
return Array.isArray(chs)
? Object.fromEntries(
chs.map((c) => {
const { gid, ...rest } = c;
return [gid, rest];
})
)
: chs;
},
updateChannel(state, action) {
@@ -41,6 +46,7 @@ const channelsSlice = createSlice({
},
});
export const {
clearChannels,
setChannels,
addChannel,
deleteChannel,