diff --git a/src/providers/events.ts b/src/providers/events.ts index 60d8cf9f6..ee551eeb5 100644 --- a/src/providers/events.ts +++ b/src/providers/events.ts @@ -48,7 +48,7 @@ export class CoreEventsProvider { public static APP_LAUNCHED_URL = 'app_launched_url'; // App opened with a certain URL (custom URL scheme). logger; - observables = {}; + observables: {[s: string] : Subject} = {}; uniqueEvents = {}; constructor(logger: CoreLoggerProvider) { @@ -65,7 +65,7 @@ export class CoreEventsProvider { * @param {Function} callBack Function to call when the event is triggered. * @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. // We don't need to create an observer because the event won't be triggered again. if (this.uniqueEvents[eventName]) { @@ -83,13 +83,13 @@ export class CoreEventsProvider { this.observables[eventName] = new Subject(); } - this.observables[eventName].subscribe(callBack); + let subscription = this.observables[eventName].subscribe(callBack); // Create and return a CoreEventObserver. return { off: () => { this.logger.debug(`Stop listening to event '${eventName}'`); - this.observables[eventName].unsubscribe(callBack); + subscription.unsubscribe(); } }; }