Donut
Donut

Reputation: 81

Storing websocket (channels) connection objects in Redux

I want to use websockets in my redux app and have problems with storing connection objects (phoenix channels).

I have a dynamic collection with possibility to add and remove items. When user adds an item, app should create a new phoenix channel based on connection, subscribe and store because I have to do some stuff on it (for example I have to call a method leave() on channel when user removes an item). Unfortunately, store in redux is all immutable, so there is no option to handle this. Any help would be appreciated.

Upvotes: 1

Views: 622

Answers (1)

markerikson
markerikson

Reputation: 67459

Definitely don't put it in the store. Per Redux FAQ, only serializable data should go into the store. The standard place to put things like persistent connection objects is inside middleware. And, in fact, there's literally dozens of existing middlewares that demonstrate that approach, with most of them listed over at redux-ecosystem-links. You should be able to use some of those as examples.

Upvotes: 1

Related Questions