Created
September 1, 2016 11:27
-
-
Save ttanimichi/492bc730b35b677094840d78e2db1471 to your computer and use it in GitHub Desktop.
socket.io の Event をメタプロでクラスに流すサンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClientEvents { | |
static connect() { | |
logger.info({ event: 'connect' }); | |
} | |
static reconnect_error(error) { | |
logger.info({ event: 'reconnect_error', error: error }); | |
} | |
} | |
socket.on('reconnect_error', ClientEvents.reconnect_error); | |
// socket.on('connect', ClientEvents.connect); | |
const s = 'connect'; | |
socket.on(s, ClientEvents[s]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
camelize 使う
https://github.com/substack/camelize