[]
        
(Showing Draft Content)

Event Class

Event Class

Represents an event.

Wijmo events are similar to .NET events. Any class may define events by declaring them as fields. Any class may subscribe to events using the event's addHandler method and unsubscribe using the removeHandler method.

Wijmo event handlers take two parameters: sender and args. The first is the object that raised the event, and the second is an object that contains the event parameters.

Classes that define events follow the .NET pattern where for every event there is an on[EVENTNAME] method that raises the event. This pattern allows derived classes to override the on[EVENTNAME] method and handle the event before and/or after the base class raises the event. Derived classes may even suppress the event by not calling the base class implementation.

For example, the TypeScript code below overrides the onValueChanged event for a control to perform some processing before and after the valueChanged event fires:

// override base class
onValueChanged(e: EventArgs) {
  // execute some code before the event fires
  console.log('about to fire valueChanged');
  // optionally, call base class to fire the event
  super.onValueChanged(e);
  // execute some code after the event fired
  console.log('valueChanged event just fired');
}

Type parameters

  • S

  • T

Heirarchy

  • Event

Constructors

constructor

  • new Event(handlersChanged?: Function): Event
  • Initializes a new instance of an Event.

    Parameters

    • Optional handlersChanged: Function

      Optional callback invoked when handlers are added or removed from this Event.

    Returns Event

Properties

handlerCount

handlerCount: number

Gets the number of handlers added to this event.

hasHandlers

hasHandlers: boolean

Gets a value that indicates whether this event has any handlers.

Methods

addHandler

  • addHandler(handler: IEventHandler<S, T>, self?: any): void
  • Adds a handler to this event.

    Parameters

    • handler: IEventHandler<S, T>

      Function invoked when the event is raised.

    • Optional self: any

      Object that defines the event handler (accessible as 'this' from the handler code).

    Returns void

getHandler

  • getHandler(index?: number): IEventHandler | void
  • Gets a handler to this event.

    Parameters

    • Optional index: number

      Desired handle index number, this is usually zero.

    Returns IEventHandler | void

raise

  • Raises this event, causing all associated handlers to be invoked.

    Parameters

    • sender: any

      Source object.

    • Optional args: EventArgs

      Event parameters.

    Returns void

removeAllHandlers

  • removeAllHandlers(): void
  • Removes all handlers associated with this event.

    Returns void

removeHandler

  • removeHandler(handler: IEventHandler<S, T>, self?: any): void
  • Removes a handler from this event.

    Parameters

    • handler: IEventHandler<S, T>

      Function invoked when the event is raised.

    • Optional self: any

      Object that owns the event handler (accessible as 'this' from the handler code).

    Returns void