Giter VIP home page Giter VIP logo

maggamediator's Introduction

MaggaMediator Build Status

The MaggaMediator is the heart of JigMagga. Its job is to provide an communication layer.

Usage

Install module to your project

npm install JigMagga/MaggaMediator --save

Then in your code use in like

var MaggaMediator = require('MaggaMediator');
mediator = new MaggaMediator();

Tests

Testem + Mocha + Chai are used for testing. Put your tests in test/<NAMESPACE> folder with *.test.js extension. To run tests use

npm test

By default tests run in node and chrome.

##Plugins We want to keep the spirit of loosly coupled. We divided Mediator in different parts and implemented its functionality by plugins.

![Scheme is missing][plugins] [plugins]: https://github.com/JigMagga/MaggaMediator/blob/master/img/MaggaMediator-plugins.jpg "Basic scheme of communication in MaggaMediator"

Inner Transport plugins

These plugins provides storage for callbacks from Jigs

  • simple Simple object used to store callbacks in key-value style.
  • baconjs For each channel Bacon.EventStream would be created. Also, all channels stored as Bacon.Bus()

Outer Transport plugins

Plugins from this set serve as communication transports between MaggaMediators.

  • sockjs Sock.js used to organize transportation of events to other Mediators.

Dispatcher plugins

Plugins that provide additional functionality like permitions or namespaces for events.

  • dispatcherSimple Tiny implementation. Only checks and calls.

Event naming plugins

Dispatchers uses this plugins to resolve particular names of events from recieved patterns of actions.

  • eventNamesSimple Stores structure in nested object ({foo:{bar:{bal:{},bot:{}},baz:{}}}). Provides
    .find() method, that returnes all nodes resolved by pattern. .find('foo.bar') will return ['foo.bar','foo.bar.bal','foo.bar.bot']

ACL plugins

Dispatchers uses this plugins to resolve permitions for particular events.

  • permissionsSimple Stores permissions in as key-values in internal Object.

Service plugins

  • monitoring Provides debugging tools.
  • hooks frovides EventEmitter methods .on() .once() .off() .emit() to the Mediator.

##Configuration

MaggaMediators are configuration driving objects. This section explains some points about config conventions. We were inspired by Grunt style of describing it. So, for the configuration you enumerate your plugins with options using plugin names as keys.

Example:

      var someSockMediator = new MaggaMediator({
        plugins: {
          "sockjs":{
            host: 'localhost',
            port: 8080,
            path: '/mediator',
            permissions:{
              publish: 'on'
            }
          },
          "anotherPlugin":{
            foo: 'bar',
            baz: 1
          }
        }
      });

Alternatively, if your plugins doesn't need any options, you can enumerate them in array:

var someSockMediator = new MaggaMediator({plugins:['simple','monitoring']});

##Examples ###sockjsChat How it works

MaggaMediator allows to create chat application in three simple steps:

Create a mediator

var MaggaMediator = require('maggaMediator.js');
mediator = new MaggaMediator({
    plugins: {
        sockjs: {
            host: 'localhost',
            port: 8080,
            path: '/mediator'
        }
    },
    loadPlugins: ['simple', 'monitoring']
});

Subscribe to channel

mediator.subscribe('chatChannel', function(msg){
    $("#chat").append('<p>' + msg.name + ' wrote: ' + msg.text + '</p>');
});

Instantiate publishing

    msg = {
        name: $("#name").first().val(),
        text: $("#msg").first().val()
    };
    mediator.publish('chatChannel',msg);

Enjoy your chat:

Setting up

To prepare client code for the example go to the folder of the project (e.g ~/repos/MaggaMediator) and type

NODE_PATH=./src ./node_modules/.bin/browserify ./examples/sockjsChat/client/client.js -o ./examples/sockjsChat/client/client.browserified.js

To start server part type

node ./examples/sockjsChat/server/dummySockJsServer.js

then open http://localhost:3000/ in several browsers and type messages

maggamediator's People

Contributors

aakrem avatar meuschke avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.