1.0.2 • Published 3 years ago

@skivy71/events v1.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
3 years ago

Simple Events bus

A lightweight events bus, for use in all JavaScript environments

Usage

var Events = require('@skivy71/events')

var uid = Events.$on('someEvent', (data) => {  // returns a uid, which can be used later, to remove the watcher
    console.log('someEvent', data)
})

Events.$off(uid) // remove the above watcher

Events.$once('someOtherEvent', (data) => { // automatically removed after the event handler is called
    console.log('someOtherEvent', data)
})

Events.$emit('someSillyEvent', 'someSillyData') // broadcast an event with data...

var events = { // this events object (and the Events.$watch method) derives the event name(s) from Object.keys(events)
    eventA(data) { // and the event handler from events[event]
        console.log('eventA', data)
    },
    eventB(data) {
        console.log('eventB', data)
    }
}

var uids = Events.$watch(events) // returns a list of uids, which can be used to remove later (as above)

Events.$unwatch(uids)
1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

5 years ago