Skip to content

Instantly share code, notes, and snippets.

@fabioluz
Last active July 6, 2017 18:10
Show Gist options
  • Save fabioluz/bcd7d39ed94856caf586f224f89fd1ff to your computer and use it in GitHub Desktop.
Save fabioluz/bcd7d39ed94856caf586f224f89fd1ff to your computer and use it in GitHub Desktop.
<template>
<require from="./some-element"></require>
<require from="./intercept-binding-behavior"></require>
${message}
<Br>
<button click.delegate="changeFromVM()">Change from VM</button>
<hr>
<some-element value.bind="message & intercept"></some-element>
</template>
export class App {
message = 'Hello World!';
changeFromVM() {
this.message = Math.random();
}
}
<!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>
export class InterceptBindingBehavior {
bind(binding, scope, interceptor) {
binding['originalUpdateTarget'] = binding['updateTarget'];
binding.updateTarget = val => {
alert('property was changed outside of the element');
binding['originalUpdateTarget'](val);
}
}
unbind(binding, scope) {
binding.updateTarget = binding['originalUpdateTarget'];
binding['originalUpdateTarget'] = null;
}
}
<template>
${value}
<button click.delegate="change()">Change From Custom-Element</button>
</template>
import { bindable, bindingMode } from 'aurelia-framework';
export class SomeElement {
@bindable({ defaultBindingMode: bindingMode.twoWay }) value;
valueChanged(newValue, oldValue) {
}
change() {
this.value = Math.random().toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment