virgilio-on

Event-driven actions

Usage no npm install needed!

<script type="module">
  import virgilioOn from 'https://cdn.skypack.dev/virgilio-on';
</script>

README

Virgilio-on

Event-driven actions for virgilio

Usage

Lets say we have a blinkLight and sendPush action on our Doorbell namespace.

var Doorbell = virgilio.namespace$('modules.doorbell');
Doorbell.defineAction$(function blinkLight() {
    console.log('Blink HUE light');
    // return Utils.hue.blink(...).then(func..{});
});
Doorbell.defineAction$(function sendPush() {
    console.log('Send RING RING push message');
    // return Utils.push.send(...).then(func..{});
});

We want these actions to run when a specific event is triggered, for example 'doorbell'. To make this happen we can assign an event to them.

Doorbell.blinkLight.on('doorbell');
Doorbell.sendPush.on('doorbell');

Now, when we send the 'doorbell' event the actions will run.

// Lets assume we have a virgilio instance
virgilio.emit('doorbell');

There is a working example of the above in the examples directory.