Skip to content

Instantly share code, notes, and snippets.

@fkleuver
Forked from bigopon/app.html
Created May 21, 2018 22:39
Show Gist options
  • Select an option

  • Save fkleuver/91860e0ea64bb3c3719566b541f84854 to your computer and use it in GitHub Desktop.

Select an option

Save fkleuver/91860e0ea64bb3c3719566b541f84854 to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<p>Hit edit and you'll see two items added to the form instead of one.</p>
<div if.bind="!editing">
<h2>${items.length} items!</h2>
<ul>
<li repeat.for="item of items">
${item.name}
</li>
</ul>
<button click.delegate="toggleEditing()">Edit</button>
</div>
<div if.bind="editing">
<ul>
<li repeat.for="item of items">
<input type="text" value.bind="item.name">
</li>
</ul>
<button click.delegate="toggleEditing()">Save</button>
</div>
</template>
import { Repeat } from 'aurelia-templating-resources';
Repeat.prototype.itemsChanged = function() {
this._unsubscribeCollection();
if (!this.scope) {
return;
}
var items = this.items;
this.strategy = this.strategyLocator.getStrategy(items);
if (!this.strategy) {
throw new Error('Value for \'' + this.sourceExpression + '\' is non-repeatable');
}
if (!this.isOneTime && !this._observeInnerCollection()) {
this._observeCollection();
}
this.ignoreMutation = true;
this.strategy.instanceChanged(this, items);
this.observerLocator.taskQueue.queueMicroTask(() => {
this.ignoreMutation = false;
})
};
Repeat.prototype.handleCollectionMutated = function(collection, changes) {
if (!this.collectionObserver) {
return;
}
if (this.ignoreMutation) {
return;
}
this.strategy.instanceMutated(this, collection, changes);
};
export class App {
constructor () {
this.items = [];
this.editing = false;
}
// Toggle the edit form
toggleEditing () {
this.editing = !this.editing;
// Also add a new item
if (this.editing) {
this.items.push({}); // NOTE: This is where things go wrong
// this.items = [...this.items, {}]
}
}
}
<!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