Use @fnMemo or @fnMemo() for automatic dependency trapping. Pass a
function only when you want finer cache-key control; the function receives
the current instance and method arguments, so the values are read fresh each
time the method is called. The method arguments are always shallow-compared.
Cache semantics:
@fnMemo and @fnMemo() are interchangeable. Both run the
method under automatic dependency trapping and recompute when the arguments
or one of the trapped reads changes.undefined: recompute when the arguments change, or on every
reproxy of the ReactiveNode.[]: recompute only when the arguments change.[a, b, ...]: recompute when the arguments or comparisons shallow-change.Each decorated method stores one cache cell per instance, containing the last argument list and return value.
@fnMemo is a cache, not a subscription. It does not emit Retree events or
trigger React renders by itself. Keep decorated methods deterministic for
the same arguments and dependency values.
Do not apply @fnMemo to static methods or methods that intentionally
perform side effects.
class ListFilter extends ReactiveNode {
list: Card[] = [];
searchText = "";
@fnMemo
filterBy(limit: number) {
return this.list
.filter((c) => c.text === this.searchText)
.slice(0, limit);
}
get dependencies() { return [this.dependency(this.list)]; }
}
Pass explicit comparisons when the automatic trapper is broader than you want:
@fnMemo((self: ListFilter, limit: number) => [
self.list,
self.searchText,
limit,
])
filterByWithExplicitComparisons(limit: number) {
return this.list
.filter((c) => c.text === this.searchText)
.slice(0, limit);
}
Decorator that memoizes a method return value on a ReactiveNode.
OptionalgetComparisons: (Use @fnMemo or @fnMemo() for automatic dependency trapping. Pass a
function only when you want finer cache-key control; the function receives
the current instance and method arguments, so the values are read fresh each
time the method is called. The method arguments are always shallow-compared.
Cache semantics:
@fnMemo and @fnMemo() are interchangeable. Both run the
method under automatic dependency trapping and recompute when the arguments
or one of the trapped reads changes.undefined: recompute when the arguments change, or on every
reproxy of the ReactiveNode.[]: recompute only when the arguments change.[a, b, ...]: recompute when the arguments or comparisons shallow-change.Each decorated method stores one cache cell per instance, containing the last argument list and return value.
@fnMemo is a cache, not a subscription. It does not emit Retree events or
trigger React renders by itself. Keep decorated methods deterministic for
the same arguments and dependency values.
Do not apply @fnMemo to static methods or methods that intentionally
perform side effects.
class ListFilter extends ReactiveNode {
list: Card[] = [];
searchText = "";
@fnMemo
filterBy(limit: number) {
return this.list
.filter((c) => c.text === this.searchText)
.slice(0, limit);
}
get dependencies() { return [this.dependency(this.list)]; }
}
Pass explicit comparisons when the automatic trapper is broader than you want:
@fnMemo((self: ListFilter, limit: number) => [
self.list,
self.searchText,
limit,
])
filterByWithExplicitComparisons(limit: number) {
return this.list
.filter((c) => c.text === this.searchText)
.slice(0, limit);
}
Decorator that memoizes a method return value on a ReactiveNode.