@totallyinformation/ti-common-event-handler

1.0.1 • Public • Published

ti-common-event-handler

A common, shared event handler used across multiple TotallyInformation packages. Implemented as a singleton class.

Uses the enhanced EventEmitter2 library for improved performance and support of wildcards

Installation

npm install @totallyinformation/ti-common-event-handler

Use as

const tiEvents = require('@totallyinformation/ti-common-event-handler')

const aDataVar = {
    some: 'data'
}

tiEvents.emit('my-event-name', aDataVar)

// NB: Don't use arrow functions if you want to be able to access event name
tiEvents.on('my-event-name', function(data) {
    console.log(`Event ${this.event} triggered: `, data)
})

Event name wildcards

* and ** can be used as wildcards when creating event listeners. ** will look down all sub-namespaces.

/ is pre-configured as the namespace separator so as to match the equivalent in MQTT topics.

See the EventEmitter2 node for details.

Current usage

Dependencies

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    413
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    413
  • 1.0.0
    9

Package Sidebar

Install

npm i @totallyinformation/ti-common-event-handler

Weekly Downloads

422

Version

1.0.1

License

Apache-2.0

Unpacked Size

26.3 kB

Total Files

7

Last publish

Collaborators

  • totallyinformation