Skip to content

Instantly share code, notes, and snippets.

@deap82
Last active March 29, 2018 17:09
Show Gist options
  • Save deap82/ad549b4ec6072b949aa97908e00e8dda to your computer and use it in GitHub Desktop.
Save deap82/ad549b4ec6072b949aa97908e00e8dda to your computer and use it in GitHub Desktop.
Aurelia Gist - life cycle log
<template>
<ul id="menu">
<li><a href="#/Welcome">Welcome</a></li>
<li><a href="#/Products">Products</a></li>
<li><a href="#/Contact">Contact</a></li>
</ul>
<div id="content">
<router-view></router-view>
</div>
<div id="output-wrapper">
<div id="output"></div>
<button type="button" onclick="document.getElementById('output').innerHTML='';">Clear</button>
</div>
</template>
import { OutputService as output } from 'output-service';
export class App {
configureRouter(config, router) {
console.log('configureRouter');
config.map([
{ route: '', redirect: 'Welcome' },
{ route: 'Welcome', name: 'Welcome', moduleId: 'page-welcome' },
{ route: 'Products', name: 'Products', moduleId: 'page-products' },
{ route: 'Contact', name: 'Contact', moduleId: 'page-contact' }
]);
}
}
<template>
<require from="./foo"></require>
<div class="foo" style="background-color: red; padding: 10px; color: white;">This is an example ${id} element.</div>
<foo if.bind="!id" id="Inner"></foo>
</template>
import { bindable } from 'aurelia-framework';
import { OutputService as console } from 'output-service';
export class Foo {
@bindable id = '';
constructor() {
console.log(this.id + ' CustomElement constructor');
}
created(owningView) {
console.log(this.id + ' CustomElement created');
}
bind() {
console.log(this.id + ' CustomElement bind');
}
attached() {
console.log(this.id + ' CustomElement attached');
}
detached() {
console.log(this.id + ' CustomElement detached');
}
unbind() {
console.log(this.id + ' CustomElement unbind');
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css" />
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
export class OutputService {
static log(message) {
var outputEl = document.getElementById('output');
var currentContent = outputEl.innerHTML;
outputEl.innerHTML = currentContent + '<br />' + message;
console.log(message);
}
}
<template>
<h1>Contact</h1>
</template>
import { OutputService as console } from 'output-service';
export class Contact {
}
<template>
<require from="./foo"></require>
<h1>Products</h1>
<foo></foo>
</template>
import { OutputService as console } from 'output-service';
export class Products {
constructor() {
console.log('Products constructor');
}
activate() {
console.log('Products activate');
}
created() {
console.log('Products created');
}
bind() {
console.log('Products bind');
}
attached() {
console.log('Products attached');
}
detached() {
console.log('Products detached');
}
unbind() {
console.log('Products unbind');
}
}
<template>
<h1>Welcome</h1>
</template>
import { OutputService as console } from 'output-service';
export class Welcome {
}
html, html *, html *:before, html *:after {
box-sizing: border-box;
}
body {
padding: 0;
margin: 0;
font-family: sans-serif;
}
#content {
padding: 10px;
}
#menu {
background: #26418f;
color: white !important;
padding: 10px;
margin: 0;
}
#menu li {
display: inline-block;
}
#menu li + li {
margin-left: 10px;
border-left: 1px solid white;
padding-left: 10px;
}
#menu li a {
color: white;
text-decoration: none;
}
#output-wrapper {
padding: 0px 0 10px 10px;
border-top: 1px solid orange;
background: #FFFFA5;
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 150px;
font-family: Consolas;
}
#output-wrapper #output {
padding-top: 10px;
overflow-y: auto;
height: calc(100% - 30px);
}
#output-wrapper button {
position: absolute;
bottom: 10px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment