-
-
Save fkleuver/91860e0ea64bb3c3719566b541f84854 to your computer and use it in GitHub Desktop.
Aurelia Gist
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> | |
| <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> |
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 { 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, {}] | |
| } | |
| } | |
| } |
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://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