O3hEvent interface

Interface to listen for distinct events being triggered on an object

Signature:

export interface O3hEvent<TArgs extends readonly any[]> 

Properties

PropertyModifiersTypeDescription
namereadonlystringThe identifier of the event, unique for all events on an object

Methods

MethodDescription
add(handler)Adds a callback that's called when this event is triggered
clear()Removes all handlers previously added to this event, allowing it to be safely nulled out
remove(handler)Remove a callback that was previously added via O3hEvent.add() so that it will not be called when this event is triggered in the future

O3hEvent.add() method

Adds a callback that's called when this event is triggered

Signature:

add(handler: O3hEventHandler<TArgs>): void;

Parameters

ParameterTypeDescription
handlerO3hEventHandler<TArgs>A function to be called when the event is raised.

Returns:

void

Exceptions

Throws an error if the parameter is not a function.

Remarks

In your event handler function, this will be undefined when triggered by an event. If you need access to this in the callback function, consider using an arrow function, or wrapping the callback in Function.bind().

Example

class Example {
    constructor(replayPlayer) {
        replayPlayer.timedEvent.add(this.onTimedEvent.bind(this));
        // OR
        replayPlayer.timedEvent.add((event) => this.onTimedEvent(event));
    }
    onTimedEvent(timedEvent) {
        this.update(timedEvent.Data);
    }
    update(data) {
        // do stuff with the event
    }
}

O3hEvent.clear() method

Removes all handlers previously added to this event, allowing it to be safely nulled out

Signature:

clear(): void;

Returns:

void

O3hEvent.name property

The identifier of the event, unique for all events on an object

Signature:

readonly name: string;

O3hEvent.remove() method

Remove a callback that was previously added via O3hEvent.add() so that it will not be called when this event is triggered in the future

Signature:

remove(handler: O3hEventHandler<TArgs>): void;

Parameters

ParameterTypeDescription
handlerO3hEventHandler<TArgs>The same function reference as was added to this event

Returns:

void