Sha256: d9d201f62c15e7788cca5e354ddeb82dae72922b9d81e094dcb2c16d7fc5f555

Contents?: true

Size: 1.46 KB

Versions: 32

Compression:

Stored size: 1.46 KB

Contents

/**
 * Created by hosekp on 11/10/16.
 */
(function () {
  /**
   * @method fire
   * @method on
   * @method of
   * @constructor
   */
  function EventBus() {
    this.registeredMap = {};
  }

  /**
   * send event to all of the listeners of specified event
   * @param {String} event
   * @param {...any}
   */
  EventBus.prototype.fire = function (event) {
    var proFunctions = this.registeredMap[event];
    if (!proFunctions) return;
    var slicedArgs = Array.prototype.slice.call(arguments, 1);
    for (var i = 0; i < proFunctions.length; i++) {
      proFunctions[i].apply(this, slicedArgs);
    }
  };
  /**
   * Register listener of specified event
   * @param {String} event
   * @param {Function} func
   */
  EventBus.prototype.on = function (event, func) {
    var eventList = this.registeredMap[event];
    if (!eventList) this.registeredMap[event] = eventList = [];
    for (var i = 0; i < eventList.length; i++) {
      if (eventList[i] === func) {
        return;
      }
    }
    eventList.push(func);
  };
  /**
   *
   * @param {String} event
   * @param {Function} func
   */
  EventBus.prototype.off = function (event, func) {
    var eventList = this.registeredMap[event];
    if (!eventList) return;
    for (var i = 0; i < eventList.length; i++) {
      if (eventList[i] === func) {
        eventList.splice(i, 1);
        return;
      }
    }
  };
  window.EASY = window.EASY || {};
  EASY.eventBusFactory = EventBus;
  EASY.eventBus = new EventBus();
})();

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
redmine_extensions-0.6.3 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.6.2 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.6.1 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.6.0 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.4.5 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.5.1 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.4.4 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.4.3 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.4.1 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.4.0 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.4.0.beta app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.11 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.10 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.9 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.8 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.7 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.6 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.4 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.3 app/assets/javascripts/redmine_extensions/event_bus.js
redmine_extensions-0.3.2 app/assets/javascripts/redmine_extensions/event_bus.js