Home Manual Reference Source Repository
import {Events} from '@loopmode/events/src/Events.js'
public class | source

Events

The Events class. Creates a single global event listener per type and target.

Usually, you want to use only one instance of this class. (Use the default export which is a singleton instance)

Static Member Summary

Static Public Members
public static

knownTargets: {"window": *, "document": *, "body": *}

An object containing "known targets" that are supported by default and for which shortcuts are added to the on nad off methods.

Constructor Summary

Public Constructor
public

Creates new instance.

Method Summary

Public Methods
public

addEventListener(type: *, listener: *, options: *): *

public

off(type: String, listener: Function, options: Object | Boolean)

Removes an event listener callback.

public

on(type: String, listener: Function, options: Object | Boolean): Object

Adds an event listener callback.

public

removeEventListener(type: *, listener: *, options: *): *

Static Public Members

public static knownTargets: {"window": *, "document": *, "body": *} source

An object containing "known targets" that are supported by default and for which shortcuts are added to the on nad off methods.

Public Constructors

public constructor() source

Creates new instance. Adds shortcuts to the on and off methods for all known targets.

Public Methods

public addEventListener(type: *, listener: *, options: *): * source

Params:

NameTypeAttributeDescription
type *
listener *
options *

Return:

*

public off(type: String, listener: Function, options: Object | Boolean) source

Removes an event listener callback. Removes the global event listener as well if the callback was the only one.

Params:

NameTypeAttributeDescription
type String

A case-sensitive string representing the event type to listen for.

listener Function

The event listener callback

options Object | Boolean
  • optional

An options object or a boolean capture flag

options.capture Boolean
  • optional

Whether to listen during the capturing phase

options.passive Boolean
  • optional

Whether to use a passive event listener

options.target Object | String
  • optional
  • default: window

The target element on which to add the event listener.

public on(type: String, listener: Function, options: Object | Boolean): Object source

Adds an event listener callback. Creates a global event listener if necessary. Returns an object with a dispose function that can be called without arguments to remove the event listener callback.

Params:

NameTypeAttributeDescription
type String

A case-sensitive string representing the event type to listen for.

listener Function

The event listener callback

options Object | Boolean
  • optional

An options object or a boolean useCapture flag

options.capture Boolean
  • optional

Whether to listen during the capturing phase

options.passive Boolean
  • optional

Whether to use a passive event listener

options.target Object | String
  • optional
  • default: window

The target element on which to add the event listener.

Return:

Object

An object with a dispose function.

public removeEventListener(type: *, listener: *, options: *): * source

Params:

NameTypeAttributeDescription
type *
listener *
options *

Return:

*