
Loading…
JS error with dom-repeat and async splice array element in followed by remove last element #2009
The splice method belongs to the Array.prototype. So, it must be called directly on the array. Moreover, you have to reflect the property as attribute. Else the DOM is not updated on array value change.
Please see this version of your Plunkr
@LM450N Polymer 1.0 requires this.splice('arr', ...) instead of this.arr.splice(...). See https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-repeat.
Yes you're right. I learned this yesterday. My apologies.
If you remove the last element first, then insert an element, there's no error, but once all elements are the same, dom-repeat does strange things.
Confirmed the issue, fix is in progress.
The primary issue related to errors (throwing) when mutating an array multiple times in the same turn is resolved.
@trevordixon Note that your repro case also exhibited the issue in #1913 since you were pushing duplicate values ('foo') on to the array, which accounts for the "strange things".
Original repro on master:
http://jsbin.com/tekiwu/edit?html,console,output
Confirmed that replacing 'foo' with Math.random() makes it work as expected:
http://jsbin.com/zubama/edit?html,console,output
Stay tuned on #1913 if the duplicates issue was important to your use case...
Demonstration: http://plnkr.co/edit/isFkxmfNUa5mrhZL1wST?p=preview
If you splice an element into an array then remove the last element (in that order), in an async handler, and the array is items for a dom-repeat, you'll trigger a javascript error "Cannot read property '_children' of undefined".