Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.1 KB

local-event.md

File metadata and controls

48 lines (33 loc) · 1.1 KB

event api | exchange api

Local Event Api

Emitting Events

Local events can be emitted only between mesh components in the same node. These events do not reach clients or go over the network.

These events use the standard node EventEmitter and do not support wildcards.

Component1.prototype.makeSomethingHappen = function ($happn, callback) {
  $happn.localEventEmitter.emit('something/happened', {data: 1});
  callback();
};

Subscribing and Unsubscribing

Component2.prototype.start = function ($happn, callback) {
  
  // subscribe
  $happner.localEvent.component1.on(
    'something/happened', this.eventHandler = function (data) {
  });
  
  callback();
};

Component2.prototype.stop = function ($happn, callback) {
  
  // unsubscribe
  $happn.localEvent.component1.removeListener('something/happened', this.eventHandler);
  
  callback();
};

The same subscription api is also available in the server as resolved at create().

Happner.create(config)
  .then(function (server) {
    server.localEvent...
  });