@devinle/sonar

A lightweight PubSub utility

Usage no npm install needed!

<script type="module">
  import devinleSonar from 'https://cdn.skypack.dev/@devinle/sonar';
</script>

README

Sonar

A lightweight PubSub utility.

npm NPM GitHub last commit

Install

npm install @devinle/sonar

Usage

import { sonar } from 'sonar';

// Make a callback function
const callback = data => {};

// Register a callback with an event
// This event can receive data
sonar.on('evt', callback);

// Remove a specific callback from an event
sonar.off('evt', callback);

// Remove an entire event and all associated callbacks
sonar.off('evt');

// Trigger an event and send a payload object
sonar.trigger('evt', {...});

Tests

yarn test

License

MIT