ty-pubsub

Event handling

Usage no npm install needed!

<script type="module">
  import tyPubsub from 'https://cdn.skypack.dev/ty-pubsub';
</script>

README

Import the module

import { PubSub } from 'ty-pubsub'

or

const { PubSub } = require('ty-pubsub')

Create an instance

const pubsub = new PubSub()

Subscribe to an event

const subscriberId = pubsub.subscribe('eventName', function() {...}, options)

interface PubSubOptions {
  collectPreviousEvents?: boolean;
}

Unsubscribe

pubsub.unsubscribe('eventName', subscriberId)

Publish an event

pubsub.publish('eventName', data)