Skip to content

Simple implementation of mediator pattern and observer pattern in Node.JS

License

Notifications You must be signed in to change notification settings

iwanjunaid/mini-mediator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

mini-mediator

Simple implementation of mediator pattern and observer pattern in Node.JS.

Installation

npm install mini-mediator

Usage

const Mediator = require('mini-mediator');
const mediator = new Mediator();

class MiniMath {
  setMediator(mediator, done) {
    this.mediator = mediator;
    done();
  }
  
  calculateAdd(firstVal, secondVal) {
    return firstVal + secondVal;
  }

  apiAdd(args, callback) {
    return callback(null, this.calculateAdd(args.firstVal, args.secondVal));
  }
}

class OtherComponent {
  setMediator(mediator) {
    this.mediator = mediator;
  }

  calculate5Plus3() {
    this.mediator.callApi('MiniMath', 'Add', {firstVal:5, secondVal:3}, function(err, result) {
      console.log(result);
    });
  }
}

const miniMath = new MiniMath();
const otherComponent = new OtherComponent();

mediator.register('MiniMath', miniMath);
mediator.register('OtherComponent', otherComponent);

otherComponent.calculate5Plus3();

About

Simple implementation of mediator pattern and observer pattern in Node.JS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published