Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utilities"

Index

Functions

GUID

  • GUID(): string
  • Create a global ID

    example

    let e.guid = GUID();

    Returns string

    The global id.

attachGUID

  • attachGUID<E>(e: E, gid?: string): string
  • Set the global identfication property on the instance.

    Type parameters

    • E

    Parameters

    • e: E

      Entity we want to set the global identifier on.

    • Optional gid: string

      The name of the gid property. If not specified it defaults to gid.

    Returns string

attachGUIDs

  • attachGUIDs<E>(e: E[], gid?: string): void
  • Set the global identfication property on the instance.

    Type parameters

    • E

    Parameters

    • e: E[]
    • Optional gid: string

      The name of the gid property. If not specified it defaults to gid.

    Returns void

deepCopy

  • deepCopy<E>(o: E): any
  • Create a deep copy of the argument.

    Type parameters

    • E

    Parameters

    • o: E

      The object to copy

    Returns any

distinct

  • distinct<E, K>(entities: E[], property: K): E[]
  • 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.

    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);
    

    Type parameters

    • E

    • K: keyof E

    Parameters

    • entities: E[]

      The entities in the array.

    • property: K

      The name of the property to check for distinct values by.

    Returns E[]

excludeKeys

  • excludeKeys<E>(entity: E, exclude: string[]): string[]
  • 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.

    Type parameters

    • E

    Parameters

    • entity: E

      An instance of type E

    • exclude: string[]

      The keys to exclude

    Returns string[]

getActiveValue

  • getActiveValue<E>(m: Map<any, E>): any
  • Gets the current active value from the active Map.

    This is used for the scenario where we are manging 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);

    Type parameters

    • E

    Parameters

    • m: Map<any, E>

    Returns any

mapEntity

  • mapEntity(keys: string[], entity: any): any
  • Filters the entities properties to the set contained in the keys array.

    Parameters

    • keys: string[]

      The array of keys that the entity be limited to

    • entity: any

      The entity to map

    Returns any

    An entity instance that has only the keys provided in the keys array

scrollingUp

  • scrollingUp(scrollable: any, debounceMS: number, sp: scrollPosition): Observable<boolean>
  • Parameters

    • scrollable: any

      The element being scrolled

    • debounceMS: number

      The number of milliseconds to debounce scroll events

    • sp: scrollPosition

      The function returning the scroll position coordinates.

    Returns Observable<boolean>

    A boolean valued observable indicating whether the element is scrolling up or down

search

  • search<E>(query?: string, entities: E[], exclude?: string[]): E[]
  • Type parameters

    • E

    Parameters

    • Default value query: string = ""
    • entities: E[]

      The entitie to search

    • Default value exclude: string[] = []

      Keys to exclude from each entity

    Returns E[]

    E[] Array of entities with properties containing the search term.

shallowCopy

  • shallowCopy<E>(o: E): E
  • Create a shallow copy of the argument.

    Type parameters

    • E

    Parameters

    • o: E

      The object to copy

    Returns E

unique

  • unique<E>(entities: E[], property: keyof E): boolean
  • Returns true if all the entities are distinct by the property value argument.

    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();

    Type parameters

    • E

    Parameters

    • entities: E[]

      The entities in the array.

    • property: keyof E

      The name of the property to check for distinct values by.

    Returns boolean

Generated using TypeDoc