NLeSC/PattyVis

View on GitHub
app/scripts/utils/messagebus.service.js

Summary

Maintainability
A
0 mins
Test Coverage
(function() {
  'use strict';

  function Messagebus($rootScope) {
    /**
     * Publish an event
     *
     * @param  {String} name     Event name to listen on.
     * @param  {*} args Optional one or more arguments which will be passed onto the event listeners.
     * @return {Object}      Event object
     *
     * @see $rootScope.$emit
     */
    this.publish = function() {
      return $rootScope.$emit.apply($rootScope, arguments);
    };
    /**
     * @param  {String} name     Event name to listen on.
     * @param  {Function} listener Function to call when the event is emitted.
     * @return {Function} unsubscribe function
     *
     * @see $rootScope.$on for how listener is called
     */
    this.subscribe = function() {
      return $rootScope.$on.apply($rootScope, arguments);
    };
  }

  angular.module('pattyApp.utils')
    .service('Messagebus', Messagebus);
})();