From 488d3d5c2cfe4396371d3c2d78c90d120641f627 Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Thu, 28 Oct 2021 23:05:00 +0300 Subject: [PATCH] add trackBy function --- src/lib/listing/models/listable.ts | 5 +++-- src/lib/listing/models/trackable.ts | 3 +++ src/lib/utils/functions.ts | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/lib/listing/models/trackable.ts diff --git a/src/lib/listing/models/listable.ts b/src/lib/listing/models/listable.ts index f270290..ead3157 100644 --- a/src/lib/listing/models/listable.ts +++ b/src/lib/listing/models/listable.ts @@ -1,5 +1,6 @@ -export interface IListable { - readonly id: string; +import { ITrackable } from './trackable'; + +export interface IListable extends ITrackable { readonly searchKey: string; readonly routerLink?: string; } diff --git a/src/lib/listing/models/trackable.ts b/src/lib/listing/models/trackable.ts new file mode 100644 index 0000000..b752b41 --- /dev/null +++ b/src/lib/listing/models/trackable.ts @@ -0,0 +1,3 @@ +export interface ITrackable { + readonly id: string; +} diff --git a/src/lib/utils/functions.ts b/src/lib/utils/functions.ts index 1ad6bd7..d4e5451 100644 --- a/src/lib/utils/functions.ts +++ b/src/lib/utils/functions.ts @@ -1,4 +1,5 @@ import { tap } from 'rxjs/operators'; +import { ITrackable } from '../listing/models/trackable'; export function capitalize(value: string): string { if (!value) { @@ -25,3 +26,7 @@ export function toNumber(str: string): number { return 0; } } + +export function trackBy() { + return (index: number, item: T): string => item.id; +}