Emitter
essential

Utility class to be used when implementing event-based APIs that
allows for handlers registered via ::on to be invoked with calls to
::emit. Instances of this class are intended to be used internally by
classes that expose an event-based API.

Register the given handler function to be invoked before all
other handlers existing at the time of subscription whenever events by the
given name are emitted via ::emit.

Use this method when you need to be the first to handle a given event. This
could be required when a data structure in a parent object needs to be
updated before third-party event handlers registered on a child object via a
public API are invoked. Your handler could itself be preempted via
subsequent calls to this method, but this can be controlled by keeping
methods based on ::preempt private.

Argument

Description

eventName

String naming the event that you want to invoke the handler when emitted.