Switch to redux and webpack
This commit is contained in:
parent
b247287075
commit
e389454535
97 changed files with 2722 additions and 2656 deletions
20
client/src/js/middleware/command.js
Normal file
20
client/src/js/middleware/command.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
export default function createCommandMiddleware(type, handlers) {
|
||||
return store => next => action => {
|
||||
if (action.type === type) {
|
||||
const words = action.command.slice(1).split(' ');
|
||||
const command = words[0];
|
||||
const params = words.slice(1);
|
||||
|
||||
if (handlers.hasOwnProperty(command)) {
|
||||
handlers[command]({
|
||||
dispatch: store.dispatch,
|
||||
getState: store.getState,
|
||||
server: action.server,
|
||||
channel: action.channel
|
||||
}, ...params);
|
||||
}
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
||||
}
|
9
client/src/js/middleware/socket.js
Normal file
9
client/src/js/middleware/socket.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
export default function createSocketMiddleware(socket) {
|
||||
return () => next => action => {
|
||||
if (action.socket) {
|
||||
socket.send(action.socket.type, action.socket.data);
|
||||
}
|
||||
|
||||
return next(action);
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue