Skip to content

Instantly share code, notes, and snippets.

@jdanyow
Created March 7, 2016 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdanyow/5c863eb4d0e58a9fc714 to your computer and use it in GitHub Desktop.
Save jdanyow/5c863eb4d0e58a9fc714 to your computer and use it in GitHub Desktop.
<template>
<require from="./let"></require>
<let foo.bind="bar"></let>
<div if.bind="foo">Test</div>
${message}
</template>
export class App {
message = 'hello world';
foo = false;
constructor() {
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,
TargetInstruction,
inject
} from 'aurelia-framework';
@customElement('let')
@noView()
@inject(TargetInstruction)
export class LetElement {
instruction = null;
bindings = null;
constructor(instruction) {
this.instruction = instruction;
}
bind(bindingContext, overrideContext) {
let expressions = this.instruction.expressions;
let i = expressions.length;
let bindings = this.bindings = [];
while (i--) {
let binding = expressions[i].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