Last active
April 13, 2018 12:56
-
-
Save fragsalat/6a7a8a0dbd1b1266042908a435a4ad29 to your computer and use it in GitHub Desktop.
Binding Behavior binding
This file contains hidden or 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="./lookup"></require> | |
<h1>${message}</h1> | |
<div repeat.for="item of items"> | |
Index: $index | Id: ${item.id} | ${item.value & lookup:item.type} | |
</div> | |
<button click.delegate="addItem()">Add item ${items.length}</button> | |
</template> |
This file contains hidden or 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'; | |
items = []; | |
addItem() { | |
const items = this.items.sort((a, b) => Math.random() < Math.random() ? 1 : -1) | |
items.push({ | |
id: items.length, | |
value: 'val ' + items.length, | |
type: 'type ' + items.length | |
}); | |
this.items = items; | |
} | |
} |
This file contains hidden or 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 {inject} from 'aurelia-dependency-injection' | |
export class Action1Dependency {} | |
export class Action2Dependency {} | |
export class ActionBase{ | |
} | |
@inject(Action1Dependency) | |
export class Action1 extends ActionBase{ | |
constructor(dep){ | |
super(); | |
this.dep = dep; | |
} | |
} | |
@inject(Action2Dependency) | |
export class Action2 extends ActionBase{ | |
constructor(dep){ | |
super(); | |
this.dep = dep; | |
} | |
} |
This file contains hidden or 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 hidden or 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 LookupBindingBehavior { | |
bind(binding, scope, ...args) { | |
binding.originalUpdateTarget = binding.updateTarget.bind(binding); | |
binding.updateTarget = binding.updateTarget = value => { | |
const evaluatedArgs = binding.sourceExpression.args.map((arg: AccessMember) => | |
arg.evaluate(scope) | |
); | |
this.update(binding.originalUpdateTarget, ...evaluatedArgs, value); | |
}; | |
} | |
unbind(binding) { | |
binding.updateTarget = binding.originUpdateTarget; | |
delete binding.originUpdateTarget; | |
} | |
update(updateTarget, type, value) { | |
updateTarget(`Value: ${value} | Type: ${type}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment