-
-
Save fabioluz/7f420ed45142908ca5713294836b2d5e 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
<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> |
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, 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); | |
} | |
} |
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> | |
${data} | |
</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 Child { | |
constructor(data, callback) { | |
this.data = data; | |
this.callback = callback; | |
} | |
attached() { | |
if (this.callback) { | |
this.callback(); | |
} | |
} | |
} |
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://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