Retree - v1.0.0
    Preparing search index...

    Function fnMemo

    • Decorator that memoizes a method return value on a ReactiveNode.

      Type Parameters

      Parameters

      Returns FnMemoMethod<This, MethodArgs, Value>

      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:

      • No argument: @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.
      • Returns undefined: recompute when the arguments change, or on every reproxy of the ReactiveNode.
      • Returns []: recompute only when the arguments change.
      • Returns [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.

      Type Parameters

      • This extends ReactiveNode
      • ComparisonArgs extends unknown[] = []

      Parameters

      • OptionalgetComparisons: (
            self: This,
            ...args: FnMemoComparisonArgs<ComparisonArgs>,
        ) => unknown[] | undefined

      Returns <MethodArgs extends unknown[], Value>(
          target: FnMemoMethod<This, MethodArgs, Value>,
          context: ClassMethodDecoratorContext<
              This,
              FnMemoMethod<This, MethodArgs, Value>,
          >,
      ) => FnMemoMethod<This, MethodArgs, Value>

      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:

      • No argument: @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.
      • Returns undefined: recompute when the arguments change, or on every reproxy of the ReactiveNode.
      • Returns []: recompute only when the arguments change.
      • Returns [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);
      }