polymer - Computed property isn't recomputed when array dependency is mutated -
i'm using computed property items dom-repeat.
<template is="dom-repeat" items="{{double(values)}}"> <span>{{item}}</span> </template> when dependency values changes, property isn't recomputed.
addvalue: function() { this.push('values', this.values.length+1); this.async(this.addvalue, 1000); }, if, instead of mutating values, set new array, work:
this.set('values', this.values.concat(this.values.length+1)) is bug or expected behavior?
i spoke scott miles, member of team behind polymer, , got back:
in order computed property bind properly, must use [[double(values.*)]].
the parameter passed double function object properties path, value, , base, in path observation.
pathrefer path string specifies iflengthorsplicesupdated in array,valuevalue oflengthorsplices, andbaserefer array.
example:
<template is="dom-repeat" items="[[double(values.*)]]"> <span>[[item]]</span> </template> <script> ... double: function(e) { return e.base.map(function(n) { return n*2; }); } docs: https://www.polymer-project.org/1.0/docs/devguide/properties.html#array-observation
demo: http://plnkr.co/edit/idrz5xvln9sz35ir8pgt?p=preview
a dom-repeat template expects working collection, , when bind values directly, knows keep tabs on items in values.
computed properties not have such expectations, , [[double(values)]] doesn't work in case because update when values reference changes, not when items in array change. using values.* lets polymer know should update computed property binding when array's contents mutated.
i wouldn't post here in scott's stead if not for
sjmiles: @vartan: otoh, if transcribe learned, me, time least elastic resource
Comments
Post a Comment