Add manifest.json, icons and install button, flatten client/src
This commit is contained in:
parent
a219e689c1
commit
474afda9c2
105 changed files with 338 additions and 283 deletions
36
client/js/middleware/socket.js
Normal file
36
client/js/middleware/socket.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import debounce from 'lodash/debounce';
|
||||
|
||||
const debounceKey = action => {
|
||||
const { key } = action.socket.debounce;
|
||||
if (key) {
|
||||
return `${action.type} ${key}`;
|
||||
}
|
||||
return action.type;
|
||||
};
|
||||
|
||||
export default function createSocketMiddleware(socket) {
|
||||
return () => next => {
|
||||
const debounced = {};
|
||||
|
||||
return action => {
|
||||
if (action.socket) {
|
||||
if (action.socket.debounce) {
|
||||
const key = debounceKey(action);
|
||||
|
||||
if (!debounced[key]) {
|
||||
debounced[key] = debounce((type, data) => {
|
||||
socket.send(type, data);
|
||||
debounced[key] = undefined;
|
||||
}, action.socket.debounce.delay);
|
||||
}
|
||||
|
||||
debounced[key](action.socket.type, action.socket.data);
|
||||
} else {
|
||||
socket.send(action.socket.type, action.socket.data);
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue