Skip to content

@windy/Evented

Major Windy.com even emitter class. Used in @windy/broadcast, @windy/store and other parts of Windy.com where publish / subscribe pattern is used.

Enjoy, widely known methods like on, off, once and emit (if you are used to, you can also use trigger or fire).

Type parameters

Name
T

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Evented<T>(params): Evented<T>

Type parameters

Name
T

Parameters

NameType
paramsEventedInitParams

Returns

Evented<T>

Properties

fire

Optional fire: <K, Q>(topic: keyof T, ...data: TrimUndefinedFromRight<Arrayify<Q>>) => void

Same as emit method, just someone, who likes to use it.

Type declaration

▸ <K, Q>(topic, ...data): void

Same as emit method, just someone, who likes to use it.

Type parameters
NameType
Kextends string | number | symbol
QQ
Parameters
NameType
topickeyof T
...dataTrimUndefinedFromRight<Arrayify<Q>>
Returns

void


trigger

Optional trigger: <K, Q>(topic: keyof T, ...data: TrimUndefinedFromRight<Arrayify<Q>>) => void

Same as emit method, just someone, who likes to use it.

Type declaration

▸ <K, Q>(topic, ...data): void

Same as emit method, just someone, who likes to use it.

Type parameters
NameType
Kextends string | number | symbol
QQ
Parameters
NameType
topickeyof T
...dataTrimUndefinedFromRight<Arrayify<Q>>
Returns

void

Methods

emit

emit<K, Q>(topic, ...data): void

Emits a message accompanied from one to four arguments.

Type parameters

NameType
Kextends string | number | symbol
QQ

Parameters

NameTypeDescription
topickeyof TTopic to emit
...dataTrimUndefinedFromRight<Arrayify<Q>>Optional data

Returns

void


off

off(id): void

Unhooks registered callback, identified by provided id. Arguments can contain (topic: string, callback) pair OR just (id: number) LIMITATION: Subscriptions based on once method MUST be unsubscribed just by unique id

Parameters

NameType
idnumber

Returns

void

off<K, Q>(topic, callback, context?): void

Unhooks registered callback, identified by provided id. Arguments can contain (topic: string, callback) pair OR just (id: number) LIMITATION: Subscriptions based on once method MUST be unsubscribed just by unique id

Type parameters

NameType
Kextends string | number | symbol
QQ

Parameters

NameTypeDescription
topicK-
callback(...data: TrimUndefinedFromRight<Arrayify<Q>>) => voidCallback to be unsubscribed - ONLY if handle is topic name
context?ThisType<unknown>Optional context to change this binding

Returns

void


on

on<K, Q>(topic, callback, context?, once?): number

Hooks a callback, that will be triggerd on specified message.

Type parameters

NameType
Kextends string | number | symbol
QQ

Parameters

NameTypeDescription
topicKTopic to subscribe
callback(...data: TrimUndefinedFromRight<Arrayify<Q>>) => voidCallback called when topic is emitted
context?ThisType<unknown>Optional context to change this binding
once?booleanOptional if callback should be fired only once or at every time

Returns

number

Unsubscribe id


once

once<K, Q>(topic, callback, context?): number

Hooks a callback, that will be triggerd just once on specified message.

Type parameters

NameType
Kextends string | number | symbol
QQ

Parameters

NameTypeDescription
topicKTopic to subscribe
callback(...data: TrimUndefinedFromRight<Arrayify<Q>>) => voidCallback called when topic is emitted
context?ThisType<unknown>Optional context to change this binding

Returns

number

Unsubscribe id