projects/i-components/src/lib/pipes/memoize.pipe.ts
MemoizePipe
Name | memoize |
Pure | true |
transform | |||||||||
transform(fn: Function, ...args: any[])
|
|||||||||
Transform
Parameters :
Returns :
any
{*} |
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);
}
}