This package contains a typed, single pub/sub pattern used in the Dark Forest game. Inspired by https://www.npmjs.com/package/monomitter
npm install @darkforest_eth/eventsThis package contains a typed, single pub/sub pattern used in the Dark Forest game.
Inspired by https://www.npmjs.com/package/monomitter
You can install this package using npm oryarn by running:
``bash`
npm install --save @darkforest_eth/events
`bash`
yarn add @darkforest_eth/events
When using this in a plugin, you might want to load it with skypack
`js`
import * as events from 'http://cdn.skypack.dev/@darkforest_eth/events';
- Callback
- Monomitter
- Subscription
Ƭ Callback<T\>: (data: T) => void
#### Type parameters
| Name |
| :--- |
| T |
#### Type declaration
▸ (data): void
##### Parameters
| Name | Type |
| :----- | :--- |
| data | T |
##### Returns
void
---
Ƭ Monomitter<T\>: Object
#### Type parameters
| Name |
| :--- |
| T |
#### Type declaration
| Name | Type |
| :---------- | :----------------------------------------------------------------------------------------- |
| clear | () => void |publish
| | (data: T) => void |subscribe
| | (cb: Callback<T\>) => Subscription |
---
Ƭ Subscription: Object
#### Type declaration
| Name | Type |
| :------------ | :----------- |
| unsubscribe | () => void |
▸ 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
| Name | Type | Default value | Description |
| :---------------------- | :-------- | :------------ | :----------------------------------------------------------------------------------------------- |
| emitLatestOnSubscribe | boolean | false | if this is true, upon subscription immediately emit the most recently set value, if there is one |
#### Returns
Monomitter<T`\>