-
-
Save bigopon/10051d07b5ba2bb9f78b6443e977da4e 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="bar + message"></let> | |
<input value.bind='bar' /> | |
<input value.bind='foo' /> | |
${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'; | |
bar = '5' | |
constructor() { | |
window.app = this; | |
// 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, | |
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