daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 60 in 26 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MessageHandlerProvider {
  2.     constructor(messageHandlerMap = {}) {
  3.         this.messageHandlerMap = messageHandlerMap
  4.     }
  5.  
  6.     getHandler(channelName = '') {
  7.         // May throw if no key exists
  8.         let messageHandler = this.messageHandlerMap[channelName]
  9.        
  10.         // Optionally, you could have a default handler for unknown channels
  11.         if (messageHandler === undefined) {
  12.             let message = `No handler found for channel: "${channelName}"`
  13.             throw new Error(message)
  14.         } else {
  15.             return messageHandler
  16.         }
  17.     }
  18. }
RAW Paste Data
Top