Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AbstractStore<E>

Type parameters

  • E

Hierarchy

Index

Constructors

constructor

Properties

Protected _query

_query: string = ""

The current query state.

config

config: StoreConfig

The configuration for the store.

entries

entries: Map<string, E> = new Map()

Primary index for the stores elements.

idEntries

idEntries: Map<string, E> = new Map()

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

Protected notify

notify: ReplaySubject<E[]> = new ReplaySubject<E[]>(1)

Create notifications that broacast the entire set of entries.

Protected notifyDelta

notifyDelta: ReplaySubject<Delta<E>> = new ReplaySubject<Delta<E>>(1)

Create notifications that broacast store or slice delta state changes.

Protected notifyEmptyState

notifyEmptyState: ReplaySubject<E[]> = new ReplaySubject<E[]>(1)

Notifies observers when the store is empty.

Protected notifyEntryCount

notifyEntryCount: ReplaySubject<E[]> = new ReplaySubject<E[]>(1)

Notifies observers of changes to the number of entries in the store.

Protected notifyQuery

notifyQuery: ReplaySubject<string> = new ReplaySubject<string>(1)

Notifies observers of the store query.

Accessors

GUID_KEY

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

    Returns string

    this.config.guidKey;

ID_KEY

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

    Returns string

    this.config.idKey;

query

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

    Returns string

    A snapshot of the query state.

  • Sets the current query state and notifies observers.

    Parameters

    • query: string

    Returns void

    A snapshot of the query state.

Methods

allSnapshot

  • allSnapshot(): E[]
  • Snapshot of all entries.

    example

    Observe a snapshot of all the entities in the store.

    let selectedTodos:Todo[] = source.allSnapshot();

    Returns E[]

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

contains

  • contains(target: E | string): boolean
  • Returns true if the entries contain the identified instance.

    example
    let contains:boolean = source.contains(guid);
    

    Parameters

    • target: E | string

      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.

containsById

  • containsById(target: E | string): boolean
  • Returns true if the entries contain the identified instance.

    example
    let contains:boolean = source.contains(guid);
    

    Parameters

    • target: E | string

      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.

count

  • count(p?: Predicate<E>): Observable<number>
  • Returns the number of entries contained.

    Parameters

    • Optional p: Predicate<E>

      The predicate to apply in order to filter the count

    Returns Observable<number>

countSnapshot

  • Returns a snapshto of the number of entries contained in the store.

    Parameters

    • Optional p: Predicate<E>

      The predicate to apply in order to filter the count

    Returns number

destroy

  • destroy(): void
  • Calls complete on all {@link BehaviorSubject} instances.

    Call destroy when disposing of the store.

    Returns void

equalsByGUID

  • equalsByGUID(e1: any, e2: any): boolean
  • Compare entities by GUID

    example

    Compare todo1 with todo2 by gid.

    if (equalsByGUID(todo1, todo2)){...};

    Parameters

    • e1: any

      The first entity

    • e2: any

      The second entity

    Returns boolean

    true if the two entities have equal GUID ids

equalsByID

  • equalsByID(e1: any, e2: any): boolean
  • Compare entities by ID

    example

    Compare todo1 with todo2 by id.

    if (equalsByID(todo1, todo2)){...};

    Parameters

    • e1: any

      The first entity

    • e2: any

      The second entity

    Returns boolean

    true if the two entities have equal ID ids

findOne

  • findOne(guid: string): E
  • Find and return the entity identified by the GUID parameter if it exists and return it.

    Parameters

    • guid: string

    Returns E

    The entity instance if it exists, null otherwise

findOneByID

  • findOneByID(id: string): E
  • Find and return the entity identified by the ID parameter if it exists and return it.

    Parameters

    • id: string

    Returns E

    The entity instance if it exists, null otherwise

isEmpty

  • isEmpty(): Observable<boolean>
  • Check whether the store is empty.

    example
    source.isEmpty();
    

    Returns Observable<boolean>

    A hot {@link Observable} that indicates whether the store is empty.

isEmptySnapshot

  • isEmptySnapshot(): boolean
  • Check whether the store is empty.

    example
    source.isEmpty();
    

    Returns boolean

    A snapshot that indicates whether the store is empty.

Protected notifyAll

  • notifyAll(v: E[], delta: Delta<E>): void

observe

  • observe(sort?: (a: any, b: any) => number): Observable<E[]>
  • Observe store state changes.

    example
    let todos$ = source.observe();
    or with a sort function
    let todos$ = source.observe((a, b)=>(a.title > b.title ? -1 : 1));

    Parameters

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

      Optional sorting function yielding a sorted observable.

        • (a: any, b: any): number
        • Parameters

          • a: any
          • b: any

          Returns number

    Returns Observable<E[]>

observeDelta

  • observeDelta(): Observable<Delta<E>>
  • Observe delta updates.

    example
    let todos$ = source.subscribeDelta();
    

    Returns Observable<Delta<E>>

observeQuery

  • observeQuery(): Observable<string>
  • Observe the query.

    example
    let query$ = source.observeQuery();
    

    Returns Observable<string>

select

  • Snapshot of the entries that match the predicate.

    example

    Select all the Todo instance where the title length is greater than 100.

    let todos:Todo[]=store.select(todo=>todo.title.length>100);

    Parameters

    • p: Predicate<E>

      The predicate used to query for the selection.

    Returns E[]

    A snapshot array containing the entities that match the predicate.

Generated using TypeDoc