Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Slice<E>

Type parameters

  • E

Hierarchy

Index

Constructors

constructor

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

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

    Parameters

    • label: string

      The slice label

    • predicate: Predicate<E>

      The slice predicate

    • Optional sc: StoreConfig
    • Optional entities: E[]

      Elements to be considered for slicing

    Returns Slice

Properties

Protected _query

_query: string = ""

The current query state.

config

config: StoreConfig

The configuration for the store.

entries

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

idEntries

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

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

label

label: string

The slice label

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.

predicate

predicate: Predicate<E>

The slice predicate

Private Optional sc

Accessors

GUID_KEY

  • get GUID_KEY(): string

ID_KEY

  • get ID_KEY(): string

query

  • get query(): string
  • set query(query: string): void

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>

countSnapshot

delete

  • delete(e: E): void
  • Delete an element from the slice.

    Parameters

    • e: E

      The element to be deleted if it satisfies the predicate

    Returns void

deleteA

  • deleteA(e: E[]): void
  • Parameters

    • e: E[]

      The elements to be deleted if they satisfy the predicate

    Returns void

deleteN

  • deleteN(...e: E[]): void
  • Parameters

    • Rest ...e: E[]

      The elements to be deleted if it satisfies the predicate

    Returns void

destroy

  • destroy(): 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

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

observeQuery

  • observeQuery(): Observable<string>

post

  • post(e: E): void
  • Add the element if it satisfies the predicate and notify subscribers that an element was added.

    Parameters

    • e: E

      The element to be considered for slicing

    Returns void

postA

  • postA(e: E[]): 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

postN

  • postN(...e: E[]): 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

put

  • put(e: E): void
  • Update the slice when an Entity instance mutates.

    Parameters

    • e: E

      The element to be added or deleted depending on predicate reevaluation

    Returns void

putA

  • putA(e: E[]): void
  • Parameters

    • e: E[]

      The elements to be put

    Returns void

putN

  • putN(...e: E[]): void
  • Update the slice with mutated Entity instances.

    Parameters

    • Rest ...e: E[]

      The elements to be deleted if it satisfies the predicate

    Returns void

reset

  • reset(): void
  • Resets the slice to empty.

    Returns void

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.

test

  • Utility method that applies the predicate to an array of entities and return the ones that pass the test.

    This can be used to create an initial set of values that should be part of the slice, such that the Slices notifier performs a notification with this set of values as soon as the slice is instantiated.

    Parameters

    Returns E[]

    The the array of entities that pass the predicate test.

Generated using TypeDoc