ActorPubSub
ActorPubSub is a dependency free publish/subscribe library for JavaScript based on the Actor Model. It takes a lot of inspiration from PubSubJS and uses the ideas from Actors Make Better Observers to implement the required actors. It can be used as a normal pub/sub library as all the actor logic is hidden away.
A major benefit of this implementation is that observer list updates do not block the notification process.
Features
- Dependency free.
- Synchronization decoupling.
- Attaching and detaching subscribers is also asynchronous.
- Since observer list updates are asynchronous, notify operations are possible while updates are in progress.
- Data passed to subscribers is a copy of the original data, thus, changes to it by the subscribers does not affect other subscribers and the publisher.
Examples
Basic Example
var { console;}; var token = PubSub; PubSub;
Cancel specific subscription
// create a function to receive the topicvar { console;}; // add the function to the list of subscribers to a particular topic// we're keeping the returned token, in order to be able to unsubscribe// from the topic later onvar token = PubSub; // unsubscribe this subscriber from this topicPubSub;
Cancel all subscriptions for a function
// create a function to receive the topicvar { console;}; // unsubscribe mySubscriber from ALL topicsPubSub;