Last active
March 3, 2021 02:23
-
-
Save fkleuver/84e33c5e6ad8a9cc66eef32303abce9e to your computer and use it in GitHub Desktop.
ValueConverter and CustomElement Issue 0.7
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
<!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 "main" (data-main attribute on script) | |
which is your src/main.js. | |
--> | |
<body> | |
<my-app></my-app> | |
<script src="/dist/entry-bundle.js" data-main="main"></script> | |
</body> | |
</html> |
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
{ | |
"dependencies": { | |
"aurelia": "0.10.0-dev.202102251102" | |
} | |
} |
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
<input value.bind="_value" input.trigger="value = _value"> |
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, BindingMode} from 'aurelia'; | |
export class FormInput { | |
@bindable({mode: BindingMode.twoWay}) value; | |
valueChanged() { | |
this._value = this.value; | |
} | |
} |
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 Aurelia from 'aurelia'; | |
import { MyApp } from './my-app'; | |
Aurelia.app(MyApp).start(); |
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 from="./form-input"></import> | |
<import from="./proper-case-value-converter"></import> | |
<p> | |
<label>First Name</label> | |
<input value.bind="first_name | properCase"> | |
</p> | |
<p> | |
<label>First Name</label> | |
<form-input value.bind="first_name | properCase"></form-input> | |
</p> |
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 MyApp { | |
first_name = ''; | |
} |
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
const reverseLookup = {}; | |
export class ProperCaseValueConverter { | |
toView(value) { | |
if (value && typeof value == 'string') { | |
return capitalize(value); | |
} | |
return value; | |
} | |
} | |
function capitalize(str) { | |
return str.split(' ').map(m => { | |
if (m && m.length > 1) { | |
return m[0].toUpperCase() + m.substr(1).toLowerCase(); | |
} else { | |
return m.toUpperCase(); | |
} | |
}).join(' '); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment