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

accu-mediator

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

accu-mediator

A mediator built on accu-router

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Mediator

Mediator (pub/sub) implemented on top of accu-router.

Getting started

npm install accu-mediator --save

.instance, new, .create()

Instantiate the mediator:

var Mediator = require( 'accu-mediator' );
var mediator = new Mediator();

//or use the default instance
var mediator = require( 'accu-mediator' ).instance;

//or
var mediator = require( 'accu-mediator' ).create();

.subscribe( topic, callback[, receiver] );

Subscribe to topics

//topics are route paths, see accu-router for route examples
mediator.subscribe( 'my/topic/with/:tokens', myCallbackFn );

//add a receiver context for your callback
mediator.subscribe( 'my/topic/without/tokens', myObj.method, myObj );

The callback will be invoked in the context of the receiver with arguments of [topic, ...arg]. This is how your callback knows which event triggered it when a token or wildcard was used to register it.

.publish( topic[, ...arg] )

Publish topics. Data arguments are optional.

mediator.publish( 'my/topic' );

The publish method returns false if no callbacks were registered or a Promise for the resolution of all callbacks. The Promise will resolve to an array of all callback values.

mediator.publish( 'call/server' ).then( doSomething );

.unsubscribe( topic, callback[, receiver] );

Remove all callbacks subscribed with the same parameters.

mediator.unsubscribe( 'my/topic', myCallback );
mediator.unsubscribe( 'my/topic', myObj.method, myObj );

Keywords

FAQs

Package last updated on 17 Apr 2014

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