API reference · generated from source
Function: memo()#
Call Signature#
function memo<This, Value>(target, context): (this) => Value;Defined in: decorators.ts:176
Decorator that memoizes a getter on a ReactiveNode.
Type Parameters#
| Type Parameter |
|---|
This extends ReactiveNode |
Value |
Parameters#
| Parameter | Type |
|---|---|
target | (this) => Value |
context | ClassGetterDecoratorContext<This, Value> |
Returns#
(this) => Value
Remarks#
Use @memo or @memo() for automatic dependency trapping. Pass a function
only when you want finer cache-key control; the function captures this
lazily, so the values are read fresh each time the getter is accessed.
Cache semantics (matches ReactiveNode.memo):
- No argument:
@memoand@memo()are interchangeable. Both run the getter under automatic dependency trapping and recompute when one of the trapped reads changes. - Returns
undefined: recompute on every reproxy of the ReactiveNode. - Returns
[]: compute once, cache forever for this instance. - Returns
[a, b, ...]: recompute on shallow-change.
The cache key is the getter's property name, so each @memo-decorated getter has
its own cell automatically.
@memo is a cache, not a subscription. It does not emit Retree events or
trigger React renders by itself. Use ReactiveNode.dependencies,
Retree.select, or useSelect when you also need notification behavior.
Do not use @memo on methods; use fnMemo. Do not use it for values
with side effects.
Example#
class ListFilter extends ReactiveNode {
list: Card[] = [];
searchText = "";
@memo
get filteredList() {
return this.list.filter((c) => c.text === this.searchText);
}
get dependencies() { return [this.dependency(this.list)]; }
}Pass explicit comparisons when the automatic trapper is broader than you want:
@memo((self: ListFilter) => [self.list, self.searchText])
get filteredListWithExplicitComparisons() {
return this.list.filter((c) => c.text === this.searchText);
}Call Signature#
function memo<This>(getComparisons?): <Value>(target, context) => (this) => Value;Defined in: decorators.ts:181
Decorator that memoizes a getter on a ReactiveNode.
Type Parameters#
| Type Parameter |
|---|
This extends ReactiveNode |
Parameters#
| Parameter | Type |
|---|---|
getComparisons? | (self) => unknown[] | undefined |
Returns#
<Value>(target, context) => (this) => Value
Remarks#
Use @memo or @memo() for automatic dependency trapping. Pass a function
only when you want finer cache-key control; the function captures this
lazily, so the values are read fresh each time the getter is accessed.
Cache semantics (matches ReactiveNode.memo):
- No argument:
@memoand@memo()are interchangeable. Both run the getter under automatic dependency trapping and recompute when one of the trapped reads changes. - Returns
undefined: recompute on every reproxy of the ReactiveNode. - Returns
[]: compute once, cache forever for this instance. - Returns
[a, b, ...]: recompute on shallow-change.
The cache key is the getter's property name, so each @memo-decorated getter has
its own cell automatically.
@memo is a cache, not a subscription. It does not emit Retree events or
trigger React renders by itself. Use ReactiveNode.dependencies,
Retree.select, or useSelect when you also need notification behavior.
Do not use @memo on methods; use fnMemo. Do not use it for values
with side effects.
Example#
class ListFilter extends ReactiveNode {
list: Card[] = [];
searchText = "";
@memo
get filteredList() {
return this.list.filter((c) => c.text === this.searchText);
}
get dependencies() { return [this.dependency(this.list)]; }
}Pass explicit comparisons when the automatic trapper is broader than you want:
@memo((self: ListFilter) => [self.list, self.searchText])
get filteredListWithExplicitComparisons() {
return this.list.filter((c) => c.text === this.searchText);
}