Observable data source with query state and asynchronous loading. Writes reload the data; its owner disposes the instance.
Default configuration: pageSize 20, pageIndex 0, paginate true; array stores are local, other stores remote. The Vue array shorthand retains paging; Dart TxDataSource.array defaults to paginate false. items starts empty; call load() unless a bound consumer triggers the initial load. Invalid paging is rejected. Replace the store and key by creating a new instance. configure returns a Promise/Future of the reloaded list. byKey returns a Promise/Future of a record or undefined/null; insert/update return the written record and remove returns no value. Vue push returns the new list; Dart push returns no value. cancel/dispose return no value. Load/write failures are also exposed in error. For unsupported operations Vue throws Error and Dart throws UnsupportedError. Loading after disposal fails.
new TxDataSource<T>(config: TxDataSourceConfig<T> | T[]): TxDataSource<T>| Member | Type / return | Behavior |
|---|---|---|
| store | TxStore<T> | Data collection or custom store contract. |
| key | TxSelector<T> | Stable key or selector; distinct from a widget key. |
| items | T[] | Entries; replaced by dataSource when bound. |
| groups | TxGroup<T>[] | undefined | Result group hierarchy. |
| totalCount | number | Total filtered record count before paging. |
| groupCount | number | undefined | Top-level group count before paging. |
| loading | boolean | Shows the loading state. |
| error | unknown | Most recent load/write error. |
| loaded | boolean | At least one load completed successfully. |
| config | TxDataSourceConfig<T> | Instance configuration. |
| containsKey | (key: TxKey) => boolean | undefined | Returns false for known removals, a boolean for an array store, otherwise undefined/null. |
| subscribe | (listener: () => void) => () => void | Registers a change listener and returns an unsubscribe function. |
| pendingLoad | Promise<T[]> | undefined | Promise for the most recently started load. |
| load | () => Promise<T[]> | Loads using the supplied options; DataSource uses current query state without arguments. Errors propagate. |
| reload | () => Promise<T[]> | Reloads the current query and returns visible records. |
| configure | (changes: Partial<TxDataSourceConfig<T>>) => Promise<T[]> | Changes query options and reloads. Search, filter and page size reset the page unless explicitly supplied. |
| cancel | () => void | Set synchronously to true to cancel the action. |
| byKey | (key: TxKey) => Promise<Awaited<T> | undefined> | Reads a record by key; missing keys return undefined (Vue) or null (Dart). |
| insert | (item: T) => Promise<T> | Inserts a record with a unique key and returns it. |
| update | (key: TxKey, changes: Partial<T>) => Promise<T> | Updates a notification or record. |
| remove | (key: TxKey) => Promise<void> | Removes the record or recursively removes a file/directory tree. |
| push | (changes: TxPush<T>[]) => Promise<T[]> | Runs store writes sequentially and reloads once; not a transaction, partial success is possible on error. |
| dispose | () => void | Stops queries and listeners; do not use the instance afterward. |
import { TxDataSource } from '@tekocloud.de/tecexpress'
const source = new TxDataSource({ store: [{ id: 1, text: 'One' }], key: 'id', pageSize: 10 })
const unsubscribe = source.subscribe(() => console.log(source.loading, source.error))
await source.load()
await source.configure({ searchExpr: ['text'], searchValue: 'One' })
console.log(await source.byKey(1), source.containsKey(1))
await source.insert({ id: 2, text: 'Two' })
await source.update(2, { text: 'Updated' })
await source.push([{ type: 'update', key: 2, data: { text: 'Changed' } }])
await source.remove(2)
await source.reload()
source.cancel()
unsubscribe()
source.dispose()