-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sergio Daniel Xalambrí
committed
Mar 18, 2016
0 parents
commit a461325
Showing
7 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
"transform-es2015-modules-commonjs", | ||
"transform-es2015-arrow-functions" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
build | ||
logs | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
lib | ||
test | ||
logs | ||
*.log | ||
.babelrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# socket.io-redux | ||
Redux middleware to emit action via socket.io. | ||
|
||
## API | ||
```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.NODE_ENV)) | ||
)); | ||
``` | ||
* `socketIO` receive a `socket` instance created by `io.connect(url)`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const socketIO = socket => () => next => action => { | ||
if (action.meta && action.meta.socket && action.meta.socket.channel) { | ||
socket.emit(action.meta.socket.channel, action); | ||
} | ||
|
||
return next(action); | ||
} | ||
|
||
export default socketIO; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "socket.io-redux", | ||
"version": "1.0.0", | ||
"description": "Redux middleware to emit action via socket.io.", | ||
"main": "build/index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"build": "babel lib --out-dir build", | ||
"pretest": "npm run build", | ||
"prepublish": "npm run test", | ||
"test": "babel-node test/index.js | tap-spec" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sergiodxa/socket.io-redux.git" | ||
}, | ||
"keywords": [ | ||
"redux", | ||
"middleware", | ||
"socket.io" | ||
], | ||
"author": "Sergio Daniel Xalambrí <[email protected]> (http://sergio.xalambri.com.ar/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/sergiodxa/socket.io-redux/issues" | ||
}, | ||
"homepage": "http://sergio.xalambri.com.ar/socket.io-redux", | ||
"devDependencies": { | ||
"babel": "6.5.2", | ||
"babel-cli": "6.6.5", | ||
"babel-plugin-transform-es2015-arrow-functions": "6.5.2", | ||
"babel-plugin-transform-es2015-modules-commonjs": "6.7.0", | ||
"tap-spec": "4.1.1", | ||
"tape": "4.5.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import test from 'tape'; | ||
import socketIO from '../build/index'; | ||
|
||
function next(action) { return action; } | ||
|
||
test('socket.io middleware', t => { | ||
t.plan(2); | ||
|
||
const testAction = { | ||
type: 'ADD_NEW', | ||
payload: 'hello world!', | ||
meta: { | ||
socket: { | ||
channel: 'add:new', | ||
}, | ||
}, | ||
}; | ||
|
||
const socket = { | ||
emit(channel, data) { | ||
t.equals(channel, 'add:new', 'it should have the channel "add:new"'); | ||
t.deepEquals(data, testAction, 'it should have the action as data'); | ||
} | ||
} | ||
|
||
socketIO(socket)()(next)(testAction); | ||
}); |