Mobx-state-tree: WebSocket buffer inside store suggestion

Created on 10 Apr 2018  路  3Comments  路  Source: mobxjs/mobx-state-tree

Hi,

I'm trying to put a socket.io-client instance inside a mst definition. I want to make the socket.io buffered/data stream goes reactive, is it possible to do so? The reason to do this is I only want one socket.io-client instance alive between navigations.

Some options I'm thinking of:

  • use plain mobx instead, and Atom (ref https://github.com/sampsonjoliver/mobx-websocket-store)
  • use socket.io-client as normal prop
question

Most helpful comment

recently also asked on spectrum. they ended up using the dependency injection to do so and did setup an action on the channel. something like that:

.actions(self => ({
  someAction(param, param2) {
      ...
  },
  afterCreate() {
    self.channel = getEnv(self).socket.channel("channelId")
    channel.on = self.someAction;
  }
 }))

All 3 comments

@skellock I'll give it a try, thank you.

recently also asked on spectrum. they ended up using the dependency injection to do so and did setup an action on the channel. something like that:

.actions(self => ({
  someAction(param, param2) {
      ...
  },
  afterCreate() {
    self.channel = getEnv(self).socket.channel("channelId")
    channel.on = self.someAction;
  }
 }))
Was this page helpful?
0 / 5 - 0 ratings