0.2.0 • Published 9 years ago

mediocre v0.2.0

Weekly downloads
12
License
BSD
Repository
github
Last release
9 years ago

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" }});


// spy on a message being executed
mediator.spy({ redirect: /.*?/ }, function (message, listeners) {
  message.once("success", function () {

  });
});

API

mediator.on(event, listeners...)

adds a listener

mediator.execute(listener, data)

executes a command

message mediator.message(name, data)

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");
0.2.0

9 years ago

0.1.0

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

11 years ago

0.0.0

11 years ago