Permalink
1 comment
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
set clientId on remote actions for duplicate vote prevention
- Loading branch information
Showing
with
42 additions
and 3 deletions.
- +3 −1 package.json
- +7 −0 src/action_creators.js
- +10 −0 src/client_id.js
- +3 −1 src/index.jsx
- +2 −0 src/reducer.js
- +4 −1 src/remote_action_middleware.js
- +13 −0 test/reducer_spec.js
@@ -0,0 +1,10 @@ | ||
import uuid from 'uuid'; | ||
|
||
export default function getClientId() { | ||
let id = localStorage.getItem('clientId'); | ||
if (!id) { | ||
id = uuid.v4(); | ||
localStorage.setItem('clientId', id); | ||
} | ||
return id; | ||
} |
@@ -1,6 +1,9 @@ | ||
import objectAssign from 'object-assign'; | ||
|
||
export default socket => store => next => action => { | ||
if (action.meta && action.meta.remote) { | ||
socket.emit('action', action); | ||
const clientId = store.getState().get('clientId'); | ||
socket.emit('action', objectAssign({}, action, {clientId})); | ||
} | ||
return next(action); | ||
} |
This comment has been minimized.
59a8b52
Hey, is it necessary to put client ID inside redux store?
isn't that will always be the same for each client regardless any state?