Class AbstractDataSource<EntityType>Abstract

Abstract DataSource class

A DataSource collection is a single source of truth for all types of data. When the DataSource changes it fires an event. All components and stores listen to the 'change' event to update themselves. This approach reduces the amount of code that has to be written and maintained.

Use a {@see DataSourceStore} in components to list data from datasources. The {@see Form} component can also load from a datasource.

Type Parameters

Hierarchy

Constructors

Properties

_browserStore?: BrowserStore
_createId: number = 0
_state?: string

JMAP state

commitBaseParams: {} = {}

Extra parameters to send to the Foo/set

Type declaration

    creates: Record<string, SaveData<EntityType>> = {}
    data: Record<string, EntityType> = {}
    delayedCommit: ((...args) => void)

    Type declaration

      • (...args): void
      • Parameters

        • Rest ...args: any[]

        Returns void

    delayedGet: ((...args) => void)

    Type declaration

      • (...args): void
      • Parameters

        • Rest ...args: any[]

        Returns void

    destroys: Record<string, DestroyData> = {}
    getIds: Record<string, GetData> = {}
    id: string
    persist: boolean = true

    Store data in the browser storage so it will persist across sessions

    setParams: {
        [key: string]: any;
    } = {}

    Extra /set parameters that will reset after commit

    Type declaration

    • [key: string]: any
    updates: Record<string, SaveData<EntityType>> = {}

    Accessors

    Methods

    • Private

      Check's if we are up-to-date with the server and fetches updates if needed.

      If no state is returned by the data source this function will ignore states and the data source should then always refresh data.

      Type Parameters

      • T

      Parameters

      • serverState: undefined | string
      • retVal: T

      Returns Promise<T>

    • Ask for confirmation and delete entities by ID

      Parameters

      • ids: string[]

        The ID's to delete

      Returns Promise<false | unknown[]>

      Example

      const tbl = this.projectTable!,
      ids = tbl.rowSelection!.selected.map(index => tbl.store.get(index)!.id);

      const result = await jmapds("Project3")
      .confirmDestroy(ids);

      if(result != false) {
      btn.parent!.hide();
      }
    • Create entity

      Multiple calls will be joined together in a single call on the next event loop

      Parameters

      • data: Partial<EntityType>
      • Optional createId: string

        The create ID to use when committing this entity to the server

      Returns Promise<EntityType>

    • Destroy an entity

      Multiple calls will be joined together in a single call on the next event loop

      Parameters

      • id: string

      Returns Promise<unknown>

    • Protected

      Does the actual getting of entities. First checks if present in this onbject, otherwise it will be requested from the remote source.

      Returns Promise<void>

    • Protected

      Get the local server state ID of the store

      Returns Promise<undefined | string>

    • Reset the data source.

      Clears all data and will resync

      Returns Promise<undefined | boolean>

    • Protected

      Set's the local server state ID

      Setting it to undefined will reset the store.

      Parameters

      • state: undefined | string

      Returns Promise<undefined | boolean>

    • Get a single entity.

      Multiple calls will be buffered and returned together on the next event loop. This way multiple calls can be joined together in a single HTTP request to the server.

      Parameters

      • id: string

      Returns Promise<undefined | EntityType>

    • Update an entity

      Multiple calls will be joined together in a single call on the next event loop

      Parameters

      • id: string
      • data: Partial<EntityType>

      Returns Promise<EntityType>

    Generated using TypeDoc