Last active
December 24, 2015 18:09
-
-
Save gurdotan/6840879 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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