Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/debjitbis08/actorpubsub
A publish/subscribe library for JavaScript based on Actor Model.
https://github.com/debjitbis08/actorpubsub
Last synced: about 1 month ago
JSON representation
A publish/subscribe library for JavaScript based on Actor Model.
- Host: GitHub
- URL: https://github.com/debjitbis08/actorpubsub
- Owner: debjitbis08
- Created: 2013-05-29T06:05:09.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-07-28T21:19:36.000Z (over 10 years ago)
- Last Synced: 2024-12-17T11:13:15.036Z (about 1 month ago)
- Language: JavaScript
- Size: 211 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ActorPubSub [![Build Status](https://travis-ci.org/debjitbis08/actorPubSub.png?branch=master)](https://travis-ci.org/debjitbis08/actorPubSub)
ActorPubSub is a dependency free publish/subscribe library for JavaScript based on the Actor Model. It takes a lot of
inspiration from [PubSubJS](https://github.com/mroderick/PubSubJS) and uses the ideas from
[Actors Make Better Observers](http://www.dalnefre.com/wp/2011/05/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
```javascript
var subscriberCb = function (msg, data) {
console.log(msg, data);
};var token = PubSub.subscribe('Topic', subscriberCb);
PubSub.publish('Topic', 'ahoy!');
```
### Cancel specific subscription```javascript
// create a function to receive the topic
var mySubscriber = function( msg, data ){
console.log(msg, data);
};// 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 on
var token = PubSub.subscribe('MY TOPIC', mySubscriber);// unsubscribe this subscriber from this topic
PubSub.unsubscribe('MY TOPIC', token);
```