Skip to content

Instantly share code, notes, and snippets.

@UsamaAshraf
Last active November 3, 2018 16:41
Show Gist options
  • Save UsamaAshraf/b203c9348ed565fe3ac927c2a095e4e9 to your computer and use it in GitHub Desktop.
Save UsamaAshraf/b203c9348ed565fe3ac927c2a095e4e9 to your computer and use it in GitHub Desktop.
class ChatUser {
displayNewMessageNotification(newMessage) {
// Push an alert message or something.
}
// `chatroom` is an instance of EventEmitter.
connectToChatroom(chatroom) {
chatroom.on('message-received', this.displayNewMessageNotification);
}
disconnectFromChatroom(chatroom) {
chatroom.removeListener('message-received', this.displayNewMessageNotification);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment