Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including reacher with all npm packages installed. Try it out:

var reacher = require("reacher")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

reacher v1.0.0

Reacher is light-weight request-value bus.

Reacher

Reacher is light-weight request-value bus.

Dependencies

None.

Installation

  • Clone this repository; or
  • Download the dist/reacher.js; or
  • bower install reacher; or
  • npm install reacher

Sample usage

var reacherBus = new Reacher();

reacherBus.handle('foo', function(arg){
    return arg;
});

var val = reacherBus.request('foo', 41); // 41

or construct in node

var reacherBus = require('reacher').Reacher();
// ...

API

{void} handle(command, callable)

Register a command handler for given command name. Only 1 command handler is permitted at any given time.

throws ReacherError when command handler already set. throws ReacherError when command handler is not a function.

{*} request(command, ...args)

Request a command value by name and with optional arguments passed on to handler.

throws ReacherError when handler does not exist.

{function} removeHandler(command)

Remove a command handler from registry and return the handler function.

throws ReacherError when command handler does not exist.

{boolean} hasHandler(command)

Determine whether the handler is set for given command name.

License

Licensed under terms and conditions of Apache 2.0 license.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free