123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 'use strict';
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2015, 2020
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- /**
- * This class creates a private event router for particular events while a global event router is used for rest of events.
- *
- * SamePage scope of private event router is supported. It can be extended in the future for between two widgets, and etc..
- */
- define(['underscore', './EventRouter'], function (_, EventRouter) {
- var EventChannelRouter = EventRouter.extend({
- //global event router
- globalEventRouter: null,
- //array of private event names to the channel
- eventNames: null,
- //private channel id
- channelId: null,
- //pretty name
- _alias: null,
- init: function init(options) {
- EventChannelRouter.inherited('init', this, arguments);
- this.globalEventRouter = options.globalEventRouter;
- this.channelId = options.channelId;
- this.eventNames = options.eventNames;
- this._alias = options.alias;
- },
- _isPrivateEvent: function _isPrivateEvent(eventName) {
- return _.find(this.eventNames, function (name) {
- return name === eventName;
- });
- },
- _getChanneledEventName: function _getChanneledEventName(name) {
- return this.channelId + '_' + name;
- },
- on: function on(eventName, handler, context) {
- if (this._isPrivateEvent(eventName)) {
- EventChannelRouter.inherited('on', this, [this._getChanneledEventName(eventName), handler, context]);
- } else {
- this.globalEventRouter.on(eventName, handler, context);
- }
- },
- off: function off(eventName, handler, context) {
- if (this._isPrivateEvent(eventName)) {
- EventChannelRouter.inherited('off', this, [this._getChanneledEventName(eventName), handler, context]);
- } else {
- this.globalEventRouter.off(eventName, handler, context);
- }
- },
- trigger: function trigger(eventName, event) {
- if (this._isPrivateEvent(eventName)) {
- EventChannelRouter.inherited('trigger', this, [this._getChanneledEventName(eventName), event]);
- } else {
- this.globalEventRouter.trigger(eventName, event);
- }
- }
- });
- return EventChannelRouter;
- });
- //# sourceMappingURL=EventChannelRouter.js.map
|