ubud

A simple publish/subscribe pattern

Usage no npm install needed!

<script type="module">
  import ubud from 'https://cdn.skypack.dev/ubud';
</script>

README

Ubud

Build Status

A simple publish/subscribe pattern.

How to install

npm install ubud

How to use

At it's most basic:

var Ubud = require( 'ubud' );

var event = new Ubud();

event.subscribe( 'createWorld', function () {
  console.log( 'hello world' );
});

event.publish( 'createWorld' );

A slightly more complex example:

var Ubud = require( 'ubud' );

var event = new Ubud();

var token = event.subscribe( 'personBorn', function ( data ) {
  console.log( 'hello ' + data.name );
});

event.publish( 'personBorn', {
  'name': 'Colin'
});

event.unsubscribe( token );

ES6

Ubud is written using ES6 syntax.

However, by default this module will use an ES5 compatible file that has been compiled using Babel and includes Babel's polyfill.

This means the compiled file is pretty heavy for what it does.

You're going to be better off using the lightweight lib/ubud.es6.js and compiling your JS into a browser compatible format yourself.