Component hooks and actions


#1

I am extending the reference select component that was suggested in the deprecation guide here.

I want to add this functionality:

  1. Fire action to update the select with the first content object if no selection is passed in.
  2. If the selection is not in the content use the change action to select the first content object.

My implementation is:

didReceiveAttrs() {
  this_super();

  if (!this.get("selection") || !this.get("content").contains(this.get("selection")) {
    this.attrs.changeAction(this.get("content").toArray()[0];
  }
}

This does what I expect. All is well.

However, if for example you have a label that is computing off the set selection. You get a label modified twice in a single render deprecation because of the action setting the selection again.

My question is: Should actions ever be fired in this way?

The alternative is to set defaults where the selection is used and do the book keeping for whether the selection is in the content in the changeAction. Are there any other options I’m not seeing?