respond( data ) {
    const { published, options, responseHandler, responsesReceived } = this;
    const { name, type, maxResponses, globalResponse } = options;

    /* Check that this event has been published */
    if ( !published ) {
      throw new EventBusException( 'You cannot respond to an event that has not been published' );
    }

    /* Check that responses are allowed to this type of event */
    if ( type !== EventType.REQRES ) {
      throw new EventBusException( 'You cannot respond to an event that is not a REQRES event' );
    }

    /* Drop the response if we have exceeded the maximum number of responses */
    if ( maxResponses !== -1 && responsesReceived >= maxResponses ) {
      return;
    }

    /* Check whether this is a global response */
    if ( globalResponse ) {
      /* Define the response event */
      EventBus.defineEvent( `${name}_RESPONSE` );

      /* Create a new event */
      const responseEvent = new Event({
        name: `${name}_RESPONSE`,
        data,
      });

      /* Publish the event */
      responseEvent.publish();
    } else {
      /* Check that a response handler is in place */
      if ( !responseHandler ) {
        throw new EventBusException( 'Cannot respond to an event that does not have a response handler' );
      }

      /* Call the response handler with the provided data */
      responseHandler( data );
    }

    /* Increment responses received */
    this.responsesReceived = this.responsesReceived + 1;
  }
/* Creates a response for the event */
Creates a response for the event
Creates a response for the event
respond( data ) {
    const { published, options, responseHandler, responsesReceived } = this;
    const { name, type, maxResponses, globalResponse } = options;
    if ( !published ) {
      throw new EventBusException( 'You cannot respond to an event that has not been published' );
    }
    if ( type !== EventType.REQRES ) {
      throw new EventBusException( 'You cannot respond to an event that is not a REQRES event' );
    }
    if ( maxResponses !== -1 && responsesReceived >= maxResponses ) {
      return;
    }
    if ( globalResponse ) {
      EventBus.defineEvent( `${name}_RESPONSE` );
      const responseEvent = new Event({
        name: `${name}_RESPONSE`,
        data,
      });
      responseEvent.publish();
    } else {
      if ( !responseHandler ) {
        throw new EventBusException( 'Cannot respond to an event that does not have a response handler' );
      }
      responseHandler( data );
    }
    this.responsesReceived = this.responsesReceived + 1;
  }
respond ( data ) { const { published , options , responseHandler , responsesReceived } = this ; const { name , type , maxResponses , globalResponse } = options ; if ( ! published ) { throw new EventBusException ( 'You cannot respond to an event that has not been published' ) ; } if ( type !== EventType . REQRES ) { throw new EventBusException ( 'You cannot respond to an event that is not a REQRES event' ) ; } if ( maxResponses !== - 1 && responsesReceived >= maxResponses ) { return ; } if ( globalResponse ) { EventBus . defineEvent ( ` ${ name } ` ) ; const responseEvent = new Event ( { name : ` ${ name } ` , data , } ) ; responseEvent . publish ( ) ; } else { if ( ! responseHandler ) { throw new EventBusException ( 'Cannot respond to an event that does not have a response handler' ) ; } responseHandler ( data ) ; } this . responsesReceived = this . responsesReceived + 1 ; }
Creates a response for the event
Creates a response for the event
/* Check that this event has been published */ /* Check that responses are allowed to this type of event */ /* Drop the response if we have exceeded the maximum number of responses */ /* Check whether this is a global response */ /* Define the response event */ /* Create a new event */ /* Publish the event */ /* Check that a response handler is in place */ /* Call the response handler with the provided data */ /* Increment responses received */