Skip to content

Instantly share code, notes, and snippets.

@loaded02
Forked from jdanyow/app.html
Last active July 6, 2017 10:39
Show Gist options
  • Save loaded02/b02295e51c040b48ea84fb6808ffeab5 to your computer and use it in GitHub Desktop.
Save loaded02/b02295e51c040b48ea84fb6808ffeab5 to your computer and use it in GitHub Desktop.
Reloading Map: Index Bug
<template>
<require from="./custom"></require>
<h1>Reloading Bug</h1>
<button click.delegate="reloadArray()">Reload Array</button>
<button click.delegate="reloadMap()">Reload Map</button>
<h2>Array</h2>
<div repeat.for="item of myArray" custom>
${item}
</div>
<h2>Map</h2>
<div repeat.for="[key, value] of myMap" custom>
<ul>
<li repeat.for="item of value">${item}</li>
</ul>
</div>
</template>
export class App {
constructor() {
this.myArray = [];
for (let i=0; i<10; i++) {
this.myArray.push(i);
}
this.myMap = new Map();
for (let i=0; i< 10; i++) {
this.myMap.set(i, Array(5).fill(i + ' foo bar'));
}
}
reloadMap() {
this.myMap.clear();
for (let i=0; i< 10; i++) {
this.myMap.set(i, Array(5).fill(i + ' foo bar'));
}
}
reloadArray() {
this.myArray.splice(0);
for (let i=0; i<10; i++) {
this.myArray.push(i + ' reloaded');
}
}
}
export class CustomCustomAttribute {
bind(bindingContext, overrideContext) {
console.log(JSON.stringify(overrideContext.bindingContext), 'index: ', overrideContext.$index, 'first: ', overrideContext.$first, 'last: ', overrideContext.$last)
if (overrideContext.$first === true) {
console.log("item is first");
}
if (overrideContext.$last === true) {
console.log("item is last");
}
}
}
<!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