question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

redux state array bound to dom-repeat doesn't reflect items property changes.

See original GitHub issue

I have the following element the issue is when changing an employee thru redux action, the changes does not propagate to the dom-repeat, but is reflected when bound directly inside the parent template (e.g. [[employees.0.id]]) I’ve tried manual re-render of the dom-repeat template e.g. this.$.employees.render() but still does not reflect the updated employee properties any suggestion?

Note: i’m using v1.01

<dom-module id="employees-info">
    <template>
        [[employees.0.id]]  - [[employees.0.firstname]]  -- [[employees.0.lastname]]
        [[employees.1.id]]  - [[employees.1.firstname]]  -- [[employees.1.lastname]]

        <template is="dom-repeat" items=[[employees]] as=“employee”   id=“employees” >
            <div>id: [[employee.id]]</div>
            <div>firstname: [[employee.firstname]]</div>
            <div>lastname: [[employee.lastname]]</div>

        </template>

    </template>
    <script>
        class EmployeesInfo extends ReduxMixin(Subscriber(Polymer.Element)) {
            static get is() { 
                return 'employees-info' 
            }

            static get properties() {
                return {
                    employees:{
                        type:Array,
                        statePath:'employees'
                    }
                }
            }
        }

        customElements.define(EmployeesInfo.is, EmployeesInfo);
    </script>
</dom-module>    

Now inside the redux store actions, (i’ve already tried multiple ways to update the array e.g. splice)

    ```
case 'UPDATE_EMPLOYEE_SUCCESS':
            
            return Object.assign({}, state, {
                employees: state.employees.slice().map((employee) =>{ 
                    // update employee bere
                    return employee;  
            }), updating_employee: 'success' });

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:7

github_iconTop GitHub Comments

4reactions
jobizznesscommented, Oct 15, 2017

Plus one this issue. I am facing the same problem. sub properties are not notified on change.

2reactions
mideswebcommented, Mar 23, 2018

On Polymer 2 there is another solution. It’s to use “mutable-data” in the template dom-repeat.

<template is="dom-repeat" items="[[todos]]" as="todo" mutable-data>
  [[todo.completed]]
</template>

The problem i found is to notify changes to children elements of the dom-repeat. Like this:

<template is="dom-repeat" items="[[todos]]" as="todo" mutable-data>
  <todo-item todo="[[todo]]" index="[[index]]"></todo-item>
</template>

In this case <todo-item> do not change, even of the mutable-data configuration on dom-repeat. This situation is solved using the Polymer.MutableData mixin on <todo-item>.

class TodoItem extends Polymer.MutableData(ReduxMixin(Polymer.Element)) {
  // all the element code remains without changes
}

I dont know the performance of this solution. (Worried because with any minimal change in the array causes a notification of change in all the items in the dom-repeat, even if only has changed one of them)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update single value inside specific array item in redux
I have an issue where re-rendering of state causes ui issues and was suggested to only update specific value inside ...
Read more >
Few Ways to Update a State Array in Redux Reducer - Medium
In React and Redux it's said to keep the state immutable. It simply means that we should not change the state properties directly....
Read more >
When does React re-render components? - Felix Gerschau
Changing the state means that React triggers an update when we call the setState function (in React hooks, you would use useState )....
Read more >
Angular NgRx Entity - Complete Practical Guide
if we store all our entities as arrays, our reducers will look almost the same for every entity. For example, take the simple...
Read more >
Udacity React & Redux - James Priest CV
Since Redux is not a topic for beginners and can be a daunting area to ... The actions represent the different events that...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found