Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/platzidev/socket.io-redux
Redux middleware to emit action via socket.io
https://github.com/platzidev/socket.io-redux
redux redux-middleware socket socket-io
Last synced: 3 months ago
JSON representation
Redux middleware to emit action via socket.io
- Host: GitHub
- URL: https://github.com/platzidev/socket.io-redux
- Owner: PlatziDev
- Created: 2016-03-18T21:55:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-08T20:20:49.000Z (almost 8 years ago)
- Last Synced: 2024-05-18T18:02:14.603Z (9 months ago)
- Topics: redux, redux-middleware, socket, socket-io
- Language: JavaScript
- Size: 9.77 KB
- Stars: 105
- Watchers: 4
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# socket.io-redux
Redux middleware to emit actions to a socket.io server## API
### Apply middleware
```javascript
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()`.### Example action
```javascript
const action = {
type: 'ADD_TODO',
payload: {
message: 'Use socket.io-redux middleware',
},
meta: {
socket: {
channel: 'add:todo',
namespace: 'ns',
room: 'room',
},
},
};
```
* `meta.socket.channel` define the socket.io channel to use to emit the action.
* `meta.socket.namespace` (optional) use the given namespace, instead of the default, to emit the action.
* `meta.socket.room` (optional) emit the action to the given room, instead of a global broadcast.