神刀安全网

socket.io-redux – Redux middleware to emit actions to a socket.io server

socket.io-redux

Redux middleware to emit actions to a socket.io server

API

Apply middleware

import io from 'socket.io-client'; import { createStore, applyMiddleware } from 'redux';  import socketIO from 'socket.io-redux';  import reducer from './reducer';  const store = createStore(reducer, applyMiddleware(   socketIO(io.connect(process.env.SOCKET_URL)) ));
  • socketIO receive a socket instance created by io.connect(<url>) .

Example action

const action = {   type: 'ADD_TODO',   payload: {     message: 'Use socket.io-redux middleware',   },   meta: {     socket: {       channel: 'add:todo',     },   }, };
  • meta.socket.channel define the socket.io channel to use to emit the action.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » socket.io-redux – Redux middleware to emit actions to a socket.io server

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮