Class: Event

Event

An instance of this class represents an event that describes some change in state or proposed change in state in the system.

Constructor

new Event(eventData)

Create a new Event.
Parameters:
Name Type Description
eventData Object
Properties
Name Type Attributes Default Description
informational boolean <optional>
false True to mark this event as information. That is, no action can be taken by listeners to affect the event.
payload * <optional>
Data associated with this event from the entity that triggered the event.
type string Type of event to fire.
Since:
  • 0.0.0
Source:
Example
// create a new event
const event = new Event({
   type: 'add',
   payload: {
      id: 0,
      name: 'my file.txt'
      item: someBlob
   }
})

Members

(readonly) cancelled :boolean

True if the event was cancelled. Event listeners must short-circuit and not perform any intended action associated with an event if it has been cancelled. Also note that return values for subsequent listeners are ignored once the event has been cancelled.
Type:
  • boolean
Since:
  • 0.0.0
Source:

(readonly) informational :boolean

True if the event is informational. False if it is actionable.
Type:
  • boolean
Since:
  • 0.0.0
Source:

(readonly) payload :*

Data associated with this event from the entity that triggered the event. Do NOT mutate the value of this property. Instead, create a deep copy and mutate the copy.
Type:
  • *
Since:
  • 0.0.0
Source:

(readonly) result :Object|Array|undefined

Data provided by the previous event handler. In many, if not most cases, this result value, which matches the return value of the most recent event listener, replaces the payload specified by the creator of the event. Lack of a result indicates that the data provided by the event creator is in effect and will be considered by all listeners responding to the event. In other words, listeners that want to affect the data associated with this event must clone the payload, make appropriate changes, and then return this modified copy. Exceptional events where this logic is not followed should be documented. Do NOT mutate the value of this property. Instead, create a deep copy and mutate the copy.
Type:
  • Object | Array | undefined
Since:
  • 0.0.0
Source:

(readonly) type :string

Type of this event.
Type:
  • string
Since:
  • 0.0.0
Source:

Methods

cancel()

Marks this event as cancelled. When an event is cancelled, the event will continue to bubble up through the list of registered listeners, but the action associated with the event must no longer occur. For example, if the "add" event is cancelled, the item to be added must not actually be added to the system, but the "add" event will continue to reach all subsequent listeners. Return values from subsequent listeners will be ignored for cancelled events as well. Another use case for cancelling an event - a listener that has already performed the action associated with the event and want to prevent any subsequent listeners from performing any further actions.
Since:
  • 0.0.0
Source: