0.1.3 • Published 2 years ago
@projectsophon/events v0.1.3
@projectsophon/events
This package contains a typed, single pub/sub pattern used in the Dark Forest game. Inspired by https://www.npmjs.com/package/monomitter
Installation
You can install this package using npm
or
yarn
by running:
npm install --save @projectsophon/events
yarn add @projectsophon/events
When using this in a plugin, you might want to load it with skypack
import * as events from 'http://cdn.skypack.dev/@projectsophon/events'
Table of contents
Classes
Type Aliases
Functions
Type Aliases
Callback
Ƭ Callback<T
>: (data
: T
) => Promise
<void
> | void
Type parameters
Name |
---|
T |
Type declaration
▸ (data
): Promise
<void
> | void
Parameters
Name | Type |
---|---|
data | T |
Returns
Promise
<void
> | void
Monomitter
Ƭ Monomitter<T
>: Object
Type parameters
Name |
---|
T |
Type declaration
Name | Type |
---|---|
clear | () => void |
publish | (data : T ) => Promise <void > |
subscribe | (cb : Callback <T >) => { unsubscribe : () => void } |
Subscription
Ƭ Subscription<T
>: (data
: T
) => Promise
<void
> | void
Type parameters
Name |
---|
T |
Type declaration
▸ (data
): Promise
<void
> | void
Parameters
Name | Type |
---|---|
data | T |
Returns
Promise
<void
> | void
Unsubscribe
Ƭ Unsubscribe: () => void
Type declaration
▸ (): void
Returns
void
Functions
monomitter
▸ monomitter<T
>(): Monomitter
<T
>
Constructs a new event emitter, whose purpose is to emit values of the given type.
Type parameters
Name |
---|
T |
Returns
Monomitter
<T
>