mediocre

- pre-hooks - post-hooks -

npm install mediocre
7 downloads in the last day
42 downloads in the last week
333 downloads in the last month

Mediocre.js Alt ci

Mediocre is a lightweight JavaScript mediator.

Features

  • ability to add pre / post hooks
  • ability to call commands with options (see below)
var mediator = require("mediocre")();

mediator.on("validate", function (message, next) {
    for(var param in message.options) {
      //validate fields against message.data
    }
});

//login helper
mediator.on("login", function (message, next) {
  console.log(message.data);
});


//add pre-hook into login to validate fields
mediator.on("pre login", { validate: { username: "string", password: "string" }});

API

mediator.on(event, listeners...)

adds a listener

mediator.execute(listener[, data][, callback])

executes a command

message mediator.message(name[, data][, options])

creates a new message option to dispatch

mediator.on("hello", function(message, options) {
  console.log(message.options.message); // world!
});

mediator.on("sayHelloWorld", { hello: { message: "world!" }});

//executes hello with options world
mediator.execute(mediator.message("hello", null, { message: "world!" }));

//same as above command
mediator.execute("sayHelloWorld");
npm loves you