Copied in-memory collection with local queries and key-based CRUD operations.
Vue: data = [], key = "id". Dart: data is required; without keyOf only queries are supported. Construction copies the list. Duplicate keys, insertion of existing keys and key changes are rejected. update/remove with an unknown key fail; byKey returns undefined/null.
TxArrayStore
| Parameter | Type | Default | Meaning |
|---|---|---|---|
| data | List<T> | required | Records or event payload. |
| keyOf | TxKeyOf<T>? | null | Reads the stable record key. |
| Member / type / return | Meaning |
|---|---|
List<T> get data | Records or event payload. |
bool get canByKey | Whether the store supports ByKey. |
bool get canInsert | Whether the store supports Insert. |
bool get canUpdate | Whether the store supports Update. |
bool get canRemove | Whether the store supports Remove. |
TxLoadResult<T> load(TxLoadOptions<T> options) | Loads using the supplied options; DataSource uses current query state without arguments. Errors propagate. |
T? byKey(Object key) | Reads a record by key; missing keys return undefined (Vue) or null (Dart). |
T insert(T item) | Inserts a record with a unique key and returns it. |
T update(Object key, T Function(T) change) | Updates a notification or record. |
void remove(Object key) | Removes the record or recursively removes a file/directory tree. |
import 'package:tecexpress/tecexpress.dart';
Future<void> example() async {
final store = TxArrayStore<Map<String, Object>>([{'id': 1}], keyOf: (row) => row['id']!);
print(store.load(const TxLoadOptions()));
print(store.byKey(1));
store.insert({'id': 2});
store.update(2, (row) => {...row, 'name': 'Two'});
store.remove(2);
}