Skip to content

Instantly share code, notes, and snippets.

Created November 21, 2017 13:36
Show Gist options
  • Save anonymous/4023001c6fc1f58e078e4e23d1670603 to your computer and use it in GitHub Desktop.
Save anonymous/4023001c6fc1f58e078e4e23d1670603 to your computer and use it in GitHub Desktop.
Feet & Inches value converters
<template>
<h1>Matt's Height</h1>
<div><input type="number" value.bind="mattHeight | feet" /></div>
<div><input type="number" value.bind="mattHeight | inches" /></div>
<div>${mattHeight}</div>
<h1>Davis' Height</h1>
<div><input type="number" value.bind="davisHeight | feet" /></div>
<div><input type="number" value.bind="davisHeight | inches" /></div>
<div>${davisHeight}</div>
</template>
export class App {
mattHeight = 67;
davisHeight = 75;
}
export class FeetValueConverter {
total = 0;
toView(inches) {
this.total = inches;
return Math.floor(inches / 12);
}
fromView(feet) {
let inches = this.total % 12;
this.total = feet * 12 + inches;
return this.total;
}
}
export class InchesValueConverter {
total = 0;
toView(inches) {
this.total = inches;
return inches % 12;
}
fromView(inches) {
let feet = Math.floor(this.total / 12) + Math.floor(inches / 12);
this.total = feet * 12 + inches % 12
return this.total;
}
}
<!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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment