Skip to content

Instantly share code, notes, and snippets.

@zakjan
Forked from jdanyow/app.html
Last active July 26, 2018 16:03
Show Gist options
  • Save zakjan/5c2d55c58bb270bfab2f41026898cd23 to your computer and use it in GitHub Desktop.
Save zakjan/5c2d55c58bb270bfab2f41026898cd23 to your computer and use it in GitHub Desktop.
compose with class ref activation
<template>
<h1>${message}</h1>
<div style="display: grid; grid-gap: 20px; grid-template-columns: repeat(2, 1fr)">
<div>
<b>String path:</b>
<br><br>
<template repeat.for="item of items">
<compose view-model="./item" model.bind="{item}"></compose>
</template>
</div>
<div>
<b>Class reference:</b>
<br><br>
<template repeat.for="item of items">
<compose view-model.bind="ItemCustomElement" model.bind="{item}"></compose>
</template>
</div>
<div>
<b>String path:</b>
<br><br>
<template repeat.for="i of items">
<compose view-model="./item" model.bind="{item: i}"></compose>
</template>
</div>
<div>
<b>Class reference:</b>
<br><br>
<template repeat.for="i of items">
<compose view-model.bind="ItemCustomElement" model.bind="{item: i}"></compose>
</template>
</div>
</div>
</template>
import {ItemCustomElement} from './item';
export class App {
message = 'Hello World!';
ItemCustomElement = ItemCustomElement;
items = new Array(10).fill().map((_, i) => ({text: i}))
}
<!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>
<template>
<span style="margin-right: 5px">
${activated ? '✓' : '×'}
</span>
${item.text}
${text}
<br>
</template>
import {computedFrom} from "aurelia-framework";
export class ItemCustomElement {
activate(params) {
this.item = params.item;
this.activated = true;
}
@computedFrom("item")
get text() {
return this.item.text * 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment