@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
| Name | Type |
|---|---|
params | EventedInitParams |
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
| Name | Type |
|---|---|
K | extends string | number | symbol |
Q | Q |
Parameters
| Name | Type |
|---|---|
topic | keyof T |
...data | TrimUndefinedFromRight<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
| Name | Type |
|---|---|
K | extends string | number | symbol |
Q | Q |
Parameters
| Name | Type |
|---|---|
topic | keyof T |
...data | TrimUndefinedFromRight<Arrayify<Q>> |
Returns
void
Methods
emit
▸ emit<K, Q>(topic, ...data): void
Emits a message accompanied from one to four arguments.
Type parameters
| Name | Type |
|---|---|
K | extends string | number | symbol |
Q | Q |
Parameters
| Name | Type | Description |
|---|---|---|
topic | keyof T | Topic to emit |
...data | TrimUndefinedFromRight<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
| Name | Type |
|---|---|
id | number |
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
| Name | Type |
|---|---|
K | extends string | number | symbol |
Q | Q |
Parameters
| Name | Type | Description |
|---|---|---|
topic | K | - |
callback | (...data: TrimUndefinedFromRight<Arrayify<Q>>) => void | Callback to be unsubscribed - ONLY if handle is topic name |
context? | ThisType<unknown> | Optional context to change this binding |
Returns
void
offAll
▸ offAll(): void
Unhooks all registered callbacks
Returns
void
on
▸ on<K, Q>(topic, callback, context?, once?): number
Hooks a callback, that will be triggerd on specified message.
Type parameters
| Name | Type |
|---|---|
K | extends string | number | symbol |
Q | Q |
Parameters
| Name | Type | Description |
|---|---|---|
topic | K | Topic to subscribe |
callback | (...data: TrimUndefinedFromRight<Arrayify<Q>>) => void | Callback called when topic is emitted |
context? | ThisType<unknown> | Optional context to change this binding |
once? | boolean | Optional 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
| Name | Type |
|---|---|
K | extends string | number | symbol |
Q | Q |
Parameters
| Name | Type | Description |
|---|---|---|
topic | K | Topic to subscribe |
callback | (...data: TrimUndefinedFromRight<Arrayify<Q>>) => void | Callback called when topic is emitted |
context? | ThisType<unknown> | Optional context to change this binding |
Returns
number
Unsubscribe id