Class: SimpleEventDispatcher

SimpleEventDispatcher()

Simple implementation of an event dispatcher that supports the registration of multiple listeners for various events. Although this type can be used on its own, it is often more convenient to extend it.

This type is designed to have (loose) consistency with the DOM EventTarget, however events are simply dispatched to listeners in the order they are registered. I.e. there is no support for bubbling, cancelling, etc.

Constructor

new SimpleEventDispatcher()

Default constructor.

Source:

Classes

SimpleEvent

Methods

(private, static) processType(type)

Utility function to validate an event type string, and convert it to a consistent case.

Parameters:
Name Type Description
type string

An event type string.

Source:
Throws:
  • If type is not defined or is a zero-length string.

    Type
    ReferenceError
  • If type is not a string.

    Type
    TypeError
Returns:

The given type converted to a consistent case.

addEventListener(type, listener, useCaptureopt)

Adds the given listener for the given event type, provided it is not already registered for that type.

Parameters:
Name Type Attributes Default Description
type string

Event type for which the given listener is to be registered.

listener SimpleEventListener | function

Listener to register.

useCapture boolean <optional>
false

Optional parameter added for consistency with the standard DOM EventTarget.addEventListener definition. If not Nothing, will print a warning on the console.

Source:
Throws:
  • If type is not defined or is a zero-length string; if listener is not defined.

    Type
    ReferenceError
  • If type is not a string; if listener does not implement SimpleEventListener or is not a function.

    Type
    TypeError

dispatchEvent(event)

Dispatches the given event to registered listeners. Listeners are called in the order they are added.

Parameters:
Name Type Description
event SimpleEventIntf

Event to dispatch.

Source:
Throws:
  • If event is not defined.

    Type
    ReferenceError
  • If event does not implement SimpleEventIntf.

    Type
    TypeError

removeEventListener(type, listener, useCaptureopt)

Removes the given listener for the given event type, provided it is currently registered for that type.

Parameters:
Name Type Attributes Default Description
type string

Event type for which the given listener is to be removed.

listener SimpleEventListener | function

Listener to be removed.

useCapture boolean <optional>
false

Optional parameter added for consistency with the standard DOM EventTarget.removeEventListener definition. If not Nothing, will print a warning on the console.

Source:
Throws:
  • If type is not defined or is a zero-length string.

    Type
    ReferenceError
  • If type is not a string.

    Type
    TypeError