Skip to content

Instantly share code, notes, and snippets.

@gurdotan
Last active December 24, 2015 18:09
Show Gist options
  • Save gurdotan/6840879 to your computer and use it in GitHub Desktop.
Save gurdotan/6840879 to your computer and use it in GitHub Desktop.
RootApp.on("switchApp", function(appName, args) {
// Assuming the Root app has already instantiated all sub-apps
// and cached the instances by their names, fetch the app instance
var currentApp = RootApp.getSubappInstance(appName);
// If the app we're switching to is the currently active one, do nothing
if (RootApp.currentApp === currentApp) return;
// Stop the previously running app. Safe-guard with `if` in case
// this is the first time this function is called and no previous app was started
if (RootApp.currentApp) RootApp.currentApp.stop();
// Keep a reference to the new app instance and start it.
RootApp.currentApp = currentApp;
currentApp.start(args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment