@fireflysemantics/slice
Version:

156 lines (150 loc) • 4.94 kB
TypeScript
import { Observable } from 'rxjs';
import { scrollPosition } from "./models/scrollPosition";
/**
* Returns all the entities are distinct by the
* `property` value argument.
*
* Note that the implementation uses a `Map<string, E>` to
* index the entities by key. Therefore the more recent occurences
* matching a key instance will overwrite the previous ones.
*
* @param property The name of the property to check for distinct values by.
* @param entities The entities in the array.
*
* @example
```
let todos: Todo[] = [
{ id: 1, title: "Lets do it!" },
{ id: 1, title: "Lets do it again!" },
{ id: 2, title: "All done!" }
];
let todos2: Todo[] = [
{ id: 1, title: "Lets do it!" },
{ id: 2, title: "All done!" }
];
expect(distinct(todos, "id").length).toEqual(2);
expect(distinct(todos2, "id").length).toEqual(2);
```
*/
export declare function distinct<E, K extends keyof E>(entities: E[], property: K): E[];
/**
* Returns true if all the entities are distinct by the
* `property` value argument.
*
* @param property The name of the property to check for distinct values by.
* @param entities The entities in the array.
*
* @example
*
```
let todos: Todo[] = [
{ id: 1, title: "Lets do it!" },
{ id: 1, title: "Lets do it again!" },
{ id: 2, title: "All done!" }
];
let todos2: Todo[] = [
{ id: 1, title: "Lets do it!" },
{ id: 2, title: "All done!" }
];
expect(unique(todos, "id")).toBeFalsy();
expect(unique(todos2, "id")).toBeTruthy();
```
*/
export declare function unique<E>(entities: E[], property: keyof E): boolean;
/**
* Create a global ID
* @return The global id.
*
* @example
* let e.guid = GUID();
*/
export declare function GUID(): string;
/**
* Set the global identfication property on the instance.
*
* @param e Entity we want to set the global identifier on.
* @param gid The name of the `gid` property. If not specified it defaults to `ESTORE_CONFIG_DEFAULT.guidKey`.
*/
export declare function attachGUID<E>(e: E, gid?: string): string;
/**
* Set the global identfication property on the instance.
*
* @param e[] Entity array we want to set the global identifiers on.
* @param gid The name of the `gid` property. If not specified it defaults to `gid`.
*/
export declare function attachGUIDs<E>(e: E[], gid?: string): void;
/**
* Create a shallow copy of the argument.
* @param o The object to copy
*/
export declare function shallowCopy<E>(o: E): E;
/**
* Create a deep copy of the argument.
* @param o The object to copy
*/
export declare function deepCopy<E>(o: E): any;
/**
* Gets the current active value from the `active`
* Map.
*
* This is used for the scenario where we are managing
* a single active instance. For example
* when selecting a book from a collection of books.
*
* The selected `Book` instance becomes the active value.
*
* @example
* const book:Book = getActiveValue(bookStore.active);
* @param m
*/
export declare function getActiveValue<E>(m: Map<any, E>): any;
/**
* The method can be used to exclude keys from an instance
* of type `E`.
*
* We can use this to exclude values when searching an object.
*
* @param entity An instance of type E
* @param exclude The keys to exclude
*
* @example
* todo = { id: '1', description: 'Do it!' }
* let keys = excludeKeys<Todo>(todo, ['id]);
* // keys = ['description']
*/
export declare function excludeKeys<E>(entity: any, exclude: string[]): string[];
/**
*
* @param entities The entity to search
* @param exclude Keys to exclude from each entity
*
* @return E[] Array of entities with properties containing the search term.
*/
export declare function search<E>(query: string | undefined, entities: E[], exclude?: string[]): E[];
/**
* @param scrollable The element being scrolled
* @param debounceMS The number of milliseconds to debounce scroll events
* @param sp The function returning the scroll position coordinates.
* @return A boolean valued observable indicating whether the element is scrolling up or down
*/
export declare function scrollingUp(scrollable: any, debounceMS: number, sp: scrollPosition): Observable<boolean>;
/**
* Filters the entities properties to the set contained in the
* `keys` array.
*
* @param keys The array of keys that the entity be limited to
* @param entity The entity to map
* @return An entity instance that has only the keys provided in the keys array
*/
export declare function mapEntity(keys: string[], entity: any): any;
/**
* Returns an `Observable<E>` instance that
* filters for arguments where the property
* value matches the provided value.
*
* @param value The value targeted
* @param propertyName The name of the property to contain the value
* @param obs The Slice Object Store Observable
* @returns Observable<E>
*/
export declare function onFilteredEvent<E>(value: any, propertyName: string, obs: Observable<E>): Observable<E>;