File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 11# socket.io-redux
2- Redux middleware to emit action via socket.io.
2+ Redux middleware to emit actions to a socket.io server
33
44## API
5+ ### Apply middleware
56``` javascript
67import io from ' socket.io-client' ;
78import { createStore , applyMiddleware } from ' redux' ;
@@ -11,7 +12,23 @@ import socketIO from 'socket.io-redux';
1112import reducer from ' ./reducer' ;
1213
1314const store = createStore (reducer, applyMiddleware (
14- socketIO (io .connect (process .env .NODE_ENV ))
15+ socketIO (io .connect (process .env .SOCKET_URL ))
1516));
1617```
17- * ` socketIO ` receive a ` socket ` instance created by ` io.connect(url) ` .
18+ * ` socketIO ` receive a ` socket ` instance created by ` io.connect(<url>) ` .
19+
20+ ### Example action
21+ ``` javascript
22+ const action = {
23+ type: ' ADD_TODO' ,
24+ payload: {
25+ message: ' Use socket.io-redux middleware' ,
26+ },
27+ meta: {
28+ socket: {
29+ channel: ' add:todo' ,
30+ },
31+ },
32+ };
33+ ```
34+ * ` meta.socket.channel ` define the socket.io channel to use to emit the action.
You can’t perform that action at this time.
0 commit comments