Skip to content

Instantly share code, notes, and snippets.

@niieani
Last active April 17, 2016 17:41
Show Gist options
  • Save niieani/123dc3b0b8353992ac93e46f4e44a487 to your computer and use it in GitHub Desktop.
Save niieani/123dc3b0b8353992ac93e46f4e44a487 to your computer and use it in GitHub Desktop.
Aurelia: Suboptimal repeat element lifecycle [alternative swap arrays]
<template>
<require from="./component"></require>
<button click.delegate="swapArrays()">Swap arrays</button>
<br>
<component
repeat.for="id of components"
id.bind="id"
></component>
</template>
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]
}
}
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)
}
}
<!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