Notify Reference
๐ฃ Minimalistic Pub/Sub implementation.
Usage
๐ฆ Node
Install @lou.codes/notify
as a dependency:
Import it and use it:
๐ฆ Deno
Import @lou.codes/notify
using the npm:
prefix, and use it directly:
๐ Browser
Import @lou.codes/notify
using esm.sh, and use it directly:
Useful links
- ๐ Documentation: TypeDoc generated documentation.
- โณ Changelog: List of changes between versions.
- โ Tests Coverage: Coveralls page with tests coverage.
Type Aliases
Emitter<Data>
Emitter function (when data is never
it doesnโt take any arguments).
Type parameters
Type parameter | Description |
---|---|
Data | Data type. |
EventListener<Data>
Event listener unary function.
See
Type parameters
Type parameter | Description |
---|---|
Data | Data type. |
EventRegistry<Events>
Registry of event names to array of listeners.
See
Example
Type parameters
Type parameter | Description |
---|---|
Events extends EventTypeDictionary | Event registry. |
EventTypeDictionary
Dictionary of event name to event types.
Example
See
Functions
broadcast()
Creates a new โbroadcastโ object, which has emit
and on
with a shared
eventRegistry
.
Type parameters
Type parameter | Description |
---|---|
Events extends Readonly <Record <string , unknown >> | Event registry. |
Parameters
Parameter | Type | Description |
---|---|---|
eventRegistry | EventRegistry <Events > | Optional record of event names mapped to an array of listeners. |
Returns
object
Object with emit
and on
functions.
Member | Type | Value |
---|---|---|
emit | <Event >(event : Event ) => Emitter <Events [Event ]> | โฆ |
on | <Event >(event : Event ) => (listener : EventListener <Events [Event ]>) => () => undefined | โฆ |
Example
emit()
Creates a curried function to emit events for listeners of the given
eventRegistry
.
Type parameters
Type parameter | Description |
---|---|
Events extends Readonly <Record <string , unknown >> | Event registry. |
Parameters
Parameter | Type | Description |
---|---|---|
eventRegistry | EventRegistry <Events > | Record of event names mapped to an array of listeners. |
Returns
Function
Curried function with eventRegistry
in context.
Creates a curried function to emit an event of the eventRegistry
in context.
Type parameters
Type parameter | Description |
---|---|
Event extends string | number | symbol | Event name. |
Parameters
Parameter | Type | Description |
---|---|---|
event | Event | Event name (has to be a valid key of the eventRegistry ). |
Returns
Emitter
<Events
[Event
]>
Curried function with eventRegistry
and event
in context.
Example
Example
on()
Creates a curried function to listen for calls to an event in the passed
eventRegistry
.
Type parameters
Type parameter | Description |
---|---|
Events extends Readonly <Record <string , unknown >> | Event registry. |
Parameters
Parameter | Type | Description |
---|---|---|
eventRegistry | EventRegistry <Events > | Record of event names mapped to an array of listeners. |
Returns
Function
Curried function with eventRegistry
in context.
Creates a curried function to listen for calls to an event of the
eventRegistry
in context.
Type parameters
Type parameter | Description |
---|---|
Event extends string | number | symbol | Event name. |
Parameters
Parameter | Type | Description |
---|---|---|
event | Event | Event name (has to be a valid key of the eventRegistry ). |
Returns
Function
Curried function with eventRegistry
and event
in context.
Parameters
Parameter | Type |
---|---|
listener | EventListener <Events [Event ]> |
Returns
Function
Returns
undefined