t×tecexpressby TeKOcloud
DEv0.7.1
API & types / VUE

TxDataSource.

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.

ts
new TxDataSource<T>(config: TxDataSourceConfig<T> | T[]): TxDataSource<T>
MemberType / returnBehavior
storeTxStore<T>Data collection or custom store contract.
keyTxSelector<T>Stable key or selector; distinct from a widget key.
itemsT[]Entries; replaced by dataSource when bound.
groupsTxGroup<T>[] | undefinedResult group hierarchy.
totalCountnumberTotal filtered record count before paging.
groupCountnumber | undefinedTop-level group count before paging.
loadingbooleanShows the loading state.
errorunknownMost recent load/write error.
loadedbooleanAt least one load completed successfully.
configTxDataSourceConfig<T>Instance configuration.
containsKey(key: TxKey) => boolean | undefinedReturns false for known removals, a boolean for an array store, otherwise undefined/null.
subscribe(listener: () => void) => () => voidRegisters a change listener and returns an unsubscribe function.
pendingLoadPromise<T[]> | undefinedPromise 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() => voidSet 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() => voidStops queries and listeners; do not use the instance afterward.
ts
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()