UNPKG

@bsw/bsweventemitter

Version:

Publish Subscribe events for the page

34 lines (33 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var rx_lite_1 = require("rx-lite"); var emitterName = 'BSWEventEmitter'; var BSWEventEmitter = /** @class */ (function () { function BSWEventEmitter() { this.subjects = {}; } BSWEventEmitter.getInstance = function () { // if(typeof window === 'undefined'){ // window={}; // } if (!window[emitterName]) { console.info('BSWEventEmitter getInstance new instance'); window[emitterName] = new BSWEventEmitter(); } return window[emitterName]; }; BSWEventEmitter.prototype.emit = function (name, data) { if (!this.subjects[name]) { this.subjects[name] = new rx_lite_1.Subject(); } this.subjects[name].onNext(data); }; BSWEventEmitter.prototype.on = function (name, handler) { if (!this.subjects[name]) { this.subjects[name] = new rx_lite_1.Subject(); } this.subjects[name].subscribe(handler); }; return BSWEventEmitter; }()); exports.BSWEventEmitter = BSWEventEmitter;