Created
April 6, 2016 11:26
-
-
Save jdanyow/f75346c4eecaa934164839316c3f0175 to your computer and use it in GitHub Desktop.
Aurelia "let" element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<require from="let"></require> | |
<let foo.bind="bar"></let> | |
<div if.bind="foo">Test</div> | |
${message} | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class App { | |
message = 'hello world'; | |
foo = false; | |
constructor() { | |
setInterval(() => this.bar = !this.bar, 1000); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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