isao / eventstop

A minimal event library for Node.js and browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

eventstop

NPM version NPM downloads Build Status donate

Features

  • Modern
  • For Node.js and browsers
  • 300 bytes minified and gzipped

Install

yarn add eventstop

You can also use the UMD version via https://unpkg.com/eventstop

Usage

const EventStop = require('eventstop')

const event = new EventStop()

// subscribe an event
const unsubscribe = event.subscribe('ready', msg => {
  console.log('message:', msg)
})

event.emit('ready', 'hola')
//=> hola

// unsubscribe
unsubscribe()

API

.subscribe(event, handler)

Return a function which would execute unsubscribe(event, handler) when you call it.

.once(event, handler)

Like .subscribe but only trigger handler once.

event

Type: string

handler

Type: function

.emit(event, ...args)

event

Type: string

.unsubscribe(event, handler)

Same args to .subscribe

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

eventstop © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin

About

A minimal event library for Node.js and browser.

License:MIT License


Languages

Language:JavaScript 100.0%