Re-sort Dom-repeat polymer after a child changes value

I have a Polymer dom-repeat list where children are sorted ok by their initial value. When I change the value inside the child, the dependent sort order of the list is not updated. How can i achieve this?

<body>
    <list-records></list-records>

    <dom-module id="list-records">
        <template>
            <template is="dom-repeat" 
                      items="{{records}}"
                      sort="sortByValue">
                <single-record record="{{item}}"
                               base="{{base}}">
                </single-record>
            </template>
        </template>
        <script>
            Polymer({
                is: 'list-records',
                properties: {
                    records: {
                        type: Array,
                        value: [
                            {number:1, value:4},
                            {number:2, value:2},
                            {number:3, value:3}]
                    }
                },
                sortByValue: function(a, b) {
                    if (a.value < b.value) return -1;
                    if (a.value > b.value) return 1;
                    return 0;
                }
            });
        </script>
    </dom-module>

    <dom-module id="single-record">
        <template>
            <div>
                Number: <span>{{record.number}}</span> 
                Value: <span>{{record.value}}</span>
                <button on-tap="_add">+</button>
            </div>
        </template>
        <script>
            Polymer({
                is: 'single-record',
                properties: {
                    record: Object,
                },
                _add: function() {
                    this.set('record.value', this.record.value + 1);
                }
            });
        </script>
    </dom-module>
</body>

Reference Information. In an application based on real locations, I center (lat, lng) and get a list of keys for locations around the center. I create a child for each key. The child uses the key to get lat, lng information from the database (async). Using lat lng information from the center and from the location, I can calculate the distance inside the child. The list must be ordered by estimated distance.

+4
2

single-record record , list-records. , record notify:true.

properties: {
  record: {
    type: Object,
    notify: true
  }
}

: https://www.polymer-project.org/1.0/docs/devguide/properties

+1

notify, Neil, "" (: dom-repeat bool Polymer).

<template id="list"
          is="dom-repeat" 
          items="{{records}}"
          sort="sortByValue"
          observe="value">

, , , :)

+1

Source: https://habr.com/ru/post/1663557/


All Articles