Skip to content

Commit

Permalink
добавил еще микро-возможную-оптимизацию для remove
Browse files Browse the repository at this point in the history
  • Loading branch information
VanyaMate committed Aug 10, 2024
1 parent 14525ed commit 06d419a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/app/model/private-messages/private-messages.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,22 @@ export const $privateMessages = store<PrivateMessagesStore>({})
removePrivateMessageEffect,
'onSuccess',
(state, { result }) => {
const messages = state[result.dialogue.id]?.filter(({ id }) => id !== result.message.id) ?? [];
return {
...state,
[result.dialogue.id]: messages,
};
const dialogueId: string = result.dialogue.id;
const dialogueMessages = state[dialogueId];

if (dialogueMessages) {
const messages = dialogueMessages.filter((message) => message.id !== result.message.id);
if (messages.length !== dialogueMessages.length) {
return {
...state,
[dialogueId]: messages,
};
}

return state;
}

return state;
},
)
.on(
Expand Down

0 comments on commit 06d419a

Please sign in to comment.