Skip to content

Instantly share code, notes, and snippets.

@fabioluz
Forked from blkbltjns/app.html
Last active November 22, 2016 09:46
Show Gist options
  • Save fabioluz/7f420ed45142908ca5713294836b2d5e to your computer and use it in GitHub Desktop.
Save fabioluz/7f420ed45142908ca5713294836b2d5e to your computer and use it in GitHub Desktop.
<template>
<div id="container">
<div repeat.for="item of items">
<compose view-model.bind="item.viewModel" view.bind="item.view"></compose>
</div>
</div>
<div style='margin-top: 20px'>
<div repeat.for="log of logs">
${log}
</div>
</div>
<button click.delegate="click()">add</button>
</template>
import {inject, TaskQueue} from 'aurelia-framework';
import {Child} from './child';
@inject(TaskQueue)
export class App {
constructor(taskQueue) {
this.items = [];
this._taskQueue = taskQueue;
this.logs = [];
}
onChildAttached() {
let container = document.getElementById('container');
this.logs.push('Current Height: ' + container.clientHeight);
}
click() {
this.items.push({
view: 'child.html',
viewModel: new Child('C', this.onChildAttached.bind(this))
});
}
bind() {
this.items.push({
view: 'child.html',
viewModel: new Child('A')
});
this.items.push({
view: 'child.html',
viewModel: new Child('B')
});
}
attached() {
this._container = document.getElementById('container');
this.logs.push('Height after adding items: ' + this._container.clientHeight);
this._taskQueue.queueMicroTask(() => {
this.logs.push('Height after queued microtask: ' + this._container.clientHeight);
});
setTimeout(() => {
this.logs.push('Height after waiting a second: ' + this._container.clientHeight);
}, 1000);
}
}
<template>
${data}
</template>
export class Child {
constructor(data, callback) {
this.data = data;
this.callback = callback;
}
attached() {
if (this.callback) {
this.callback();
}
}
}
<!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://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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment