How to concatenate two states in angular?

I have state

export interface ChatMessagesState {
  messages: Message[] | null;
  chatId: string;
}

in the websocket, data may come that will be something like this

newMessages: Message[] = [
{
    text: 'Hello',
    chatId: '100'
},
{
    text: 'Hello 2',
    chatId: '101'
}
]

and so, I want to update add a separate message to the state (concatenate them) if the chatIds match, and if not, then do not add. Where should this be done, in the reducer? Or in the facade?


Solution 1:

That logic should exist in the reducer because it holds the state. This means that you can easily read the state within the reducer to decide if it should append the message or not. In my apps, all of the logic to check what/if it needs to update state lives in reducers.