A boring typed event emitter library.
This project uses node and npm. Go check them out if you don't have them locally installed.
npm install --save mett
# or
yarn add mett
// using ES6 modules
import mett from 'boring-event-emitter'
// using CommonJS modules
const mett = require('boring-event-emitter')
Create a single-event event emitter.
import mett from 'boring-event-emitter'
// create a new event with numeric values
const event = mett<number>()
// listen to an event
const dispose = event.listen((value) => console.log(`value is ${value}`))
// dispose a listener
dispose()
// emit a value
event.emit(1)
// read the last emitted value
const currentValue = event.lastEmittedValue
mett
accept the following options:
initialValue
the initialValue of the event emitter. Will be emitted on the listen ifreplayLast
istrue
.replayLast
emit to newly added listener thelastEmittedValue
.