jeudi 30 septembre 2021

EmberJS Octane Avoid two way binding for @tracked variable and normal variable

In EmberJS if I assign a @tracked variable as the value of a second variable, updating the second variable also updates the tracked variable.

For example:

  @tracked
  baseProperty = this.args.baseProperty;

  @action
  updateDescription(event){
    let newProperty = this.baseProperty;
    let text = event.target.innerText;

    this.newProperty = Object.assign(this.newProperty , { property: htmlSafe(event.target.innerText) });
  }

If updateDescription() runs property for the newProperty object is updated, but property for the tracked baseProperty is updated as well. Is there a way to make it so that only newProperty updates?




Aucun commentaire:

Enregistrer un commentaire