Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/recruit-tech/redux-effects-socket-io
socket.io bindings for redux-effects family
https://github.com/recruit-tech/redux-effects-socket-io
Last synced: about 11 hours ago
JSON representation
socket.io bindings for redux-effects family
- Host: GitHub
- URL: https://github.com/recruit-tech/redux-effects-socket-io
- Owner: recruit-tech
- License: mit
- Created: 2016-09-05T13:26:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-20T09:33:31.000Z (over 7 years ago)
- Last Synced: 2024-04-24T20:03:18.670Z (7 months ago)
- Language: JavaScript
- Size: 109 KB
- Stars: 2
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-effects-socket-io
[![Build Status](https://travis-ci.org/recruit-tech/redux-effects-socket-io.svg?branch=master)](https://travis-ci.org/recruit-tech/redux-effects-socket-io)[`socket.io`](socket.io) binding for `redux-effects` family.
# Install
```
$ npm install redux-effects-socket-io --save
```# Usage
Register `redux-effects-socket-io` as middleware
```javascript
import { createStore, applyMiddleware } from 'redux';
import stepsMiddleware from 'redux-effects-steps';
import socketio from 'redux-effects-socket-io';
import rootReducer from './reducers';const store = createStore(
rootReducer,
applyMiddleware(
stepsMiddleware,
// specify hostname default location.host
socketio({ hostname: 'localhost:3010'})
)
);
```Usage `redux-effects-socket-io` as client
```javascript
import { createAction } from 'redux-actions';
import { steps } from 'redux-effects-steps';
import { connect, emit, on } from 'redux-effects-socket-io';const ON_MESSAGE = 'on_message';
const onMessage = createAction(ON_MESSAGE, (data) => ({ data }));
const EMIT_MESSAGE = 'emit_message';
const emitMessage = createAction(EMIT_MESSAGE, (data) => ({ data }));
function onMessage(event) {
return steps(
connect(),
on(event, onMessageChat)
);
}function emitMessage(event, data) {
retrun emit(event, data);
}
```Use from component
```javascript
const promise = store.dispatch(onMessage('message'));
```# API
## connect(config = {})
connect to `socket.io` server.
## emit(event, data)
emit event and data to `socket.io` server.
## on(event, action)
receive event and send action event
## disconnect()
disconnect from `socket.io` server.