eventHandler()

in src/Package.ts [170:184]


  eventHandler(eventName: string, handlerFactory: FactoryDef) {

    if ( typeof eventName !== 'string' ) {
      throw new Error('You must provide a string identifying the type of event to handle');
    }
    if (typeof handlerFactory !== 'function' ) {
      throw new Error('handlerFactory must be a function.\nGot "' + typeof handlerFactory + '"');
    }

    const handlers = this.handlers[eventName] = this.handlers[eventName] || [];
    const handlerName = handlerFactory.name || (this.name + '_' + eventName + '_' + handlers.length);
    this.factory(handlerName, handlerFactory);
    handlers.push(handlerName);
    return this;
  }