refactor(event): no longer call prevent default by default (#1926)
BREAKING CHANGE: no longer calling preventDefault on all events, this can be switched back to v1 behavior via IListenerBindingOptions
[skip ci]
* BREAKING CHANGE: no longer reexport fetch plugin from aurelia package
* fix(router-lite): dont register config
* chore: cleanup unused methods, correct typings on test fixture
Strongly-typed templates
Many users may be familiar with libraries such as FAST Element or lit-html . They want to know how to write strongly-typed templates with Aurelia.
In the following, we will see how to write a template as follows and introduce it to Aurelia.
x => x.size
x => x.block ? 'btn-block' : ''
(x) => x.getName()
Then, for variable parts, we remove the lambda part (VARIABLE => VARIABLE.) by regex via parse function. Finally, an HTML is created according to the acceptable standards for the Aurelia template engine.
The generic parameter in this function is actually your view-model.
bs-button-template.ts
import { html } from './strongly-typed-template';
// BootstrapButton is my view-model
export const buttonTemplate = html<BootstrapButton>`
<button class="btn btn-primary btn-${x => x.size} ${x => x.block ? 'btn-block' : ''}" ref="bsButtonTemplate">
${(x) => x.getName()}
</button>
`;
Now, we have to introduce this strongly-typed template to Aurelia via template option.
bs-button.ts
import { buttonTemplate } from "./bs-button-temlate";
@customElement({ name: "bs-button", template: buttonTemplate /* HERE */ })
export class BootstrapButton /* view-model */ {
@bindable({ mode: BindingMode.toView }) public size: string;
@bindable({ mode: BindingMode.toView }) public block: boolean;
getName() {
return "Primary Button";
}
}