@@ -7,52 +7,38 @@ const ServiceName: string = "PubSub Service";
77
88@Injectable ( )
99export class PubSubService implements IPubSubService {
10- private events = { } ;
10+ private events = { } ;
1111
1212 constructor ( ) { }
1313
14- $sub ( event : string ) : Observable < any > ;
15- $sub ( event : string , callback : ( value : any ) => void ) : Subscription ;
16- $sub ( event : string , callback : ( value : any ) => void , error : ( error : any ) => void ) : Subscription ;
17- $sub ( event : string , callback : ( value : any ) => void , error : ( error : any ) => void , complete : ( ) => void ) : Subscription ;
18- $sub ( event : string , callback ?: ( value : any ) => void , error ?: ( error : any ) => void , complete ?: ( ) => void ) {
19- if ( event == undefined ) {
14+ public $sub ( event : string , callback ?: ( value : any ) => void , error ?: ( error : any ) => void , complete ?: ( ) => void ) {
15+ if ( ! event ) {
2016 throw new Error ( `[${ ServiceName } ] => Subscription method must get event name.` ) ;
21- } ;
17+ }
2218
2319 if ( this . events [ event ] === undefined ) {
2420 this . events [ event ] = new BehaviorSubject < any > ( 0 ) ;
2521 }
2622
27- if ( ! callback || typeof callback !== 'function' ) {
23+ if ( typeof callback !== 'function' ) {
2824 return this . events [ event ] . asObservable ( ) ;
29- }
30- else {
25+ } else {
3126 return this . events [ event ] . asObservable ( ) . subscribe ( callback , error , complete ) ;
3227 }
3328 }
3429
35- $pub ( event : string , eventObject ?: any ) {
36- if ( event == undefined ) {
30+ public $pub ( event : string , eventObject ?: any ) {
31+ if ( ! event ) {
3732 throw new Error ( `[${ ServiceName } ] => Publish method must get event name.` ) ;
38- }
39- else if ( this . events [ event ] === undefined ) {
33+ } else if ( ! this . events [ event ] ) {
4034 throw new Error ( `[${ ServiceName } ] => No recorded events found for ${ event } .` ) ;
4135 }
4236
4337 this . events [ event ] . next ( eventObject ) ;
4438 }
4539}
4640
47- interface IPubSubService {
41+ export interface IPubSubService {
4842 $pub ( event : string , eventObject ?: any ) ;
49- $sub : I$sub ;
43+ $sub ( event : string , callback ?: ( value : any ) => void , error ?: ( error : any ) => void , complete ?: ( ) => void ) ;
5044}
51-
52- interface I$sub {
53- ( event : string ) : Observable < any > ;
54- ( event : string , callback : ( value : any ) => void ) : Subscription ;
55- ( event : string , callback : ( value : any ) => void , error : ( error : any ) => void ) : Subscription ;
56- ( event : string , callback : ( value : any ) => void , error : ( error : any ) => void , complete : ( ) => void ) : Subscription ;
57- }
58-
0 commit comments