Skip to content

Instantly share code, notes, and snippets.

@bigopon
Last active July 9, 2021 08:39
Show Gist options
  • Save bigopon/b99b96f61b75db753379e238f5be05e7 to your computer and use it in GitHub Desktop.
Save bigopon/b99b96f61b75db753379e238f5be05e7 to your computer and use it in GitHub Desktop.
call binding example gh #1231
<!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>
{
"dependencies": {
"aurelia": "latest"
}
}
import Aurelia from 'aurelia';
import { MyApp } from './my-app';
Aurelia.app(MyApp).start();
<!--
Try to create a paired css/scss/sass/less file like my-app.scss.
It will be automatically imported based on convention.
-->
<!--
There is no bundler config you can change in Dumber Gist to
turn on shadow DOM.
But you can turn shadow DOM on by adding a meta tag in every
html template:
<use-shadow-dom>
-->
<h1>${message}</h1>
<!-- this following line should stop working in v2 -->
<!-- this is a breaking change that should be documented -->
<my-btn on-click.call="logs.push(a + ' -- time: ' + time)"></my-btn>
<!-- the following 2 should work -->
<my-btn on-click.call="switch1Toggled($event)"></my-btn>
<my-btn on-click.call="switch2Toggled($event)"></my-btn>
<template as-custom-element="my-btn">
<bindable property="onClick"></bindable>
<let i.bind="0"></let>
<button click.trigger="onClick({ a: (i = i + 1), time: $event.timeStamp })">
Call bindable
</button>
</template>
<div repeat.for="log of logs">${log}</div>
export class MyApp {
message = 'Hello Aurelia 2!';
logs = [];
switch1Toggled(val){
this.switch1 = val;
this.logs.push('switch 1 toggled: ' + val);
}
switch2Toggled = (val) => {
this.switch2 = val;
this.logs.push('switch 2 toggled: ' + val);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment