Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dtang-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dtang-pubsub

A small PubSub library under the PS constructor function.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

#PS.js

##Browser Usage Minified and unminified versions in the dist folder.

	<script src="pubsub.min.js"></script>
	<script>
		var ps = new PS();
	</script>

##Node.js Usage

	npm install dtang-pubsub

Link to NPM page: https://npmjs.org/package/dtang-pubsub

	var Evt = require('pubsub');
	var ps = new Evt.PS();

##Public Methods

####publish(topic, [data])

  • topic (string) - your custom event name
  • data (mixed) optional argument for any data that you would like to be passed with a publication and used in subscriptions.

####subscribe(topic, callback, [context])

  • topic (string) - your custom event name
  • callback (function) - function invoked when topic is published
  • context (object) - optional argument for what this will refer to within the callback function. By default, this will point to the current PS instance
  • returns a subscription ID to potentially be used in unsubscribing

####unsubscribe(subscriptionID)

  • subscriptionID (int) - returned from the subscribe method

##Examples

	var ps = new PS();

	var s1 = ps.subscribe('test-topic', function(data) {
		console.log(this, data);
	});

	// 3rd argument will be the context used for the 2nd argument
	var s2 = ps.subscribe('test-topic', function(data) {
		console.log(this, data);
	}, {
		name: 'David',
		age: 27
	});

	ps.publish('test-topic', 'some data');

	ps.unsubscribe(s1); // unsubscribes s1
	console.log(ps);

Keywords

FAQs

Package last updated on 06 Feb 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc