2.2.1 • Published 10 years ago

simplehub v2.2.1

Weekly downloads
28
License
-
Repository
github
Last release
10 years ago

simplehub

travis status

NPM NPM

This is a simple implementation of a publish subscribe module in JavaScript. It can be used in the browser (CommonJS, AMD or just vanilla JS is supported) or on the server as a node module.

Usage

Here is a simple publish subscribe example.

// Subscribe to a topic
var hub = simplehub.create();
hub.subscribe("someTopic", function(data){
	console.log(data.text);
});
// Publish a topic
hub.publish("someTopic", {text: "hello world"});

// You can also use the hub right out of the box, like so
simplehub.publish("..", {});
simplehub.subscribe("..", function(){});

It is possible to have sub topics which provides for a more fine grained approach, below is a sample of how that might look.

var hub = require('../../lib/simplehub/simplehub.js');

hub.subscribe('events/subtopic', function(){
	// Fires only when event with subtopic is present
	console.log('A subtopic event fired');
})
hub.subscribe('events', function(){
	// Fires for both events
	console.log('Just an event fired');
});

hub.publish('events', '');
hub.publish('events/subtopic', '');
2.2.1

10 years ago

2.2.0

10 years ago

2.1.0

10 years ago

2.0.2

10 years ago

2.0.1

10 years ago

2.0.0

10 years ago