Last active
December 16, 2016 04:41
-
-
Save joeldenning/d96a25991b1e53437c14437fadd32af0 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
// single-spa will import this file and call the exported lifecyle functions | |
let user; | |
export function bootstrap() { | |
return fetch('/api/users/0') | |
.then(response => response.json()) | |
.then(json => user = json); | |
} | |
export function mount() { | |
/* This is normally where you would have your framework-specific code like | |
* ReactDOM.render or angular.bootstrap(). The fact that you can put *anything* | |
* into this function is what makes single-spa so powerful -- any framework | |
* can implement a "mount" and "unmount" to become a single-spa application. | |
*/ | |
return Promise.resolve() | |
.then(() => { | |
document.getElementById("user-app").innerHTML = ` | |
<div> | |
Hello ${user.name}! | |
<div> | |
` | |
}) | |
} | |
export function unmount() { | |
/* Real world use cases would be something like ReactDOM.unmountComponentAtNode() | |
* or vue.$destroy() | |
*/ | |
return Promise.resolve() | |
.then(() => { | |
document.getElementById("user-app").innerHTML = ''; | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment