Datalynk Client
    Preparing search index...

    Class Slice<T>

    An object to aid in constructing Datalynk requests

    Type Parameters

    • T extends Meta = any
    Index

    Constructors

    • An object to aid in constructing requests

      Type Parameters

      • T extends Meta = any

      Parameters

      • slice: string | number

        Slice ID to interact with

      • api: Api

        Api to send the requests through

      Returns Slice<T>

    Properties

    cache$: BehaviorSubject<T[]> = ...

    Cached slice data as an observable

    unsubscribe?: null | Unsubscribe

    Unsubscribe from changes, undefined if not subscribed

    idMap: { [key: number]: number } = {}
    nextId: number = 0

    Accessors

    • get cache(): T[]

      Cached slice data

      Returns T[]

    • set cache(cache: T[]): void

      Set cached data & alert subscribers

      Parameters

      • cache: T[]

      Returns void

    • get offlineEnabled(): undefined | boolean

      Whether this slice has local IndexedDB/offline support enabled.

      Offline-enabled slices can fall back to their local cache when either the browser loses network connectivity or the Datalynk client enters an unavailable recovery state after a returned server/API failure.

      Returns undefined | boolean

    Methods

    • Count the returned rows

      Parameters

      • arg: string | object = 'id'

        Count argument

      Returns ApiCall<T>

    • Set the request type to delete

      Parameters

      • id: number | number[]

        ID(s) to delete

      Returns ApiCall<T>

    • Get slice information

      Parameters

      • Optionalreload: boolean

        Ignore cache & reload info

      Returns Promise<SliceInfo>

    • Set the request type to insert

      Parameters

      • rows: T | T[]

        Rows to be inserted into the slice

      Returns ApiCall<T>

    • Returns Promise<void>

    • Save multiple rows to the slice, automatically inserts/updates

      Parameters

      • rows: T | T[]

        Rows to add to slice

      Returns ApiCall<T>

    • Set the request type to select

      Parameters

      • Optionalid: number | number[]

        ID(s) to select, leaving blank will return all rows

      Returns ApiCall<T>

    • Synchronize the local slice cache with the server and subscribe to socket changes.

      For an offline-enabled slice, synchronization failures caused by network or API unavailability are contained in the background rather than becoming unhandled promise rejections. Local cached data remains usable while the Api recovery loop determines when the failed API path works again. When the client becomes online again, pending local changes are scheduled for upload without overlapping push operations.

      Calling sync(false) unsubscribes from slice socket events.

      Parameters

      • on: boolean = true

        Enable or disable synchronization/socket events.

      Returns undefined | BehaviorSubject<T[]>

      The observable local cache when synchronization is enabled.

      const slice: Slice = new Slice<T>(Slices.Contact);
      const rows$ = slice.sync();
      rows$?.subscribe((rows: T[]) => console.log(rows));
    • Set the request type to update

      Parameters

      • rows: T | T[]

        Rows to be updated, each row must have an ID

      Returns ApiCall<T>