Last active
August 15, 2017 14:16
-
-
Save hfitzwater/4e6144a5675bf8bd127d893cf440dab9 to your computer and use it in GitHub Desktop.
Aurelia Custom Element Lifecycle
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
<template> | |
<div class="page-host"> | |
<router-view></router-view> | |
</div> | |
<br> | |
<div> | |
<strong>Results:</strong> | |
</div> | |
<div repeat.for="msg of messages"> | |
${ msg } | |
</div> | |
</template> |
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
export class App { | |
configureRouter(config, router) { | |
config.title = 'Lifecycle'; | |
config.map([ | |
{ route: ['done'], name: 'done', moduleId: 'done', nav: true, title: 'Done' }, | |
{ route: ['','lifecycle'], name: 'lifecycle', moduleId: 'lifecycle', nav: true, title: 'Lifecycle' }, | |
]); | |
window.lifecycle = []; | |
this.messages = window.lifecycle; | |
this.router = router; | |
} | |
} |
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
<template> | |
Home | |
</template> |
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
import {inject} from 'aurelia-framework'; | |
import {Router} from 'aurelia-router'; | |
@inject( Router ) | |
export class Done { | |
constructor( router ) { | |
this.router = router; | |
} | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Aurelia</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
</head> | |
<body aurelia-app> | |
<h1>Loading...</h1> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script> | |
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script> | |
<script> | |
System.import('aurelia-bootstrapper'); | |
</script> | |
</body> | |
</html> |
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
<template> | |
<div> | |
Lifecycle | |
</div> | |
</template> |
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
import {inject, customElement, TaskQueue} from 'aurelia-framework'; | |
import {Router} from 'aurelia-router'; | |
@customElement( 'lifecycle' ) | |
@inject( Router, TaskQueue ) | |
export class Lifecyle { | |
constructor( router, taskQueue ) { | |
this.router = router; | |
this.taskQueue = taskQueue; | |
} | |
created( view ) { | |
this.log( 'created' ); | |
} | |
bind( context ) { | |
this.log( 'bind' ); | |
} | |
unbind() { | |
this.log( 'unbind' ); | |
} | |
attached() { | |
this.log( 'attached' ); | |
this.taskQueue.queueTask(() => { | |
this.router.navigateToRoute('done'); | |
}); | |
} | |
detached() { | |
this.log( 'detached' ); | |
} | |
activate( params, routeConfig, navigationInstruction ) { | |
this.log( 'activate' ); | |
} | |
deactivate() { | |
this.log( 'deactivate' ); | |
} | |
log( msg ) { | |
console.log( msg ); | |
window.lifecycle.push( msg ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment