Skip to content

Instantly share code, notes, and snippets.

@Seebiscuit
Created March 9, 2021 14:21
Show Gist options
  • Save Seebiscuit/c7c8113646e4a928f1b876830e6a082a to your computer and use it in GitHub Desktop.
Save Seebiscuit/c7c8113646e4a928f1b876830e6a082a to your computer and use it in GitHub Desktop.
Bindable binding behavior between consumer and component
<!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>
{
"dependencies": {
"aurelia-bootstrapper": "^2.3.3"
}
}
<template>
<require from="dumb-toggle"></require>
<dumb-toggle
is-boolean.bind="otherBoolean"
on-toggle-status.call="toggleStatus()">
</dumb-toggle>
</template>
import { TaskQueue, inject } from 'aurelia-framework';
@inject(TaskQueue)
export class App {
otherBoolean = false;
asyncBoolean = false;
constructor(taskQueue) {
this.taskQueue = taskQueue;
}
counter = 0;
toggleStatus() {
console.log("--- App Toggle", this.otherBoolean);
if (!(this.counter % 2) || !this.counter) {
this.otherBoolean = !this.otherBoolean;
}
this.counter++;
console.log("App Toggle", this.otherBoolean);
}
}
<template>
<div css="background-color: ${isBoolean ? 'white' : 'black'};color: ${isBoolean ? 'black' : 'white'};">
A Block
</div>
<label>
<button click.delegate="toggleBoolean()">Update Is Boolean</button>
</label>
</template>
import {bindable} from "aurelia-framework"
export class DumbToggle {
@bindable onToggleStatus;
@bindable isBoolean = false;
counter = 0;
toggleBoolean() {
console.log(this.counter++, "Dumb Toggle", this.isBoolean);
this.isBoolean = !this.isBoolean;
console.log("Dumb Toggle", this.isBoolean);
this.onToggleStatus();
console.log("Dumb Toggle Last", this.isBoolean);
}
propertyChanged(newValue) {
console.log("***isBoolean Changed", this.isBoolean);
}
}
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