feedgetstream-io

Best Practices For Handling Feed Subscription Events In getStream


Im having trouble finding documentation regarding best practices for handling activity data emitted from a realtime subscription to a getStream feed.

Our current set-up mimics what it seems react-activity-feed does: (1) subscribe to feed and listen for new activities (2) when a new activity is emitted display a button at the top of the feed announcing the new activity (3) when the announcement button is selected make a new feed.get() call to retrieve the most recent feed data.

The problem we are considering is how we could avoid making a new call to feed.get() every time a new activity is emitted (seems wasteful). We would rather store the original response data from feed.get() inside a state variable and insert new activities into that object.

This doesn't seem possible, however, as we get the following error whenever we try to append to the nested array inside the feed.get() response object: TypeError: Cannot assign to read only property 'activities'

I would greatly appreciate any advice on how others have handled new activities emitted from a feed.


Solution

  • I discovered that react-activity-feed does NOT make a call to feed.get() to retrieve the updated feed data after a new event is emitted to the feed.

    feed.get() is only called when a feed is first visited or a pagination event occurs that makes a request to get more feed data. Otherwise, a copy of the feed activity object is created (using immutableJS.Map) and newly emitted events are pushed to this object which is used to display content in the feed (see object definition here). The same is done for managing reactions to activities as well as notifications.

    So for anyone who is curious how to manage new events emitted from Streams real-time subscription try to managed feed state in your app by making a copy of the object that is initially returned by feed.get() and manipulate that object in your UI to limit the number of requests made to getStream and improves the performance of the feed as well.