mercredi 16 décembre 2020

Ember component is not re-rendering on change of @tracked variable

My UserTag component is only re-rendering on page refresh. I expect it to refresh when action saveRoles(updatedUserRoles) is used, since it depends on an @tracked variable. UserRoles is a component from an imported dependency in package.json.

Defined in my template:

<UserTag @tags= />

In my controller:

  @tracked persistedRoles = null;

  @computed('persistedRoles')
  get sortedUserRoles() {
    console.log('sorting user roles...');
    return this.persistedRoles.sort();
  }

  @action
  saveRoles(updatedUserRoles) {
    ... // Some manipulating of updated roles for AJAX call

    this.persistedRoles = [...updatedUserRoles];
  }

I've tried adding a console.log in sortedUserRoles() to see if it is being called when I save permissions, but it is not being used. If I add outside of the @tags=..., it is called and the sorted roles are shown, which leads me to believe it ignored the tracking when set to a property for a component. Is this the case? (Note: @tags is @tracked in <UserTag>)

Versions:

"ember-cli": 3.22.0

"ember-data": "~3.18.0"




Aucun commentaire:

Enregistrer un commentaire