1.1.2 • Published 7 years ago

mini-mediator v1.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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();
1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago