@devs-toolbox/topic
v1.0.0
Published
Simple event publishing
Downloads
1
Readme
Dev's Toolbox // Topic
Simple event publishing / pubsub-like topic system.
API
new Topic()
Create a new Topic. When using Typescript, provide a generic type that represents the shape of data which will be published to this topic.
topic.publish(data)
Publish to this topic, triggering all subscribed listeners.
topic.publishAsync(data)
Publish to this topic after the current event loop completes.
topic.subscribe(handlerFn)
Subscribe to a topic with a handler function that receives published data.
topic.before(handlerFn)
Similar to .subscribe()
, but the handler is called before handlers registered with .subscribe()
topic.after(handlerFn)
Similar to .subscribe()
, but the handler is called after handlers registered with .subscribe()