Hello,
So I am rewriting some code and we have errors for didLoad()
and addObserver
in esLint. We are resolving these but I have no idea how we can track if the array for targets has changed? I basically just need to set the hasDirtyAttributes
to true if the array has changed.
Here is what I am working with:
import Model, { attr, hasMany } from "@ember-data/model";
import { computed } from "@ember/object";
import Validator from "frontend/mixins/model-validator";
import AgariConstants from "frontend/constants";
export default class AddressGroup extends Model.extend(Validator) {
@attr("string") name;
@attr("date") created_at;
@attr("date") updated_at;
@attr("boolean", { defaultValue: true }) enable_scoring;
@attr("array", { defaultValue: () => [] }) targets;
@attr("array", { defaultValue: () => [] }) exceptions;
@attr("array", { defaultValue: () => [] }) invalid_targets;
@attr("string") link_id;
@attr("string", {
defaultValue: AgariConstants.ADDRESS_GROUP.AD_LINKAGE.NATIVE
})
link_status;
@attr("string") azure_ad_name;
@attr("date") last_ad_sync;
@attr("string") type;
@hasMany("MessageAlert", { defaultValue: false }) message_alerts;
@computed("type")
get isPartner() {
return this.type === "PartnerAddressGroup";
}
validations = {
name: {
presence: true
},
targets: {
length: {
minimum: 1,
if(key, value, model) {
return !model.get("isPartner");
}
}
},
link_id: {
custom(key, value, model) {
return model.get("link_status") === "linked" ? !!value : true;
}
},
azure_ad_name: {
custom(key, value, model) {
return ["linked", "delinked", "orphaned"].includes(
model.get("link_status")
)
? !!value
: true;
}
}
};
pushErrors() {}
}
So how would I track the targets array to change the hasDirtyAttributes
?