Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eventuate

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventuate

Handle events without emitters

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

eventuate

NPM version Build Status Coverage Status

Handle events without emitters. If we had to do it all over again, we might do it this way...

example

var eventuate = require('eventuate'),
    assert    = require('assert')

// create an event type, let us call it request
// kind of like an EventEmitter for a single event type
var request = eventuate()

// consume all requests (think .on)
function onRequest (req) {
    // do something
}
request(onRequest)

// make sure someone is listening
assert(request.hasConsumer)

// produce an event
request.produce({ url: '/test' })

// remove our consumer
request.removeConsumer(onRequest)

api

var eventuate = require('eventuate')

var event = eventuate(options)

Create an object, event, that represents a consumable event type.

Valid options are:

  • requireConsumption - throw an error if a produced event is not consumed, useful for error producers
  • monitorConsumers - [default: true] true or false, see "unmonitored eventuate" below

event(consumer)

Consume events with the consumer function, which should have the signature function (data) {}. When an event is produced, it will be passed to the consumer function as the first and only argument.

event.produce(data)

Produce an event. All event consumer functions will be called with data. If the requireConsumption option was provided, and nothing consumes the data, an error will be thrown.

event.removeConsumer(consumer)

Remove the formerly added consumer, so that it will not be called with future produced events.

event.hasConsumer

Property containing value true or false, indicating whether or not the event has a consumer.

event.consumers

Property exposing a shallow copy of all consuming functions.

event.consumerAdded(consumer)

Unmonitored eventuate representing additions of consumers. Any consumers of consumerAdded will be invoked with the consumer added to the eventuate.

Example:

var event = eventuate()
event.consumerAdded(function (eventConsumer) {
    // eventConsumer will be the consumer function
    console.log('a consumer was added to event')
})

event.consumerRemoved(consumer)

Unmonitored eventuate representing removal of consumers. Any consumers of consumerRemoved will be invoked with the consumer removed from the eventuate.

Example:

var event = eventuate()
event.consumerRemoved(function (eventConsumer) {
    // eventConsumer will be the consumer function
    console.log('a consumer was removed from event')
})

unmonitored eventuate

If the eventuate is created with the option monitorConsumers set to false, the eventuate will not have the following properties: consumers, hasConsumer, consumerRemoved, consumerAdded. No events will be triggered when consumers are manipulated. This is used internally within eventuate for sub-events such as consumerRemoved and consumerAdded.

install

npm install eventuate

testing

npm test [--dot | --spec] [--grep=pattern]

Specifying --dot or --spec will change the output from the default TAP style. Specifying --grep will only run the test files that match the given pattern.

coverage

npm run coverage [--html]

This will output a textual coverage report. Including --html will also open an HTML coverage report in the default browser.

Keywords

FAQs

Package last updated on 28 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc