dvajs / dva

🌱 React and redux based, lightweight and elm-style framework. (Inspired by elm and choo)
https://dvajs.com/
MIT License
16.24k stars 3.17k forks source link

Example of Websockets use with global store? #2424

Closed jwmann closed 3 years ago

jwmann commented 3 years ago

The documentation for subscriptions mentions the use of websockets but doesn't provide any example of this.

My websocket implementation needs access to the global store in order to pass information to the server alongside the connection.

https://github.com/dvajs/dva-knowledgemap/blob/master/README_en.md#subscription

app.model({
  subscriptions: {
    setup({ dispatch, history }) {
      history.listen(({ pathname }) => {
        if (pathname === '/users') {
          dispatch({
            type: 'users/fetch',
          });
        }
      });
    },
  },
});

In this example it's using history.listen, this doesn't have anything to do with websockets.

In #499 @sorrycc provides a link to a project that supposedly shows an example of subscriptions using websockets but there is nothing about websockets.

Inside subscriptions, there's seems to be no way to access to global store either, this is a requirement for me.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.