2

Hello guys I have a question regarding state management in applications centered around events.

Let us say take a scenario in which a some one posts a tweet on twitter, so this tweet should be visible to the users in real time. So things like posting a tweet or typing a comment etc are all real time events; where as fetching data from the server on the click of a button are all Restful in nature. Real-time communication can be achieved by using either web-sockets or server-sent-events. Now the question naturally that comes in the mind is How do we manage the data (state management) for rest as well as real time communication?

Restful resources are generally fetched as a bundle of information, but server sent event or websocket send it as a packet of information, by packet what i mean is data related to the single tweet. If we were to show a list of all tweets to the user we need to update the state to previously received tweets and incoming tweets but state management here becomes very hard.

I have looked at some solutions like RxJs which typically involves observables, and redux-saga which deals with generators. So can you share your experiences and insights to managing real time data and restful data.

End goal is how to manage rest and real time data in a live feed. Please feel free to correct me for any technical inaccuracies and/ suggestions. Thank you

  • 2
    It isn't any more complicated than polling and prepending new data to state, i.e. `tweets = [ ...newTweets, ...state.tweets ]` and `newTweets` may come from web socket or calling `fetch` again. If the socket sends a single tweet at a time then it could becme `tweets = [ newTweet, ...state.tweets ]`. – pawel May 03 '20 at 18:01

0 Answers0