0.1.3 • Published 2 years ago

@projectsophon/events v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@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
NameType
dataT
Returns

Promise<void> | void


Monomitter

Ƭ Monomitter<T>: Object

Type parameters

Name
T

Type declaration

NameType
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
NameType
dataT
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>