Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Events

The 'Events' is the class for creating event listeners.

example:
const events = new Events();


const eventId = events.on('test', (arg1, arg2, arg3) => {

    console.log(arg1, arg2, arg3);

});


events.trigger('test', [1, 2, {srt: 'string'}]); // console: 1 2 {srt: "string"}

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

Private events

events: Map<string, Map<number, (...args: any[]) => void>> = ...

Private namesByIds

namesByIds: Map<number, (string | number)[]> = ...

Private onceEvents

onceEvents: Map<string, Set<(...args: any[]) => void>> = ...

Methods

clear

  • clear(): void

off

  • off(id: number): boolean
  • Unsubscribes the callback function from the given event name.

    Parameters

    • id: number

    Returns boolean

    True if the event was successfully unsubscribed, otherwise false

on

  • on(name: string, callback: (...args: any[]) => void): number
  • Subscribes the callback function to the given event name.

    Parameters

    • name: string
    • callback: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns number

    The id of the event

once

  • once(name: string, callback: (...args: any[]) => void): void
  • Subscribes the callback function to the given event name for one time.

    Parameters

    • name: string
    • callback: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns void

trigger

  • trigger(name: string, args?: any[]): void
  • Triggers all the callbacks subscribed to the given name.

    Parameters

    • name: string
    • args: any[] = []

    Returns void

Generated using TypeDoc