Mirror Engine
V7
How To
Mirror Engine Logo

Mirror Engine API


Mirror Engine API / EventHandle

Class: EventHandle

Event Handle that is created by EventHandler and can be used for easier event removal and management.

Examples

const evt = obj.on('test', (a, b) => {
  console.log(a + b)
})
obj.fire('test')

evt.off() // easy way to remove this event
obj.fire('test') // this will not trigger an event
// store an array of event handles
let events = []

events.push(objA.on('testA', () => {}))
events.push(objB.on('testB', () => {}))

// when needed, remove all events
events.forEach((evt) => {
  evt.off()
})
events = []

Constructors

new EventHandle()

new EventHandle(
   handler: EventHandler,
   name: string,
   callback: HandleEventCallback,
   scope: any,
   once?: boolean): EventHandle

Parameters

handler

EventHandler

source object of the event.

name

string

Name of the event.

callback

HandleEventCallback

Function that is called when event is fired.

scope

any

Object that is used as this when event is fired.

once?

boolean = false

If this is a single event and will be removed after event is fired.

Returns

EventHandle

Methods

off()

off(): void

Remove this event from its handler.

Returns

void

Mirror Engine Logo