How recreate View and VM for compose?

I have this requirement that on selection of a dropdown item, a specific custom element is shown dynamically with the help of compose. It is possible to have same custom element for multiple options in the dropdown.
Now in this case, I would expect a new instance of the custom element when the option is changed even if the both current and previous options are associated with the same custom element. However, that is not happening. This is a problem for me because I use some validation rules in these custom elements that are used in compose. And, once the value is dirty, even if the option is changed (and with that model too which is not dirty), validation rules are fired. This creates superfluous validation errors.

I have tried the @transient decorator, although custom elements should be transient by default in Aurelia. That didn’t work. I also tried to set the activate strategy as follows, only to realize that compose does not use this at all.

public determineActivationStrategy() {
  return activationStrategy.replace;
}

As only activate hook works for compose, I cannot even use a deactivate hook to unset the validation rules.

Is there anyway the instance of view and vm can be recreated?

1 Like

You could implement your own signal setup: https://aurelia.io/docs/binding/binding-behaviors#signal

2 Likes