Last active
April 17, 2016 17:41
-
-
Save niieani/123dc3b0b8353992ac93e46f4e44a487 to your computer and use it in GitHub Desktop.
Aurelia: Suboptimal repeat element lifecycle [alternative swap arrays]
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="./component"></require> | |
<button click.delegate="swapArrays()">Swap arrays</button> | |
<br> | |
<component | |
repeat.for="id of components" | |
id.bind="id" | |
></component> | |
</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
import {Component} from './component' | |
export class App { | |
constructor() { | |
this.components = [] | |
for (let i = 1; i <= 10; i++) { | |
this.components.push(i) | |
} | |
this.componentsAlternative = this.components.filter(element => element !== 8) | |
} | |
swapArrays() { | |
[this.components, this.componentsAlternative] = [this.componentsAlternative, this.components] | |
} | |
} |
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 {inlineView, bindable} from 'aurelia-framework' | |
@inlineView('<template>${id}<br></template>') | |
export class Component { | |
@bindable id | |
bind() { | |
console.log('bind', this.id) | |
} | |
unbind() { | |
console.log('unbind', this.id) | |
} | |
} |
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://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script> | |
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script> | |
<script> | |
require(['aurelia-bootstrapper']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment