Support changing the server name by clicking it in the status tab

This commit is contained in:
Ken-Håvard Lieng 2017-06-12 06:18:32 +02:00
parent 3b33957161
commit b639ba6846
14 changed files with 259 additions and 56 deletions

View file

@ -1,9 +1,36 @@
export default function createSocketMiddleware(socket) {
return () => next => action => {
if (action.socket) {
socket.send(action.socket.type, action.socket.data);
}
import debounce from 'lodash/debounce';
return next(action);
const debounceKey = action => {
const key = action.socket.debounce.key;
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);
};
};
}