File

projects/i-components/src/lib/pipes/memoize.pipe.ts

Description

MemoizePipe

Metadata

Name memoize
Pure true

Methods

transform
transform(fn: Function, ...args: any[])

Transform

Parameters :
Name Type Optional
fn Function No
args any[] No
Returns : any

{*}

Properties

context
Type : any

context

import {
  ChangeDetectorRef,
  EmbeddedViewRef,
  Pipe,
  PipeTransform,
  Type,
} from '@angular/core';

/**
 * MemoizePipe
 *
 * @export
 * @class MemoizePipe
 * @implements {PipeTransform}
 */
@Pipe({
  name: 'memoize',
  pure: true,
})
export class MemoizePipe implements PipeTransform {
  /**
   * context
   *
   * @type {*}
   * @memberof MemoizePipe
   */
  context: any;

  /**
   * Creates an instance of MemoizePipe.
   *
   * @param {ChangeDetectorRef} cdRef
   * @memberof MemoizePipe
   */
  constructor(cdRef: ChangeDetectorRef) {
    this.context = (cdRef as EmbeddedViewRef<Type<any>>).context;
  }

  /**
   * Transform
   *
   * @param {Function} fn
   * @param {...any[]} args
   * @return {*}  {*}
   * @memberof MemoizePipe
   */
  // eslint-disable-next-line @typescript-eslint/ban-types
  transform(fn: Function, ...args: any[]): any {
    return fn.apply(this.context, args);
  }
}

result-matching ""

    No results matching ""