Type Parameters

  • E

Hierarchy

Constructors

  • perform initial notification to all observers, such that operations like combineLatest{} will execute at least once.

    Type Parameters

    • E

    Parameters

    • label: string

      The slice label

    • predicate: Predicate<E>

      The slice predicate

    • eStore: EStore<E>

      The EStore instance containing the elements considered for slicing

    Returns Slice<E>

    Example

     //Empty slice
    new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete);

    //Initialized slice
    let todos = [new Todo(false, "You complete me!"),
    new Todo(true, "You completed me!")];
    new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete, todos);

Properties

_query: string = ''

The current query state.

config: StoreConfig

The configuration for the store.

eStore: EStore<E>

The EStore instance containing the elements considered for slicing

entries: Map<string, E> = ...

Primary index for the stores elements.

idEntries: Map<string, E> = ...

The element entries that are keyed by an id generated on the server.

label: string

The slice label

notify: ReplaySubject<E[]> = ...

Create notifications that broacast the entire set of entries.

notifyDelta: ReplaySubject<Delta<E>> = ...

Create notifications that broacast store or slice delta state changes.

notifyQuery: ReplaySubject<string> = ...

Notifies observers of the store query.

obs: Observable<E[]> = ...

An Observable<E[]> reference to the entities in the store or Slice instance.

predicate: Predicate<E>

The slice predicate

Accessors

  • get GUID_KEY(): string
  • The current guid key for the EStore instance.

    Returns string

    this.config.guidKey;

  • get ID_KEY(): string
  • The current id key for the EStore instance.

    Returns string

    this.config.idKey;

  • get query(): string
  • Returns string

    A snapshot of the query state.

  • set query(query): void
  • Sets the current query state and notifies observers.

    Parameters

    • query: string

    Returns void

Methods

  • Snapshot of all entries.

    Returns E[]

    Snapshot array of all the elements the entities the store contains.

    Example: Observe a snapshot of all the entities in the store.

    let selectedTodos:Todo[] = source.allSnapshot();
    
  • Returns true if the entries contain the identified instance.

    Parameters

    • target: string | E

      Either an instance of type E or a guid identifying the instance.

    Returns boolean

    true if the instance identified by the guid exists, false otherwise.

    Example

    <pre>
    let contains:boolean = source.contains(guid);
    </pre>
  • Returns true if the entries contain the identified instance.

    Parameters

    • target: string | E

      Either an instance of type E or a id identifying the instance.

    Returns boolean

    true if the instance identified by the id exists, false otherwise.

    Example

    <pre>
    let contains:boolean = source.contains(guid);
    </pre>
  • Returns the number of entries contained.

    Parameters

    • Optional p: Predicate<E>

      The predicate to apply in order to filter the count

    Returns Observable<number>

  • Delete an element from the slice.

    Parameters

    • e: E | E[]

      The element to be deleted if it satisfies the predicate

    Returns void

  • Parameters

    • e: E[]

      The elements to be deleted if they satisfy the predicate

    Returns void

  • Parameters

    • Rest ...e: E[]

      The elements to be deleted if it satisfies the predicate

    Returns void

  • Compare entities by GUID

    Parameters

    • e1: any

      The first entity

    • e2: any

      The second entity

    Returns boolean

    true if the two entities have equal GUID ids

    Example: Compare todo1 with todo2 by gid.

    if (equalsByGUID(todo1, todo2)){...};
    
  • Compare entities by ID

    Parameters

    • e1: any

      The first entity

    • e2: any

      The second entity

    Returns boolean

    true if the two entities have equal ID ids

    Example: Compare todo1 with todo2 by id.

    if (equalsByID(todo1, todo2)){...};
    
  • Find and return the entity identified by the GUID parameter if it exists and return it.

    Parameters

    • guid: string

    Returns undefined | E

    The entity instance if it exists, null otherwise

  • Find and return the entity identified by the ID parameter if it exists and return it.

    Parameters

    • id: string

    Returns undefined | E

    The entity instance if it exists, null otherwise

  • Check whether the store is empty.

    Returns Observable<boolean>

    A hot Observable that indicates whether the store is empty.

    Example

    const empty$:Observable<boolean> = source.isEmpty();
    
  • Check whether the store is empty.

    Returns boolean

    A snapshot that indicates whether the store is empty.

    Example

    const empty:boolean = source.isEmptySnapshot();
    
  • Observe store state changes.

    Parameters

    • Optional sort: ((a, b) => number)

      Optional sorting function yielding a sorted observable.

        • (a, b): number
        • Parameters

          • a: any
          • b: any

          Returns number

    Returns Observable<E[]>

    Example

    let todos$ = source.observe();
    //or with a sort by title function
    let todos$ = source.observe((a, b)=>(a.title > b.title ? -1 : 1));
  • Add the element if it satisfies the predicate and notify subscribers that an element was added.

    Parameters

    • e: E | E[]

      The element to be considered for slicing

    Returns void

  • Add the elements if they satisfy the predicate and notify subscribers that elements were added.

    Parameters

    • e: E[]

      The element to be considered for slicing

    Returns void

  • Add the elements if they satisfy the predicate and notify subscribers that elements were added.

    Parameters

    • Rest ...e: E[]

      The element to be considered for slicing

    Returns void

  • Update the slice when an Entity instance mutates.

    Parameters

    • e: E | E[]

      The element to be added or deleted depending on predicate reevaluation

    Returns void

  • Parameters

    • e: E[]

      The elements to be put

    Returns void

  • Update the slice with mutated Entity instances.

    Parameters

    • Rest ...e: E[]

      The elements to be deleted if it satisfies the predicate

    Returns void

  • Resets the slice to empty.

    Returns void

  • Snapshot of the entries that match the predicate.

    Parameters

    • p: Predicate<E>

      The predicate used to query for the selection.

    Returns E[]

    A snapshot array containing the entities that match the predicate.

    Example: Select all the Todo instances where the title length is greater than 100.

    let todos:Todo[]=store.select(todo=>todo.title.length>100);
    
  • Utility method that applies the predicate to an array of entities and return the ones that pass the test.

    Used to create an initial set of values that should be part of the Slice.

    Parameters

    Returns E[]

    The the array of entities that pass the predicate test.

Generated using TypeDoc