Skip to content
Mediator pattern implementation for Node.js
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
tests
README.md
index.js
package.json

README.md

mediator

Mediator pattern implementation for Node.js.

example

var Mediator = require('../index'),
    mediator =  new Mediator(),
    // Add a couple of members
    member0 = {},
    member1 = {};

//add the members to the mediator
mediator.add(member0,"testEvent0",member0Callback);
mediator.add(member1,"testEvent0",member1Callback);

//inline callback
mediator.add(member1,"testEvent1",function(rs){
    console.log("-> testEvent1 " + rs.res);
});

//anon member with inline callback
mediator.on("testEvent1", function(rs){
    console.log("-> Anon testEvent1 " + rs.res);
});

//add a few callbacks
function member0Callback (rs){
    console.log("-> member0Callback " + rs.res);
};

function member1Callback (rs){
    console.log("-> member1Callback " + rs.res);
};

//emit some events
member0.emit("testEvent0", {res:"word"});
member1.emit("testEvent1", {res:"yo"});

//removelistener
mediator.remove("testEvent0",member1);
//...and check if is still listening
member0.emit("testEvent0", {res:"word"});

install

With npm do:

npm install mediator
You can’t perform that action at this time.