havana-event
v0.1.6
Published
A simple publish/subscribe pattern
Downloads
6
Maintainers
Readme
Havana event
A simple publish/subscribe pattern.
How to install
npm install havana-event
How 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.