Skip to content

Instantly share code, notes, and snippets.

@iovergard
Created July 4, 2018 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iovergard/bee0058ef77b282c6597cab0e55c1663 to your computer and use it in GitHub Desktop.
Save iovergard/bee0058ef77b282c6597cab0e55c1663 to your computer and use it in GitHub Desktop.
Custom elements reconstructed on sort
<template>
<require from="./card"></require>
<button click.delegate="sortByName()">Sort alphabetically by name</button>
<button click.delegate="sortByOldest()">Sort by oldest</button>
<card repeat.for="person of people" model.bind="person"></card>
</template>
export class App {
people = [
{
name: "Bob",
age: 33
},
{
name: "Steve",
age: 22
},
{
name: "John",
age: 45
}
]
sortByName() {
this.people.sort((cardA, cardB) => {
if (cardA.name < cardB.name) {
return -1;
} else if (cardA.name > cardB.name) {
return 1;
}
return 0;
})
}
sortByOldest() {
this.people.sort((cardA, cardB) => {
if (cardA.age < cardB.age) {
return 1;
} else if (cardA.age > cardB.age) {
return -1;
}
return 0;
})
}
card {
display: block;
}
<template style.bind="styleString">
<require from="card.css"></require>
<h1>${model.name}</h1>
<div>${model.age}</div>
<button click.delegate="makeCardRed()">Make Card Red</button>
</template>
import { bindable } from "aurelia-framework";
export class Card {
@bindable model;
styleString = "";
makeCardRed() {
this.styleString = "background-color: red;";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment