Created
July 4, 2018 20:08
-
-
Save iovergard/bee0058ef77b282c6597cab0e55c1663 to your computer and use it in GitHub Desktop.
Custom elements reconstructed on sort
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> | |
<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> |
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 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; | |
}) | |
} |
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
card { | |
display: block; | |
} |
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 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> |
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 { 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