{"version":3,"file":"angular7-pubsub.mjs","sources":["../../src/angular7-pubsub.service.ts","../../src/angular7-pubsub.module.ts","../../src/angular7-pubsub.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { ReplaySubject, Observable, Subscription } from 'rxjs';\n\nconst ServiceName: string = 'PubSub Service';\n\n@Injectable()\nexport class PubSubService implements IPubSubService {\n  private events = {};\n\n  constructor() {}\n\n  /**\n   * a subscription which returns everything as an observable from @see {RxJs}\n   * this method does not use eventObject\n   * @param {event} event - the specific name to subscribe on - the names must be specific to those we publish.\n   * @returns {Observable<any>} an observable.\n   * @summary remember to unsubscribe in onDestroy of the components\n   */\n  public $sub(event: string): Observable<any>;\n\n  /**\n   * a subscription which returns the callback, error and complete as a subscription from @see {RxJs}\n   * this method does not use eventObject\n   * @param {event} event - the specific name to subscribe on - the names must be specific to those we publish.\n   * @param {(value: any) => void} callback - callback method which gets the value from eventObject.\n   * @returns {Subscription} a subscription which we can listen to.\n   * @summary remember to unsubscribe in onDestroy of the components\n   */\n  public $sub(event: string, callback: (value: any) => void): Subscription;\n\n  /**\n   * a subscription which returns the callback, error and complete as a subscription from @see {RxJs}\n   * this method does not use eventObject\n   * @param {event} event - the specific name to subscribe on - the names must be specific to those we publish.\n   * @param {(error: any) => void} error - exception catch function\n   * @param {() => void} complete - complete function\n   * @returns {Subscription} a subscription which we can listen to.\n   * @summary remember to unsubscribe in onDestroy of the components\n   */\n  public $sub(\n    event: string,\n    callback: (value: any) => void,\n    error: (error: any) => void\n  ): Subscription;\n\n  /**\n   * a subscription which returns the callback, error and complete as a subscription from @see {RxJs}\n   * @param {event} event - the specific name to subscribe on - the names must be specific to those we publish.\n   * @param {(value: any) => void} callback - callback function\n   * @param {(error: any) => void} error - exception catch function\n   * @param {() => void} complete - complete function\n   * @returns {Subscription} a subscription which we can listen to.\n   * @summary remember to unsubscribe in onDestroy of the components\n   */\n  public $sub(\n    event: string,\n    callback: (value: any) => void,\n    error: (error: any) => void,\n    complete: () => void\n  ): Subscription;\n\n  /**\n   * a void function when we don't want to use the subscription from 'RxJs';\n   * @param {event} event - the specific name to subscribe on - the names must be specific to those we publish.\n   * @param {(value: any) => void} callback - callback function\n   * @param {(error: any) => void} error - exception catch function\n   * @param {() => void} complete - complete function\n   */\n  public $sub(event: string,callback?: (value: any) => void,error?: (error: any) => void,complete?: () => void\n  ) {\n    if (!event) {\n      throw new Error(\n        `[${ServiceName}] => Subscription method must get event name.`\n      );\n    }\n\n    if (this.events[event] === undefined) {\n      this.events[event] = new ReplaySubject<any>();\n    }\n\n    if (typeof callback !== 'function') {\n      return this.events[event].asObservable();\n    } else {\n      return this.events[event]\n        .asObservable()\n        .subscribe(callback, error, complete);\n    }\n  }\n\n  /**\n   * Base Module needed to use PubSubService.\n   * @param {event} event - the specific name to subscribe on\n   * @param {eventObject} eventObject - the optional paramter to send when raising the event\n   */\n  public $pub(event: string, eventObject?: any) {\n    if (!event) {\n      throw new Error(\n        `[${ServiceName}] => Publish method must get event name.`\n      );\n    } else if (!this.events[event]) {\n      return;\n    }\n\n    this.events[event].next(eventObject);\n  }\n}\n\nexport interface IPubSubService {\n  $pub(event: string, eventObject?: any): void;\n  $sub(event: string): Observable<any>;\n  $sub(event: string, callback: (value: any) => void): Subscription;\n  $sub(\n    event: string,\n    callback: (value: any) => void,\n    error: (error: any) => void\n  ): Subscription;\n  $sub(\n    event: string,\n    callback: (value: any) => void,\n    error: (error: any) => void,\n    complete: () => void\n  ): Subscription;\n}\n\ninterface I$sub {\n  (event: string): Observable<any>;\n  (event: string, callback: (value: any) => void): Subscription;\n  (\n    event: string,\n    callback: (value: any) => void,\n    error: (error: any) => void\n  ): Subscription;\n  (\n    event: string,\n    callback: (value: any) => void,\n    error: (error: any) => void,\n    complete: () => void\n  ): Subscription;\n}\n","import { PubSubService } from './angular7-pubsub.service';\nimport { ModuleWithProviders, NgModule } from '@angular/core';\n\n/**\n * Base Module needed to use PubSubService.\n * @constructor\n */\n@NgModule()\nexport class PubSubModule {\n  public static forRoot(): ModuleWithProviders<PubSubModule> {\n    return {\n      ngModule: PubSubModule,\n      providers: [\n        PubSubService\n      ]\n    };\n  }\n}","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAGA,MAAM,WAAW,GAAW,gBAAgB;MAG/B,aAAa,CAAA;IAChB,MAAM,GAAG,EAAE;AAEnB,IAAA,WAAA,GAAA;AAoDA;;;;;;AAMG;AACI,IAAA,IAAI,CAAC,KAAa,EAAC,QAA+B,EAAC,KAA4B,EAAC,QAAqB,EAAA;QAE1G,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,MAAM,IAAI,KAAK,CACb,IAAI,WAAW,CAAA,6CAAA,CAA+C,CAC/D;AACF;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE;YACpC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,aAAa,EAAO;AAC9C;AAED,QAAA,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAClC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,YAAY,EAAE;AACzC;AAAM,aAAA;AACL,YAAA,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK;AACrB,iBAAA,YAAY;AACZ,iBAAA,SAAS,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC;AACxC;;AAGH;;;;AAIG;IACI,IAAI,CAAC,KAAa,EAAE,WAAiB,EAAA;QAC1C,IAAI,CAAC,KAAK,EAAE;AACV,YAAA,MAAM,IAAI,KAAK,CACb,IAAI,WAAW,CAAA,wCAAA,CAA0C,CAC1D;AACF;AAAM,aAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;YAC9B;AACD;QAED,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;;wGAjG3B,aAAa,EAAA,IAAA,EAAA,EAAA,EAAA,MAA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