Hi @M_D, just as a note I reformatted your post to put the code in code blocks (triple backticks at the start and end) for readability.
There are a lot of ways you could rewrite this. For example my preference is to create my own Input component which uses one-way binding, so i have more control over how the updates work.
That said the most straightforward way to do this might be something like:
@tracked _first_name;
@tracked _last_name;
@tracked isNameChanged = false;
get first_name() {
return this._first_name;
}
set first_name(value) {
this._first_name = value;
this.isNameChanged = true;
}
get last_name() {
return this._last_name;
}
set last_name(value) {
this._last_name = value;
this.isNameChanged = true;
}
Not directly. The computed version is basically using an observer pattern which is against the autotracking/octane model.
In that case I’d recommend writing your own one-way-bound input component, and hooking into its change/update action to set both attributes.
A minimal version would look something like the below. Note that for brevity I’m using some helpers from ember-composable-helpers as well as the set helper from ember-set-helper. These could be easily adapted to not need those helpers.
<MyCoolInput
@value={{this.first_name}}
@onChange={{queue
(set this "first_name")
(set this "isNameChanged" true)
}}
/>
<MyCoolInput
@value={{this.last_name}}
@onChange={{queue
(set this "last_name")
(set this "isNameChanged" true)
}}
/>
... and so on
If you didn’t want to use queue/set you could just drop an action on the controller like: