0.1.6 • Published 10 years ago
havana-event v0.1.6
Havana event
A simple publish/subscribe pattern.
How to install
npm install havana-eventHow to use
At it's most basic:
import Event from 'havana-event';
const event = new Event();
event.subscribe( 'createWorld', () => {
console.log( 'hello world' );
});
event.publish( 'createWorld' );A slightly more complex example:
import Event from 'havana-event';
const event = new Event();
const token = event.subscribe( 'personBorn', data => {
console.log( `hello ${data.name}` );
});
event.publish( 'personBorn', {
'name': 'Colin'
});
event.unsubscribe( token );ES2015+
Havana event is written using ES2015+ syntax.
However, by default this module will use an ES5 compatible file that has been compiled using Babel.
In the dist directory there are four files, the default
is event.server.js. The default when using a client-side
bundler that supports the
browser field
spec is event.browser.js.
Havana event currently requires the
Babel polyfill.
You are expected to supply this yourself. However, as a
courtesy you will also find event.server.with-polyfill.js
and event.browser.with-polyfill.js in the dist
directory.