Home Reference Source
import {EventHandler} from '@osjs/common/src/event-handler.js'
public class | source

EventHandler

Direct Subclass:

BasicApplication, CoreBase

A standards compatible event handler (observer) with some sugar.

Constructor Summary

Public Constructor
public

Create Event Handler

Member Summary

Public Members
public

Registered events

public

The name of the handler

Method Summary

Public Methods
public

Destroys all events

public

emit(name: String | String[], args: *): EventHandler

Emits an event

public

off(name: String | String[], callback: Function, force: boolean): EventHandler

Removes an event handler

public

on(name: String | String[], callback: Function, options: Object): EventHandler

Add an event handler

Public Constructors

public constructor(name: String) source

Create Event Handler

Params:

NameTypeAttributeDescription
name String
  • optional

A name for logging

Public Members

public events: Object source

Registered events

public name: String source

The name of the handler

Public Methods

public destroy() source

Destroys all events

public emit(name: String | String[], args: *): EventHandler source

Emits an event

You can supply an array of event names or a comma separated list with a string

Params:

NameTypeAttributeDescription
name String | String[]

Event name

args *
  • optional

Arguments

Return:

EventHandler

Returns current instance

public off(name: String | String[], callback: Function, force: boolean): EventHandler source

Removes an event handler

If no callback is provided, all events bound to given name will be removed.

You can supply an array of event names or a comma separated list with a string

Params:

NameTypeAttributeDescription
name String | String[]

Event name

callback Function
  • optional

Callback function

force boolean
  • optional
  • default: false

Forces removal even if set to persis

Return:

EventHandler

Returns current instance

public on(name: String | String[], callback: Function, options: Object): EventHandler source

Add an event handler

You can supply an array of event names or a comma separated list with a string

Params:

NameTypeAttributeDescription
name String | String[]

Event name

callback Function

Callback function

options Object
  • optional

Options

options.persist boolean
  • optional

This even handler cannot be removed unless forced

Return:

EventHandler

Returns current instance