text: import Validate from '../Validate';
  import SPEventManager from './SPEventManager';
  /**
   * Represents a framework event that components can subscribe to.
   *
   * @remarks
   * Examples of events in a web application might include: the user clicking a button, the system navigating to
   * another page, or an item being added/removed from an abstract collection.  The SharePoint Framework
   * represents events using instances of the SPEvent object, one for each kind of event.  The SPEvent object
   * is typically exposed as a property of an associated class (e.g. the button that can be clicked).
   * When a component is interested in an event, it calls add() to register an event handler callback that
   * will be invoked each time the event occurs.  The handler receives an SPEventArgs parameter that may
   * provide additional details about what happened.  This is analogous to the browser's Document Object Model
   * (DOM) events.  The main difference is the ISPEventObserver feature, which tracks which component subscribed
   * to each event, and automatically unsubscribes the handler when the component is disposed.
   *
   * When an event is raised, all handlers are invoked synchronously.  The order in which event handlers
   * are called is unspecified.  The event handler callback must catch any exceptions that occur during
   * processing; an uncaught exception will not prevent other handlers from executing, but it will be
   * reported as a problem with the associated component.
   *
   * @public
   */
  var SPEvent = /** @class */ (function () {
      /**
       * @internal
       */
      function SPEvent(name) {
          Validate.isNonemptyString(name, 'name');
          this._name = name;
      }
      /**
       * Registers a callback that will be invoked whenever the event occurs.
       *
       * @remarks
       * The same object can add multiple event handlers to the same event. Since BaseComponent implements
       * the ISPEventObserver interface, a web part or extension can pass itself as the observer. This will cause
       * the event handler to be automatically unsubscribed when the web part or extension is disposed.
       *
       * @param observer - Indicates the object that is subscribing to the event: When the object is disposed,
       *   the event handler will be automatically removed.  This object is also used for diagnostic purposes,
       *   e.g. detecting if the event handler failed to catch an exception.
       * @param eventHandler - A callback function that will be invoked whenever the event occurs
       */
      SPEvent.prototype.add = function (observer, eventHandler) {
          Validate.isNotNullOrUndefined(observer, 'component');
          Validate.isNotNullOrUndefined(eventHandler, 'eventHandler');
          SPEventManager.instance.registerEvent(this._name, observer, eventHandler);
      };
      /**
       * Unregisters a callback that was registered using add().
       *
       * @remarks
       * If the event handler has already been removed, or if it was never added, then this
       * method has no effect.
       *
       * @param observer - This must be the same observer that was passed to the add() function.
       * @param eventHandler - The event handler to remove; this must be the same object instance
       *   that was passed to the add() function.
       */
      SPEvent.prototype.remove = function (observer, eventHandler) {
          Validate.isNotNullOrUndefined(observer, 'component');
          Validate.isNotNullOrUndefined(eventHandler, 'eventHandler');
          SPEventManager.instance.unregisterEvent(this._name, observer, eventHandler);
      };
      /**
       * Returns the number of listeners to the event
       * @internal
       */
      SPEvent.prototype._listenerCount = function () {
          return SPEventManager.instance._listenerCount(this._name);
      };
      return SPEvent;
  }());
  export default SPEvent;
  //# sourceMappingURL=SPEvent.js.map