Created
August 27, 2024 05:14
-
-
Save Vheissu/d43822bc180f2dc8602ebf435124a9e4 to your computer and use it in GitHub Desktop.
Value converters and signal bindings example
This file contains hidden or 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> | |
<meta charset="utf-8"> | |
<title>Dumber Gist</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no"> | |
<base href="/"> | |
</head> | |
<!-- | |
Dumber gist uses dumber bundler, the default bundle file | |
is /dist/entry-bundle.js. | |
The starting module is pointed to aurelia-bootstrapper | |
(data-main attribute on script) for Aurelia, | |
The aurelia bootstrapper then loads up user module "main" | |
(aurelia-app attribute on <body>) which is your src/main.js. | |
--> | |
<body aurelia-app="main"> | |
<script src="/dist/entry-bundle.js" data-main="aurelia-bootstrapper"></script> | |
</body> | |
</html> |
This file contains hidden or 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
{ | |
"dependencies": { | |
"aurelia-bootstrapper": "latest" | |
} | |
} |
This file contains hidden or 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="./clock.html"></require> | |
<div> | |
Change locale to | |
<div> | |
<button | |
repeat.for="locale of locales" | |
click.delegate="changeLocale(locale.locale)" | |
style="margin-right: 5px" | |
> | |
${locale.name} | |
</button> | |
</div> | |
</div> | |
<div> | |
<h2>Flights</h2> | |
<table | |
repeat.for="flight of flights" | |
style="margin-bottom: 15px; color: #5B5B5B" | |
> | |
<tr> | |
<th>From ${flight.from}</th> | |
<th style="width: 10px"></th> | |
<th>To ${flight.to}</th> | |
</tr> | |
<tr> | |
<td><clock time.bind="flight.depart"></clock></td> | |
<td style="width: 10px"></td> | |
<td><clock time.bind="flight.arrive"></clock></td> | |
</tr> | |
</table> | |
</div> | |
</template> |
This file contains hidden or 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 { signalBindings } from "aurelia-binding"; | |
export class App { | |
flights; | |
locales = [ | |
{ locale: "en-US", name: "US" }, | |
{ locale: "en-GB", name: "UK" }, | |
{ locale: "ko-KR", name: "Korean" }, | |
{ locale: "ar-EG", name: "Arabic" }, | |
{ locale: "ja-JP-u-ca-japanese", name: "Japan" }, | |
{ locale: "de-DE", name: "Germany" }, | |
{ locale: "pt-BR", name: "Brazil" }, | |
{ locale: "ru-RU", name: "Russia" }, | |
{ locale: "es-ES", name: "Spain" }, | |
{ locale: "it-IT", name: "Italy" }, | |
{ locale: "zh-CN", name: "China" }, | |
{ locale: "zh-HK", name: "Hong Kong" }, | |
{ locale: "zh-TW", name: "Taiwan" } | |
]; | |
changeLocale(locale) { | |
window.currentLocale = locale; | |
signalBindings("locale-changed"); | |
} | |
constructor() { | |
this.flights = [ | |
{ | |
from: "Los Angeles", | |
to: "San Fran", | |
depart: new Date("2017-10-09"), | |
arrive: new Date("2017-10-10") | |
}, | |
{ | |
from: "Melbourne", | |
to: "Sydney", | |
depart: new Date("2017-10-11"), | |
arrive: new Date("2017-10-12") | |
}, | |
{ | |
from: "Hawaii", | |
to: "Crescent", | |
depart: new Date("2017-10-13"), | |
arrive: new Date("2017-10-14") | |
} | |
]; | |
} | |
} |
This file contains hidden or 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 | |
bindable="time" | |
style="display: inline-block; | |
width: 200px; | |
padding: 4px 6px; | |
border-radius: 10px; | |
border: 2px solid #1e1e1e; | |
font-size: 16px; | |
text-align: center;" | |
> | |
<require from="./flight-time-value-converter"></require> ${time | flightTime} | |
</template> |
This file contains hidden or 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 FlightTimeValueConverter { | |
signals = ["locale-changed"]; | |
toView(val) { | |
let newVal = | |
val instanceof Date | |
? val.toLocaleString(window.currentLocale) | |
: val === null | |
? "" | |
: val; // eslint-disable-line | |
return newVal; | |
} | |
} |
This file contains hidden or 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 function configure(aurelia) { | |
aurelia.use | |
.standardConfiguration() | |
.developmentLogging('info'); | |
aurelia.start().then(() => aurelia.setRoot()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment