Skip to content

Instantly share code, notes, and snippets.

@bigopon
Forked from jdanyow/app.html
Last active August 28, 2017 07:35
Show Gist options
  • Save bigopon/10051d07b5ba2bb9f78b6443e977da4e to your computer and use it in GitHub Desktop.
Save bigopon/10051d07b5ba2bb9f78b6443e977da4e to your computer and use it in GitHub Desktop.
Aurelia "let" element
<template>
<require from="let"></require>
<let foo="bar + message"></let>
<input value.bind='bar' />
<input value.bind='foo' />
${message}
</template>
export class App {
message = 'hello world';
bar = '5'
constructor() {
window.app = this;
// setInterval(() => this.bar = !this.bar, 1000);
}
}
<!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://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
import {
customElement,
noView,
BindingEngine,
BindingExpression,
bindingMode,
TargetInstruction,
inject
} from 'aurelia-framework';
var LookupFunctions = {
bindingBehaviors: function bindingBehaviors(name) {
return null;
},
valueConverters: function valueConverters(name) {
return null;
}
};
@customElement('let')
@noView()
@inject(Element, BindingEngine, TargetInstruction)
export class LetElement {
instruction = null;
bindings = null;
constructor(element, bindingEngine, instruction) {
console.clear();
this.element = element;
this.bindingEngine = bindingEngine;
this.instruction = instruction;
}
bind(bindingContext, overrideContext) {
let bindings = this.bindings = [];
let attrs = this.element.attributes;
let i = attrs.length;
let attr;
let name;
let bindingExpression;
let binding;
while (i--) {
attr = attrs[i];
name = attr.name;
if (name === 'au-target-id' || name === 'class') continue;
bindingExpression = this.bindingEngine.createBindingExpression(name, `${attr.name} = ${attr.value}`);
binding = bindingExpression.createBinding(overrideContext);
binding.bind({ bindingContext, overrideContext });
bindings.push(binding);
}
}
unbind() {
let i = this.bindings.length;
while (i--) {
this.bindings[i].unbind();
}
this.bindings = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment