When any field consumed by the computed field changes, the value will rerender.
Computed fields are executed on-demand whenever they are accessed. They are never cached, ensuring fresh values on every access.
Computed fields can be applied to contains, containsMany, linksTo, and linksToMany field types. The computeVia function is executed each time the field is accessed.o linking to or containing card fields, a card can have a “computed” field. Its value will be determined by the output of the computeVia function and update when its constituent fields changes.
export class Person extends CardDef {
@field firstName = contains(StringField);
@field lastName = contains(StringField);
@field fullName = contains(StringField, {
computeVia: function (this: Person) {
return `${this.firstName ?? ''} ${this.lastName ?? ''}`;
}
});
…The field can be used in a template like any other:
When any field consumed by the computed field changes, the value will rerender.
Computed fields are eagerly evaluated, they do not need to be consumed for computeVia to run.
While computeVia can currently only be applied to contains/containsMany fields, there’s a plan to let it work for linksTo and linksToMany in the future.