0.0.6 • Published 1 year ago

@df0/events v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

@df0/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 @df0/events
yarn add @df0/events

When using this in a plugin, you might want to load it with skypack

import * as events from 'http://cdn.skypack.dev/@df0/events';

Table of contents

Type Aliases

Functions

Type Aliases

Callback

Ƭ Callback<T>: (data: T) => void

Type parameters

Name
T

Type declaration

▸ (data): void

Parameters
NameType
dataT
Returns

void


Monomitter

Ƭ Monomitter<T>: Object

Type parameters

Name
T

Type declaration

NameType
clear() => void
publish(data: T) => void
subscribe(cb: Callback<T>) => Subscription

Subscription

Ƭ Subscription: Object

Type declaration

NameType
unsubscribe() => void

Functions

monomitter

monomitter<T>(emitLatestOnSubscribe?): Monomitter<T>

Constructs a new event emitter, whose purpose is to emit values of the given type.

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
emitLatestOnSubscribebooleanfalseif this is true, upon subscription immediately emit the most recently set value, if there is one

Returns

Monomitter<T>