import { Subject } from "rx-lite" ; export class RxJsEventEmitter { public subjects : Object ; public readonly hasOwnProp : any = { } . hasOwnProperty ; private constructor ( ) { this . subjects = { } ; } /**
     * Singleton for the page so we capture all the Observers and Observables in one global array;
     */ public static getInstance ( ) { if ( ! window [ "RxJsEventEmitter" ] ) { window [ "RxJsEventEmitter" ] = new RxJsEventEmitter ( ) ; } return window [ "RxJsEventEmitter" ] ; } param name param data public emit ( name , data ) { let fnName = this . _createName ( name ) ; if ( ! this . subjects [ fnName ] ) { this . subjects [ fnName ] = new Subject ( ) ; } this . subjects [ fnName ] . onNext ( data ) ; } param name param handler public on ( name , handler ) { let fnName = this . _createName ( name ) ; if ( ! this . subjects [ fnName ] ) { this . subjects [ fnName ] = new Subject ( ) ; } this . subjects [ fnName ] . subscribe ( handler ) ; } param name public off ( name ) { let fnName = this . _createName ( name ) ; if ( this . subjects [ fnName ] ) { this . subjects [ fnName ] . dispose ( ) ; delete this . subjects [ fnName ] ; } } /**
     * Not tested.
     */ public dispose ( ) { let subjects = this . subjects ; for ( let prop in subjects ) { if ( this . hasOwnProp . call ( subjects , prop ) ) { subjects [ prop ] . dispose ( ) ; } } this . subjects = { } ; } private _createName ( name ) { return `$${ name }` ; } }