Skip to content

Instantly share code, notes, and snippets.

@zakjan
Last active November 23, 2016 06:28
Show Gist options
  • Save zakjan/58e940a5a2a75eed22c604984f29bec0 to your computer and use it in GitHub Desktop.
Save zakjan/58e940a5a2a75eed22c604984f29bec0 to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<require from="./item"></require>
<h1>${message}</h1>
<ul>
<li repeat.for="item of items">
<input type="checkbox" model.bind="item" checked.bind="selectedItems" matcher.bind="matcher">
<input type="checkbox" model.bind="item" checked.bind="selectedItems" matcher.bind="matcher.bind($this)">
<input type="checkbox" model.bind="item" checked.bind="selectedItems" matcher.bind="matcherBound">
<input type="checkbox" model.bind="item" checked.bind="selectedItems" matcher.call="matcherBound(item1, item2)">
${item.type} ${item.id}
</li>
</ul>
<p>${selectedItemsString}</p>
</template>
class ItemUtils {
itemsAreEqual(item1, item2) {
return item1 && item2 && item1.type === item2.type && item1.id === item2.id;
}
}
export class App {
message = 'Hello World!';
items = [{type: "car", id: 1}, {type: "car", id: 2}, {type: "car", id: 3}, {type: "truck", id: 1}, {type: "truck", id: 2}];
selectedItems = [{type: "truck", id: 1}];
itemUtils = new ItemUtils();
matcherBound = this.matcher.bind(this);
matcher(item1, item2) {
return this && this.itemUtils && this.itemUtils.itemsAreEqual(item1, item2);
}
get selectedItemsString() {
return JSON.stringify(this.selectedItems);
}
}
<!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>
<template>
<button click.trigger="clickHandler(item)">${title}</button>
</template>
import {bindable} from "aurelia-framework";
export class ItemCustomElement {
@bindable item;
@bindable clickHandler;
@bindable title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment