1.0.0 • Published 1 year ago

boring-event-emitter v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

meet (boring-event-emitter)

CD CI codecov npm version semantic-release

A boring typed event emitter library.

Install

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

Usage

// 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

Options

mett accept the following options:

  • initialValue the initialValue of the event emitter. Will be emitted on the listen if replayLast is true.
  • replayLast emit to newly added listener the lastEmittedValue.