I have an array from which I would like to display the top N elements. This array is mutated and sorted by another component in my application.
I see an error, although if I show all the elements of the array, everything is fine. If I react to changing the array by taking a copy of the array with .slice() and placing it in another field and displaying that field filtered for the top elements of N, then all if that is okay. But if I just show the original array filtered through the top N elements, the DOM will never be updated before the changes.
Here's a code shortcut for the error that indicates the problem: http://codepen.io/rictic/pen/ienJK?editors=101
Full code:
<script src="http://www.polymer-project.org/platform.js"></script><script src="http://www.polymer-project.org/components/web-animations-js/web-animations.js"></script><link rel="import" href="http://www.polymer-project.org/components/polymer/polymer.html"> <my-app></my-app> <script>console.clear()</script> <polymer-element name='my-app'> <template> <template if='{{results}}'> r in results <ul> <template repeat='{{ r in results }}'> <li>{{r.value}} - {{r.name}}</li> </template> </ul> r in processedResults | first(5) <ul> <template repeat='{{ r in processedResults | first(5) }}'> <li>{{r.value}} - {{r.name}}</li> </template> </ul> r in results | first(5) <ul> <template repeat='{{ r in results | first(5) }}'> <li>{{r.value}} - {{r.name}}</li> </template> </ul> </template> </template> <script> </script> </polymer-element> <script> 'use strict'; var names = ['Alice', 'Bob', 'Charline', 'Daryl', 'Elise', 'Franz', 'Geraldine', 'Happsburg', 'Irene', 'Jerome']; Polymer('my-app', { results: [{value: 10, name: 'root'}], first: function(a, k) { </script>
source share