In an Ionic App a user can open a new browser via "inAppBrowser". I'm trying to get the stats of the user before they go into to the inAppBrowser, get the stats again when browser closes, and then run a function to compare the before and after.

What I have right now is working but I feel like I'm not doing it the proper RXJS way and I want to make sure I do this right. Is this a case for using MergeMap or is that making it needlessly complicated? Do I need to worry about possible race conditions?

Code Snippet:

let previousStats = []

        first(), // getting only the first because I dont want this to update
        tap(val => {
          previousStats = val //setting the stats before the user leaves

    const browser = this.inAppBrowser.create(user.url) //user opens a browser

    this.subscriptionUserUrl = browser.on('exit') // user closes the browser
      .switchMap(() => this.reloadStats(user)) // get the most latest stats
      .subscribe(currentStats =>{
        this.handleBrowserExit(previousStats, currentStats) // do the comparison

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.