https://github.com/sharongrossman/redux-sockets
Simplify the integration of socket.io with your Redux application
https://github.com/sharongrossman/redux-sockets
middleware reducer redux-socket
Last synced: 5 months ago
JSON representation
Simplify the integration of socket.io with your Redux application
- Host: GitHub
- URL: https://github.com/sharongrossman/redux-sockets
- Owner: SharonGrossman
- License: mit
- Created: 2017-07-23T12:33:43.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-23T12:10:06.000Z (about 8 years ago)
- Last Synced: 2024-10-29T22:26:07.991Z (11 months ago)
- Topics: middleware, reducer, redux-socket
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-sockets 
## Install
```
npm install --save-dev redux-sockets
```## Description
* A simple module to help simplify the integration of [socket.io](https://socket.io)
with your [redux](http://redux.js.org/docs/introduction/) application
* Emits client actions to the server if a `socket` payload is presented
* Initializes socketio connection and handles connection actions to the server and client
* Listens to any socket event using `socketio-wildcard`
and dispatches the event to the client in the form of `server/ACTION_TYPE`## Usage
The module exports a middleware and a reducer### middleware
Add the middleware to the applyMiddleware function upon redux store initialization```
import socketIoMiddleware from 'redux-sockets';
...
return createStore(
...
applyMiddleware(socketIoMiddleware(), ...middlewares)
);
```
### reducer
Simply import and add the reducer to your other reducers
```
import {combineReducers} from 'redux';
import {reducer as socket} from 'redux-sockets';
...
export default combineReducers({
...
socket
});
```The module also exports the action ``` socketConnect``` ,
and action types ``` CONNECT, CONNECTED, DISCONNECTED```## Why not [redux-socket.io](https://github.com/itaylor/redux-socket.io)?
redux-socket.io is great for capturing events from the server but I wanted more control
over the received actions and create a connection on demand (emitting a CONNECT action)
Also, with redux-socket.io you could only capture a single event name.
This module captures all sorts of events.## License
[MIT](LICENSE) © [Sharon Grossman](https://github.com/sharongrossman)