Signals

Module: Signals

Members

Fields & Properties
Methods
Dispatch and watch custom events.
Example
import {Signals} from 'fenix-tools'

const dispatcher = Signals()
Author:
  • FeniXEngine Contributors
License:

(require("Signals"))() → {dispatcher}

Signals will return a dispatcher client to use for adding and watching custom events.
Example
import {Dispatcher} from 'fenix-tools'

const dispatcher = Signals()
// Emit the signal event
dispatcher.emit('my-event', eventData)

// Do something when the signal event is emitted
dispatcher.on('my-event', (eventData) => {
  // Perform actions with eventData
})

// Remove the signal event
dispatcher.remove('my-event')
Returns
Type
dispatcher

Members

(protected, static, constant) _events :array

An array that stores all custom events created by the dispatcher

(inner) dispatcher

Dispatcher interface is returned when creating a Signal client via Signals()
Properties:
Name Type Description
on function Adds a custom signal event.
emit function Emits a custom signal event by calling the events handler.
remove function Removes a custom signal event.

Methods

emit(name, args)

Emits a signal, calling the events handler when doing so. (see: dispatcher)
Example
dispatcher.emit('my-event', someData)
Parameters
Name Type Description
name * The name of the signal event
args * Arguments to pass through to the signal events handler.

on(name, handler, context)

Adds a custom signal event to the array. (see: dispatcher)
Example
dispatcher.on('my-event', (args) => {
  // Perform some actions when event is called
})
Parameters
Name Type Description
name string The name you'd like to call this signal
handler callback A function which is called when signal is emitted.
context context The context in which to run the callback function

remove(name)

Removes a signal form the events (see: dispatcher)
Example
dispatcher.remove('my-event')
Parameters
Name Type Description
name * The name of the signal event