eventmonger

5.0.0 • Public • Published

EventMonger is a dead simple event system.

I didnt like a lot of the syntax for classical event system, so presto.

var { Event, emit, on, off, once, when, clear } = require('eventmonger')
// or
import { Event, emit, on, off, once, when, clear } from 'eventmonger'

let sampleEvent = Event()

let callback = name => console.log("hello ", name, "!")

// register a callback on an event
// note: returns the callback
on(sampleEvent, callback)

// remove a callback from an event
// note: returns the callback
off(sampleEvent, callback)

// once will return a promise that will resolve once the event if fired
once(sampleEvent).then(data => console.log(data))

// fire off the event!
// note: events can only have one paramter
emit(sampleEvent, "world")

// you can use 'when' to filter a callback!
on(sampleEvent, when(name => name == "world", name => console.log("hello world")))

// you can use clear, to well, clear all the callbacks from an Event
// note: returns the event
clear(sampleEvent)

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 5.0.0
    1
    • latest

Version History

Package Sidebar

Install

npm i eventmonger

Weekly Downloads

1

Version

5.0.0

License

ISC

Unpacked Size

3.66 kB

Total Files

4

Last publish

Collaborators

  • felixmo42