The options that I see are:
There is an array of current chat messages. There is an observable that is created to notify subscribers to new posts. And each new message rushes to the array.
There is an observable that stores in itself an array of all open chat messages at once (or all opened in a session, I don’t know how to do it either). When a new message is received, it is added to the array.
There is an observable that stores only the last message and notifies subscribers about it. That is, if a message is added, then all subscribers trigger functions and add new messages to html, but the entire list is not stored. Well, or stored until the destruction of the component.
If relevant, chat messages are stored in the database and are received via sockets.
Please tell me how it is more convenient, optimized and more intelligent to implement this function? If possible, explain why