forked from CIT/Vmeda.Online
		
	MOBILE-2302 core: Fix unsubscribe in CoreEventsProvider
This commit is contained in:
		
							parent
							
								
									c950d7dd40
								
							
						
					
					
						commit
						f94cd92322
					
				| @ -48,7 +48,7 @@ export class CoreEventsProvider { | |||||||
|     public static APP_LAUNCHED_URL = 'app_launched_url'; // App opened with a certain URL (custom URL scheme).
 |     public static APP_LAUNCHED_URL = 'app_launched_url'; // App opened with a certain URL (custom URL scheme).
 | ||||||
| 
 | 
 | ||||||
|     logger; |     logger; | ||||||
|     observables = {}; |     observables: {[s: string] : Subject<any>} = {}; | ||||||
|     uniqueEvents = {}; |     uniqueEvents = {}; | ||||||
| 
 | 
 | ||||||
|     constructor(logger: CoreLoggerProvider) { |     constructor(logger: CoreLoggerProvider) { | ||||||
| @ -65,7 +65,7 @@ export class CoreEventsProvider { | |||||||
|      * @param {Function} callBack Function to call when the event is triggered. |      * @param {Function} callBack Function to call when the event is triggered. | ||||||
|      * @return {CoreEventObserver} Observer to stop listening. |      * @return {CoreEventObserver} Observer to stop listening. | ||||||
|      */ |      */ | ||||||
|     on(eventName: string, callBack: Function) : CoreEventObserver { |     on(eventName: string, callBack: (value: any) => void) : CoreEventObserver { | ||||||
|         // If it's a unique event and has been triggered already, call the callBack.
 |         // If it's a unique event and has been triggered already, call the callBack.
 | ||||||
|         // We don't need to create an observer because the event won't be triggered again.
 |         // We don't need to create an observer because the event won't be triggered again.
 | ||||||
|         if (this.uniqueEvents[eventName]) { |         if (this.uniqueEvents[eventName]) { | ||||||
| @ -83,13 +83,13 @@ export class CoreEventsProvider { | |||||||
|             this.observables[eventName] = new Subject<any>(); |             this.observables[eventName] = new Subject<any>(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.observables[eventName].subscribe(callBack); |         let subscription = this.observables[eventName].subscribe(callBack); | ||||||
| 
 | 
 | ||||||
|         // Create and return a CoreEventObserver.
 |         // Create and return a CoreEventObserver.
 | ||||||
|         return { |         return { | ||||||
|             off: () => { |             off: () => { | ||||||
|                 this.logger.debug(`Stop listening to event '${eventName}'`); |                 this.logger.debug(`Stop listening to event '${eventName}'`); | ||||||
|                 this.observables[eventName].unsubscribe(callBack); |                 subscription.unsubscribe(); | ||||||
|             } |             } | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user