More of a technical question than a philosophical, because I am mainly interested in the intelligence of the LWC cache and any performance implications.
I use the lazy-init pattern extensively in Apex, when implementing complex objects. The code usually looks something like this
@AuraEnabled
public List<String> Errors {
public get {
if (Errors == null) Errors = getErrors();
return Errors;
}
private set;
}
Where Errors is an object property and getErrors() is a private function that initializes the List of errors (where I know, that once initialized, the errors will never change during the life-time of the object).
Now considering client/server round trips: What happens in LWC under the hood, if I use @wire to import and call an apex method that retrieves a list of objects with lazy-init properties? My JavaScript / HTML may access said properties. Are there any unnecessary round trips where it would be faster / more efficient to simply load all Properties with the constructor?
PS: I recently started with LWC, so I'm always thankful if you point me to existing resources that already answer my question.