tinybase 6.1.0-beta.5 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/persisters/index.d.ts +82 -0
- package/@types/persisters/with-schemas/index.d.ts +91 -0
- package/@types/store/index.d.ts +123 -1
- package/@types/store/with-schemas/index.d.ts +159 -24
- package/@types/ui-react/index.d.ts +120 -0
- package/@types/ui-react/with-schemas/index.d.ts +179 -37
- package/index.js +73 -53
- package/mergeable-store/index.js +73 -53
- package/mergeable-store/with-schemas/index.js +73 -53
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/mergeable-store/index.js +1 -1
- package/min/mergeable-store/index.js.gz +0 -0
- package/min/mergeable-store/with-schemas/index.js +1 -1
- package/min/mergeable-store/with-schemas/index.js.gz +0 -0
- package/min/persisters/index.js +1 -1
- package/min/persisters/index.js.gz +0 -0
- package/min/persisters/persister-automerge/index.js +1 -1
- package/min/persisters/persister-automerge/index.js.gz +0 -0
- package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
- package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-browser/index.js +1 -1
- package/min/persisters/persister-browser/index.js.gz +0 -0
- package/min/persisters/persister-browser/with-schemas/index.js +1 -1
- package/min/persisters/persister-browser/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-cr-sqlite-wasm/index.js +1 -1
- package/min/persisters/persister-cr-sqlite-wasm/index.js.gz +0 -0
- package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +1 -1
- package/min/persisters/persister-cr-sqlite-wasm/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-storage/index.js +1 -1
- package/min/persisters/persister-durable-object-storage/index.js.gz +0 -0
- package/min/persisters/persister-durable-object-storage/with-schemas/index.js +1 -1
- package/min/persisters/persister-durable-object-storage/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-electric-sql/index.js +1 -1
- package/min/persisters/persister-electric-sql/index.js.gz +0 -0
- package/min/persisters/persister-electric-sql/with-schemas/index.js +1 -1
- package/min/persisters/persister-electric-sql/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-expo-sqlite/index.js +1 -1
- package/min/persisters/persister-expo-sqlite/index.js.gz +0 -0
- package/min/persisters/persister-expo-sqlite/with-schemas/index.js +1 -1
- package/min/persisters/persister-expo-sqlite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-file/index.js +1 -1
- package/min/persisters/persister-file/index.js.gz +0 -0
- package/min/persisters/persister-file/with-schemas/index.js +1 -1
- package/min/persisters/persister-file/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-indexed-db/index.js +1 -1
- package/min/persisters/persister-indexed-db/index.js.gz +0 -0
- package/min/persisters/persister-indexed-db/with-schemas/index.js +1 -1
- package/min/persisters/persister-indexed-db/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-libsql/index.js +1 -1
- package/min/persisters/persister-libsql/index.js.gz +0 -0
- package/min/persisters/persister-libsql/with-schemas/index.js +1 -1
- package/min/persisters/persister-libsql/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-partykit-client/index.js +1 -1
- package/min/persisters/persister-partykit-client/index.js.gz +0 -0
- package/min/persisters/persister-partykit-client/with-schemas/index.js +1 -1
- package/min/persisters/persister-partykit-client/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-pglite/index.js +1 -1
- package/min/persisters/persister-pglite/index.js.gz +0 -0
- package/min/persisters/persister-pglite/with-schemas/index.js +1 -1
- package/min/persisters/persister-pglite/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-postgres/index.js +1 -1
- package/min/persisters/persister-postgres/index.js.gz +0 -0
- package/min/persisters/persister-postgres/with-schemas/index.js +1 -1
- package/min/persisters/persister-postgres/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-powersync/index.js +1 -1
- package/min/persisters/persister-powersync/index.js.gz +0 -0
- package/min/persisters/persister-powersync/with-schemas/index.js +1 -1
- package/min/persisters/persister-powersync/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-remote/index.js +1 -1
- package/min/persisters/persister-remote/index.js.gz +0 -0
- package/min/persisters/persister-remote/with-schemas/index.js +1 -1
- package/min/persisters/persister-remote/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-bun/index.js +1 -1
- package/min/persisters/persister-sqlite-bun/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-bun/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-bun/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-wasm/index.js +1 -1
- package/min/persisters/persister-sqlite-wasm/index.js.gz +0 -0
- package/min/persisters/persister-sqlite-wasm/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite-wasm/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-sqlite3/index.js +1 -1
- package/min/persisters/persister-sqlite3/index.js.gz +0 -0
- package/min/persisters/persister-sqlite3/with-schemas/index.js +1 -1
- package/min/persisters/persister-sqlite3/with-schemas/index.js.gz +0 -0
- package/min/persisters/persister-yjs/index.js +1 -1
- package/min/persisters/persister-yjs/index.js.gz +0 -0
- package/min/persisters/persister-yjs/with-schemas/index.js +1 -1
- package/min/persisters/persister-yjs/with-schemas/index.js.gz +0 -0
- package/min/persisters/with-schemas/index.js +1 -1
- package/min/persisters/with-schemas/index.js.gz +0 -0
- package/min/store/index.js +1 -1
- package/min/store/index.js.gz +0 -0
- package/min/store/with-schemas/index.js +1 -1
- package/min/store/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/index.js +1 -1
- package/min/synchronizers/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
- package/min/synchronizers/synchronizer-broadcast-channel/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-local/index.js +1 -1
- package/min/synchronizers/synchronizer-local/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-local/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-client/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-client/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-client/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-durable-object/index.js.gz +0 -0
- package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
- package/min/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js.gz +0 -0
- package/min/synchronizers/with-schemas/index.js +1 -1
- package/min/synchronizers/with-schemas/index.js.gz +0 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/package.json +6 -6
- package/persisters/index.js +33 -8
- package/persisters/persister-automerge/index.js +23 -3
- package/persisters/persister-automerge/with-schemas/index.js +23 -3
- package/persisters/persister-browser/index.js +23 -3
- package/persisters/persister-browser/with-schemas/index.js +23 -3
- package/persisters/persister-cr-sqlite-wasm/index.js +33 -8
- package/persisters/persister-cr-sqlite-wasm/with-schemas/index.js +33 -8
- package/persisters/persister-durable-object-storage/index.js +23 -3
- package/persisters/persister-durable-object-storage/with-schemas/index.js +23 -3
- package/persisters/persister-electric-sql/index.js +33 -8
- package/persisters/persister-electric-sql/with-schemas/index.js +33 -8
- package/persisters/persister-expo-sqlite/index.js +33 -8
- package/persisters/persister-expo-sqlite/with-schemas/index.js +33 -8
- package/persisters/persister-file/index.js +23 -3
- package/persisters/persister-file/with-schemas/index.js +23 -3
- package/persisters/persister-indexed-db/index.js +23 -3
- package/persisters/persister-indexed-db/with-schemas/index.js +23 -3
- package/persisters/persister-libsql/index.js +33 -8
- package/persisters/persister-libsql/with-schemas/index.js +33 -8
- package/persisters/persister-partykit-client/index.js +23 -3
- package/persisters/persister-partykit-client/with-schemas/index.js +23 -3
- package/persisters/persister-pglite/index.js +33 -8
- package/persisters/persister-pglite/with-schemas/index.js +33 -8
- package/persisters/persister-postgres/index.js +33 -8
- package/persisters/persister-postgres/with-schemas/index.js +33 -8
- package/persisters/persister-powersync/index.js +33 -8
- package/persisters/persister-powersync/with-schemas/index.js +33 -8
- package/persisters/persister-remote/index.js +23 -3
- package/persisters/persister-remote/with-schemas/index.js +23 -3
- package/persisters/persister-sqlite-bun/index.js +33 -8
- package/persisters/persister-sqlite-bun/with-schemas/index.js +33 -8
- package/persisters/persister-sqlite-wasm/index.js +33 -8
- package/persisters/persister-sqlite-wasm/with-schemas/index.js +33 -8
- package/persisters/persister-sqlite3/index.js +33 -8
- package/persisters/persister-sqlite3/with-schemas/index.js +33 -8
- package/persisters/persister-yjs/index.js +23 -3
- package/persisters/persister-yjs/with-schemas/index.js +23 -3
- package/persisters/with-schemas/index.js +33 -8
- package/readme.md +6 -6
- package/releases.md +23 -11
- package/store/index.js +73 -53
- package/store/with-schemas/index.js +73 -53
- package/synchronizers/index.js +27 -9
- package/synchronizers/synchronizer-broadcast-channel/index.js +27 -9
- package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +27 -9
- package/synchronizers/synchronizer-local/index.js +27 -9
- package/synchronizers/synchronizer-local/with-schemas/index.js +27 -9
- package/synchronizers/synchronizer-ws-client/index.js +27 -9
- package/synchronizers/synchronizer-ws-client/with-schemas/index.js +27 -9
- package/synchronizers/synchronizer-ws-server/index.js +27 -9
- package/synchronizers/synchronizer-ws-server/with-schemas/index.js +27 -9
- package/synchronizers/synchronizer-ws-server-durable-object/index.js +27 -9
- package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +27 -9
- package/synchronizers/with-schemas/index.js +27 -9
- package/ui-react/index.js +84 -20
- package/ui-react/with-schemas/index.js +84 -20
- package/ui-react-dom/index.js +1 -1
- package/ui-react-dom/with-schemas/index.js +1 -1
- package/ui-react-inspector/index.js +97 -57
- package/ui-react-inspector/with-schemas/index.js +97 -57
- package/with-schemas/index.js +73 -53
|
@@ -1307,6 +1307,88 @@ export interface Persister<Persist extends Persists = Persists.StoreOnly> {
|
|
|
1307
1307
|
*/
|
|
1308
1308
|
isAutoSaving(): boolean;
|
|
1309
1309
|
|
|
1310
|
+
/**
|
|
1311
|
+
* The startAutoPersist method is a convenience method that starts both
|
|
1312
|
+
* automatic loading and saving of the Store data.
|
|
1313
|
+
*
|
|
1314
|
+
* This simply runs the startAutoLoad and startAutoSave methods in sequence,
|
|
1315
|
+
* and returns a Promise that resolves when both have completed.
|
|
1316
|
+
*
|
|
1317
|
+
* This method can take `initialContent` to pass to the startAutoLoad method.
|
|
1318
|
+
* See its documentation for more details.
|
|
1319
|
+
*
|
|
1320
|
+
* If for some reason you want to start saving _before_ you start loading,
|
|
1321
|
+
* pass true as the second parameter.
|
|
1322
|
+
* @param initialContent An optional Content object used when the underlying
|
|
1323
|
+
* storage has not previously been populated.
|
|
1324
|
+
* @param startSaveFirst Whether to start saving before loading, defaulting to
|
|
1325
|
+
* false.
|
|
1326
|
+
* @returns A Promise containing a reference to the Persister object.
|
|
1327
|
+
* @example This example creates a Persister and starts automatically loading
|
|
1328
|
+
* and saving.
|
|
1329
|
+
*
|
|
1330
|
+
* ```js
|
|
1331
|
+
* import {createStore} from 'tinybase';
|
|
1332
|
+
* import {createSessionPersister} from 'tinybase/persisters/persister-browser';
|
|
1333
|
+
*
|
|
1334
|
+
* const persister = createSessionPersister(createStore(), 'pets');
|
|
1335
|
+
*
|
|
1336
|
+
* await persister.startAutoPersisting();
|
|
1337
|
+
* console.log(persister.isAutoSaving());
|
|
1338
|
+
* // -> true
|
|
1339
|
+
* console.log(persister.isAutoLoading());
|
|
1340
|
+
* // -> true
|
|
1341
|
+
*
|
|
1342
|
+
* persister.destroy();
|
|
1343
|
+
* ```
|
|
1344
|
+
* @category Lifecycle
|
|
1345
|
+
* @since v6.1.0
|
|
1346
|
+
*/
|
|
1347
|
+
startAutoPersisting(
|
|
1348
|
+
initialContent?: Content | (() => Content),
|
|
1349
|
+
startSaveFirst?: boolean,
|
|
1350
|
+
): Promise<this>;
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* The stopAutoPersist method is a convenience method that stops both
|
|
1354
|
+
* automatic loading and saving of the Store data.
|
|
1355
|
+
*
|
|
1356
|
+
* This simply runs the stopAutoLoad and stopAutoSave methods in sequence, and
|
|
1357
|
+
* returns a Promise that resolves when both have completed.
|
|
1358
|
+
*
|
|
1359
|
+
* If for some reason you want to stop saving _before_ you stop loading, pass
|
|
1360
|
+
* true as the second parameter.
|
|
1361
|
+
* @param stopSaveFirst Whether to stop saving before loading, defaulting to
|
|
1362
|
+
* false.
|
|
1363
|
+
* @returns A Promise containing a reference to the Persister object.
|
|
1364
|
+
* @example This example creates a Persister and starts, then stops,
|
|
1365
|
+
* automatically loading and saving.
|
|
1366
|
+
*
|
|
1367
|
+
* ```js
|
|
1368
|
+
* import {createStore} from 'tinybase';
|
|
1369
|
+
* import {createSessionPersister} from 'tinybase/persisters/persister-browser';
|
|
1370
|
+
*
|
|
1371
|
+
* const persister = createSessionPersister(createStore(), 'pets');
|
|
1372
|
+
*
|
|
1373
|
+
* await persister.startAutoPersisting();
|
|
1374
|
+
* console.log(persister.isAutoSaving());
|
|
1375
|
+
* // -> true
|
|
1376
|
+
* console.log(persister.isAutoLoading());
|
|
1377
|
+
* // -> true
|
|
1378
|
+
*
|
|
1379
|
+
* await persister.stopAutoPersisting();
|
|
1380
|
+
* console.log(persister.isAutoSaving());
|
|
1381
|
+
* // -> false
|
|
1382
|
+
* console.log(persister.isAutoLoading());
|
|
1383
|
+
* // -> false
|
|
1384
|
+
*
|
|
1385
|
+
* persister.destroy();
|
|
1386
|
+
* ```
|
|
1387
|
+
* @category Lifecycle
|
|
1388
|
+
* @since v6.1.0
|
|
1389
|
+
*/
|
|
1390
|
+
stopAutoPersisting(stopSaveFirst?: boolean): Promise<this>;
|
|
1391
|
+
|
|
1310
1392
|
/**
|
|
1311
1393
|
* The getStatus method lets you find out if the Persister is currently in the
|
|
1312
1394
|
* process of loading or saving content.
|
|
@@ -1400,6 +1400,97 @@ export interface Persister<
|
|
|
1400
1400
|
*/
|
|
1401
1401
|
isAutoSaving(): boolean;
|
|
1402
1402
|
|
|
1403
|
+
/**
|
|
1404
|
+
* The startAutoPersist method is a convenience method that starts both
|
|
1405
|
+
* automatic loading and saving of the Store data.
|
|
1406
|
+
*
|
|
1407
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1408
|
+
*
|
|
1409
|
+
* ```ts override
|
|
1410
|
+
* startAutoPersisting(
|
|
1411
|
+
* initialContent?: Content | (() => Content),
|
|
1412
|
+
* startSaveFirst?: boolean,
|
|
1413
|
+
* ): Promise<this>;
|
|
1414
|
+
* ```
|
|
1415
|
+
*
|
|
1416
|
+
* This simply runs the startAutoLoad and startAutoSave methods in sequence,
|
|
1417
|
+
* and returns a Promise that resolves when both have completed.
|
|
1418
|
+
*
|
|
1419
|
+
* This method can take `initialContent` to pass to the startAutoLoad method.
|
|
1420
|
+
* See its documentation for more details.
|
|
1421
|
+
*
|
|
1422
|
+
* If for some reason you want to start saving _before_ you start loading,
|
|
1423
|
+
* pass true as the second parameter.
|
|
1424
|
+
* @param initialContent An optional Content object used when the underlying
|
|
1425
|
+
* storage has not previously been populated.
|
|
1426
|
+
* @param startSaveFirst Whether to start saving before loading, defaulting to
|
|
1427
|
+
* false.
|
|
1428
|
+
* @returns A Promise containing a reference to the Persister object.
|
|
1429
|
+
* @example This example creates a Persister and starts automatically loading
|
|
1430
|
+
* and saving.
|
|
1431
|
+
*
|
|
1432
|
+
* ```js
|
|
1433
|
+
* import {createStore} from 'tinybase';
|
|
1434
|
+
* import {createSessionPersister} from 'tinybase/persisters/persister-browser';
|
|
1435
|
+
*
|
|
1436
|
+
* const persister = createSessionPersister(createStore(), 'pets');
|
|
1437
|
+
*
|
|
1438
|
+
* await persister.startAutoPersisting();
|
|
1439
|
+
* console.log(persister.isAutoSaving());
|
|
1440
|
+
* // -> true
|
|
1441
|
+
* console.log(persister.isAutoLoading());
|
|
1442
|
+
* // -> true
|
|
1443
|
+
*
|
|
1444
|
+
* persister.destroy();
|
|
1445
|
+
* ```
|
|
1446
|
+
* @category Lifecycle
|
|
1447
|
+
* @since v6.1.0
|
|
1448
|
+
*/
|
|
1449
|
+
startAutoPersisting(
|
|
1450
|
+
initialContent?: Content<Schemas, true> | (() => Content<Schemas, true>),
|
|
1451
|
+
startSaveFirst?: boolean,
|
|
1452
|
+
): Promise<this>;
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* The stopAutoPersist method is a convenience method that stops both
|
|
1456
|
+
* automatic loading and saving of the Store data.
|
|
1457
|
+
*
|
|
1458
|
+
* This simply runs the stopAutoLoad and stopAutoSave methods in sequence, and
|
|
1459
|
+
* returns a Promise that resolves when both have completed.
|
|
1460
|
+
*
|
|
1461
|
+
* If for some reason you want to stop saving _before_ you stop loading, pass
|
|
1462
|
+
* true as the second parameter.
|
|
1463
|
+
* @param stopSaveFirst Whether to stop saving before loading, defaulting to
|
|
1464
|
+
* false.
|
|
1465
|
+
* @returns A Promise containing a reference to the Persister object.
|
|
1466
|
+
* @example This example creates a Persister and starts, then stops,
|
|
1467
|
+
* automatically loading and saving.
|
|
1468
|
+
*
|
|
1469
|
+
* ```js
|
|
1470
|
+
* import {createStore} from 'tinybase';
|
|
1471
|
+
* import {createSessionPersister} from 'tinybase/persisters/persister-browser';
|
|
1472
|
+
*
|
|
1473
|
+
* const persister = createSessionPersister(createStore(), 'pets');
|
|
1474
|
+
*
|
|
1475
|
+
* await persister.startAutoPersisting();
|
|
1476
|
+
* console.log(persister.isAutoSaving());
|
|
1477
|
+
* // -> true
|
|
1478
|
+
* console.log(persister.isAutoLoading());
|
|
1479
|
+
* // -> true
|
|
1480
|
+
*
|
|
1481
|
+
* await persister.stopAutoPersisting();
|
|
1482
|
+
* console.log(persister.isAutoSaving());
|
|
1483
|
+
* // -> false
|
|
1484
|
+
* console.log(persister.isAutoLoading());
|
|
1485
|
+
* // -> false
|
|
1486
|
+
*
|
|
1487
|
+
* persister.destroy();
|
|
1488
|
+
* ```
|
|
1489
|
+
* @category Lifecycle
|
|
1490
|
+
* @since v6.1.0
|
|
1491
|
+
*/
|
|
1492
|
+
stopAutoPersisting(stopSaveFirst?: boolean): Promise<this>;
|
|
1493
|
+
|
|
1403
1494
|
/**
|
|
1404
1495
|
* The getStatus method lets you find out if the Persister is currently in the
|
|
1405
1496
|
* process of loading or saving content.
|
package/@types/store/index.d.ts
CHANGED
|
@@ -576,6 +576,50 @@ export type ChangedValueIds = {[valueId: Id]: IdAddedOrRemoved};
|
|
|
576
576
|
*/
|
|
577
577
|
export type DoRollback = (store: Store) => boolean;
|
|
578
578
|
|
|
579
|
+
/**
|
|
580
|
+
* The SortedRowIdsArgs type describes the arguments used to sort Row Ids using
|
|
581
|
+
* the getSortedRowIds method.
|
|
582
|
+
*
|
|
583
|
+
* It's an object containing the Id of the Table in the Store, and optional
|
|
584
|
+
* `cellId`, `descending`, `offset`, and `limit` parameters. See the
|
|
585
|
+
* getSortedRowIds method for specific examples.
|
|
586
|
+
* @category Store
|
|
587
|
+
* @since v6.1.0
|
|
588
|
+
*/
|
|
589
|
+
export type SortedRowIdsArgs = {
|
|
590
|
+
/**
|
|
591
|
+
* The Id of the Table in the Store, required.
|
|
592
|
+
* @category Argument
|
|
593
|
+
* @since v6.1.0
|
|
594
|
+
*/
|
|
595
|
+
tableId: Id;
|
|
596
|
+
/**
|
|
597
|
+
* The optional Id of the Cell whose values are used for the sorting, defaults
|
|
598
|
+
* to sorting by the Row Id itself.
|
|
599
|
+
* @category Argument
|
|
600
|
+
* @since v6.1.0
|
|
601
|
+
*/
|
|
602
|
+
cellId?: Id;
|
|
603
|
+
/**
|
|
604
|
+
* Whether the sorting should be in descending order, defaulting to false.
|
|
605
|
+
* @category Argument
|
|
606
|
+
* @since v6.1.0
|
|
607
|
+
*/
|
|
608
|
+
descending?: boolean;
|
|
609
|
+
/**
|
|
610
|
+
* The number of Row Ids to skip for pagination purposes, defaulting to 0.
|
|
611
|
+
* @category Argument
|
|
612
|
+
* @since v6.1.0
|
|
613
|
+
*/
|
|
614
|
+
offset?: number;
|
|
615
|
+
/**
|
|
616
|
+
* The maximum number of Row Ids to return, defaulting to all.
|
|
617
|
+
* @category Argument
|
|
618
|
+
* @since v6.1.0
|
|
619
|
+
*/
|
|
620
|
+
limit?: number;
|
|
621
|
+
};
|
|
622
|
+
|
|
579
623
|
/**
|
|
580
624
|
* The TransactionListener type describes a function that is used to listen to
|
|
581
625
|
* the completion of a transaction for the Store.
|
|
@@ -2120,7 +2164,7 @@ export interface Store {
|
|
|
2120
2164
|
* any.
|
|
2121
2165
|
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
2122
2166
|
* all.
|
|
2123
|
-
* @returns An array of the sorted Ids of
|
|
2167
|
+
* @returns An array of the sorted Ids of appropriate Rows in the Table.
|
|
2124
2168
|
* @example
|
|
2125
2169
|
* This example retrieves sorted Row Ids in a Table.
|
|
2126
2170
|
*
|
|
@@ -2212,6 +2256,34 @@ export interface Store {
|
|
|
2212
2256
|
limit?: number,
|
|
2213
2257
|
): Ids;
|
|
2214
2258
|
|
|
2259
|
+
/**
|
|
2260
|
+
* When called with one object argument, the getSortedRowIds method
|
|
2261
|
+
* destructures it to make it easier to skip optional parameters.
|
|
2262
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
2263
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit`
|
|
2264
|
+
* parameters.
|
|
2265
|
+
* @returns An array of the sorted Ids of appropriate Rows in the Table.
|
|
2266
|
+
* @example
|
|
2267
|
+
* This example retrieves the first sorted Row Id in a Table.
|
|
2268
|
+
*
|
|
2269
|
+
* ```js
|
|
2270
|
+
* import {createStore} from 'tinybase';
|
|
2271
|
+
*
|
|
2272
|
+
* const store = createStore().setTables({
|
|
2273
|
+
* pets: {
|
|
2274
|
+
* fido: {species: 'dog'},
|
|
2275
|
+
* felix: {species: 'cat'},
|
|
2276
|
+
* cujo: {species: 'wolf'},
|
|
2277
|
+
* },
|
|
2278
|
+
* });
|
|
2279
|
+
* console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
|
|
2280
|
+
* // -> ['cujo']
|
|
2281
|
+
* ```
|
|
2282
|
+
* @category Getter
|
|
2283
|
+
* @since v6.1.0
|
|
2284
|
+
*/
|
|
2285
|
+
getSortedRowIds(args: SortedRowIdsArgs): Ids;
|
|
2286
|
+
|
|
2215
2287
|
/**
|
|
2216
2288
|
* The getRow method returns an object containing the entire data of a single
|
|
2217
2289
|
* Row in a given Table.
|
|
@@ -5673,6 +5745,56 @@ export interface Store {
|
|
|
5673
5745
|
mutator?: boolean,
|
|
5674
5746
|
): Id;
|
|
5675
5747
|
|
|
5748
|
+
/**
|
|
5749
|
+
* When called with an object as the first argument, the
|
|
5750
|
+
* addSortedRowIdsListener method destructures it to make it easier to skip
|
|
5751
|
+
* optional parameters.
|
|
5752
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
5753
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit`
|
|
5754
|
+
* parameters.
|
|
5755
|
+
* @param listener The function that will be called whenever the sorted Row
|
|
5756
|
+
* Ids in the Table change.
|
|
5757
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
5758
|
+
* Store data.
|
|
5759
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
5760
|
+
* explicitly, or to remove it.
|
|
5761
|
+
* @example
|
|
5762
|
+
* This example registers a listener that responds to any change to the first
|
|
5763
|
+
* of the sorted Row Ids of a specific Table.
|
|
5764
|
+
*
|
|
5765
|
+
* ```js
|
|
5766
|
+
* import {createStore} from 'tinybase';
|
|
5767
|
+
*
|
|
5768
|
+
* const store = createStore().setTables({
|
|
5769
|
+
* pets: {fido: {price: 6}, felix: {price: 5}},
|
|
5770
|
+
* });
|
|
5771
|
+
*
|
|
5772
|
+
* const listenerId = store.addSortedRowIdsListener(
|
|
5773
|
+
* {tableId: 'pets', limit: 1},
|
|
5774
|
+
* (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
5775
|
+
* console.log(`First sorted Row Id for ${tableId} table changed`);
|
|
5776
|
+
* console.log(sortedRowIds);
|
|
5777
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
5778
|
+
* },
|
|
5779
|
+
* );
|
|
5780
|
+
* console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
|
|
5781
|
+
* // -> ['felix']
|
|
5782
|
+
*
|
|
5783
|
+
* store.setRow('pets', 'carnaby', {price: 4.5});
|
|
5784
|
+
* // -> 'First sorted Row Id for pets table changed'
|
|
5785
|
+
* // -> ['carnaby']
|
|
5786
|
+
*
|
|
5787
|
+
* store.delListener(listenerId);
|
|
5788
|
+
* ```
|
|
5789
|
+
* @category Listener
|
|
5790
|
+
* @since v6.1.0
|
|
5791
|
+
*/
|
|
5792
|
+
addSortedRowIdsListener(
|
|
5793
|
+
args: SortedRowIdsArgs,
|
|
5794
|
+
listener: SortedRowIdsListener<this>,
|
|
5795
|
+
mutator?: boolean,
|
|
5796
|
+
): Id;
|
|
5797
|
+
|
|
5676
5798
|
/**
|
|
5677
5799
|
* The addHasRowListener method registers a listener function with the Store
|
|
5678
5800
|
* that will be called when a Row is added to or removed from the Store.
|
|
@@ -896,6 +896,56 @@ export type DoRollback<Schemas extends OptionalSchemas> = (
|
|
|
896
896
|
store: Store<Schemas>,
|
|
897
897
|
) => boolean;
|
|
898
898
|
|
|
899
|
+
/**
|
|
900
|
+
* The SortedRowIdsArgs type describes the arguments used to sort Row Ids using
|
|
901
|
+
* the getSortedRowIds method.
|
|
902
|
+
*
|
|
903
|
+
* It's an object containing the Id of the Table in the Store, and optional
|
|
904
|
+
* `cellId`, `descending`, `offset`, and `limit` parameters. See the
|
|
905
|
+
* getSortedRowIds method for specific examples.
|
|
906
|
+
* @category Store
|
|
907
|
+
* @since v6.1.0
|
|
908
|
+
*/
|
|
909
|
+
export type SortedRowIdsArgs<
|
|
910
|
+
Schema extends OptionalTablesSchema,
|
|
911
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
912
|
+
CellIdOrUndefined extends CellIdFromSchema<Schema, TableId> | undefined =
|
|
913
|
+
| CellIdFromSchema<Schema, TableId>
|
|
914
|
+
| undefined,
|
|
915
|
+
> = {
|
|
916
|
+
/**
|
|
917
|
+
* The Id of the Table in the Store, required.
|
|
918
|
+
* @category Argument
|
|
919
|
+
* @since v6.1.0
|
|
920
|
+
*/
|
|
921
|
+
tableId: TableId;
|
|
922
|
+
/**
|
|
923
|
+
* The optional Id of the Cell whose values are used for the sorting, defaults
|
|
924
|
+
* to sorting by the Row Id itself.
|
|
925
|
+
* @category Argument
|
|
926
|
+
* @since v6.1.0
|
|
927
|
+
*/
|
|
928
|
+
cellId?: CellIdOrUndefined;
|
|
929
|
+
/**
|
|
930
|
+
* Whether the sorting should be in descending order, defaulting to false.
|
|
931
|
+
* @category Argument
|
|
932
|
+
* @since v6.1.0
|
|
933
|
+
*/
|
|
934
|
+
descending?: boolean;
|
|
935
|
+
/**
|
|
936
|
+
* The number of Row Ids to skip for pagination purposes, defaulting to 0.
|
|
937
|
+
* @category Argument
|
|
938
|
+
* @since v6.1.0
|
|
939
|
+
*/
|
|
940
|
+
offset?: number;
|
|
941
|
+
/**
|
|
942
|
+
* The maximum number of Row Ids to return, defaulting to all.
|
|
943
|
+
* @category Argument
|
|
944
|
+
* @since v6.1.0
|
|
945
|
+
*/
|
|
946
|
+
limit?: number;
|
|
947
|
+
};
|
|
948
|
+
|
|
899
949
|
/**
|
|
900
950
|
* The TransactionListener type describes a function that is used to listen to
|
|
901
951
|
* the completion of a transaction for the Store.
|
|
@@ -1346,18 +1396,15 @@ export type RowIdsListener<
|
|
|
1346
1396
|
export type SortedRowIdsListener<
|
|
1347
1397
|
Schemas extends OptionalSchemas,
|
|
1348
1398
|
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
1349
|
-
|
|
1350
|
-
Descending extends boolean,
|
|
1351
|
-
Offset extends number,
|
|
1352
|
-
Limit extends number | undefined,
|
|
1399
|
+
CellIdOrUndefined extends CellIdFromSchema<Schemas[0], TableId> | undefined,
|
|
1353
1400
|
Store extends StoreAlias<Schemas> = StoreAlias<Schemas>,
|
|
1354
1401
|
> = (
|
|
1355
1402
|
store: Store,
|
|
1356
1403
|
tableId: TableId,
|
|
1357
|
-
cellId:
|
|
1358
|
-
descending:
|
|
1359
|
-
offset:
|
|
1360
|
-
limit:
|
|
1404
|
+
cellId: CellIdOrUndefined,
|
|
1405
|
+
descending: boolean,
|
|
1406
|
+
offset: number,
|
|
1407
|
+
limit: number | undefined,
|
|
1361
1408
|
sortedRowIds: Ids,
|
|
1362
1409
|
) => void;
|
|
1363
1410
|
|
|
@@ -3145,7 +3192,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
3145
3192
|
* any.
|
|
3146
3193
|
* @param limit The maximum number of Row Ids to return, or `undefined` for
|
|
3147
3194
|
* all.
|
|
3148
|
-
* @returns An array of the sorted Ids of
|
|
3195
|
+
* @returns An array of the sorted Ids of appropriate Rows in the Table.
|
|
3149
3196
|
* @example
|
|
3150
3197
|
* This example retrieves sorted Row Ids in a Table.
|
|
3151
3198
|
*
|
|
@@ -3237,6 +3284,42 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
3237
3284
|
limit?: number,
|
|
3238
3285
|
): Ids;
|
|
3239
3286
|
|
|
3287
|
+
/**
|
|
3288
|
+
* When called with one object argument, the getSortedRowIds method
|
|
3289
|
+
* destructures it to make it easier to skip optional parameters.
|
|
3290
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
3291
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit`
|
|
3292
|
+
* parameters.
|
|
3293
|
+
* @returns An array of the sorted Ids of appropriate Rows in the Table.
|
|
3294
|
+
* @example
|
|
3295
|
+
* This example retrieves the first sorted Row Id in a Table.
|
|
3296
|
+
*
|
|
3297
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
3298
|
+
*
|
|
3299
|
+
* ```ts override
|
|
3300
|
+
* getSortedRowIds(args: SortedRowIdsArgs): Ids;
|
|
3301
|
+
* ```
|
|
3302
|
+
*
|
|
3303
|
+
* ```js
|
|
3304
|
+
* import {createStore} from 'tinybase';
|
|
3305
|
+
*
|
|
3306
|
+
* const store = createStore().setTables({
|
|
3307
|
+
* pets: {
|
|
3308
|
+
* fido: {species: 'dog'},
|
|
3309
|
+
* felix: {species: 'cat'},
|
|
3310
|
+
* cujo: {species: 'wolf'},
|
|
3311
|
+
* },
|
|
3312
|
+
* });
|
|
3313
|
+
* console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
|
|
3314
|
+
* // -> ['cujo']
|
|
3315
|
+
* ```
|
|
3316
|
+
* @category Getter
|
|
3317
|
+
* @since v6.1.0
|
|
3318
|
+
*/
|
|
3319
|
+
getSortedRowIds<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
3320
|
+
args: SortedRowIdsArgs<Schemas[0], TableId>,
|
|
3321
|
+
): Ids;
|
|
3322
|
+
|
|
3240
3323
|
/**
|
|
3241
3324
|
* The getRow method returns an object containing the entire data of a single
|
|
3242
3325
|
* Row in a given Table.
|
|
@@ -7140,24 +7223,76 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
7140
7223
|
addSortedRowIdsListener<
|
|
7141
7224
|
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
7142
7225
|
CellIdOrUndefined extends CellIdFromSchema<Schemas[0], TableId> | undefined,
|
|
7143
|
-
Descending extends boolean,
|
|
7144
|
-
Offset extends number,
|
|
7145
|
-
Limit extends number | undefined,
|
|
7146
7226
|
>(
|
|
7147
7227
|
tableId: TableId,
|
|
7148
7228
|
cellId: CellIdOrUndefined,
|
|
7149
|
-
descending:
|
|
7150
|
-
offset:
|
|
7151
|
-
limit:
|
|
7152
|
-
listener: SortedRowIdsListener<
|
|
7153
|
-
|
|
7154
|
-
|
|
7155
|
-
|
|
7156
|
-
|
|
7157
|
-
|
|
7158
|
-
|
|
7159
|
-
|
|
7160
|
-
|
|
7229
|
+
descending: boolean,
|
|
7230
|
+
offset: number,
|
|
7231
|
+
limit: number | undefined,
|
|
7232
|
+
listener: SortedRowIdsListener<Schemas, TableId, CellIdOrUndefined, this>,
|
|
7233
|
+
mutator?: boolean,
|
|
7234
|
+
): Id;
|
|
7235
|
+
|
|
7236
|
+
/**
|
|
7237
|
+
* When called with an object as the first argument, the
|
|
7238
|
+
* addSortedRowIdsListener method destructures it to make it easier to skip
|
|
7239
|
+
* optional parameters.
|
|
7240
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
7241
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit`
|
|
7242
|
+
* parameters.
|
|
7243
|
+
* @param listener The function that will be called whenever the sorted Row
|
|
7244
|
+
* Ids in the Table change.
|
|
7245
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
7246
|
+
* Store data.
|
|
7247
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
7248
|
+
* explicitly, or to remove it.
|
|
7249
|
+
* @example
|
|
7250
|
+
* This example registers a listener that responds to any change to the first
|
|
7251
|
+
* of the sorted Row Ids of a specific Table.
|
|
7252
|
+
*
|
|
7253
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
7254
|
+
*
|
|
7255
|
+
* ```ts override
|
|
7256
|
+
* addSortedRowIdsListener(
|
|
7257
|
+
* args: SortedRowIdsArgs,
|
|
7258
|
+
* listener: SortedRowIdsListener<this>,
|
|
7259
|
+
* mutator?: boolean,
|
|
7260
|
+
* ): Id;
|
|
7261
|
+
* ```
|
|
7262
|
+
*
|
|
7263
|
+
* ```js
|
|
7264
|
+
* import {createStore} from 'tinybase';
|
|
7265
|
+
*
|
|
7266
|
+
* const store = createStore().setTables({
|
|
7267
|
+
* pets: {fido: {price: 6}, felix: {price: 5}},
|
|
7268
|
+
* });
|
|
7269
|
+
*
|
|
7270
|
+
* const listenerId = store.addSortedRowIdsListener(
|
|
7271
|
+
* {tableId: 'pets', limit: 1},
|
|
7272
|
+
* (store, tableId, cellId, descending, offset, limit, sortedRowIds) => {
|
|
7273
|
+
* console.log(`First sorted Row Id for ${tableId} table changed`);
|
|
7274
|
+
* console.log(sortedRowIds);
|
|
7275
|
+
* // ^ cheaper than calling getSortedRowIds again
|
|
7276
|
+
* },
|
|
7277
|
+
* );
|
|
7278
|
+
* console.log(store.getSortedRowIds({tableId: 'pets', limit: 1}));
|
|
7279
|
+
* // -> ['felix']
|
|
7280
|
+
*
|
|
7281
|
+
* store.setRow('pets', 'carnaby', {price: 4.5});
|
|
7282
|
+
* // -> 'First sorted Row Id for pets table changed'
|
|
7283
|
+
* // -> ['carnaby']
|
|
7284
|
+
*
|
|
7285
|
+
* store.delListener(listenerId);
|
|
7286
|
+
* ```
|
|
7287
|
+
* @category Listener
|
|
7288
|
+
* @since v6.1.0
|
|
7289
|
+
*/
|
|
7290
|
+
addSortedRowIdsListener<
|
|
7291
|
+
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
7292
|
+
CellIdOrUndefined extends CellIdFromSchema<Schemas[0], TableId> | undefined,
|
|
7293
|
+
>(
|
|
7294
|
+
args: SortedRowIdsArgs<Schemas[0], TableId, CellIdOrUndefined>,
|
|
7295
|
+
listener: SortedRowIdsListener<Schemas, TableId, CellIdOrUndefined, this>,
|
|
7161
7296
|
mutator?: boolean,
|
|
7162
7297
|
): Id;
|
|
7163
7298
|
|
|
@@ -86,6 +86,7 @@ import type {
|
|
|
86
86
|
RowCountListener,
|
|
87
87
|
RowIdsListener,
|
|
88
88
|
RowListener,
|
|
89
|
+
SortedRowIdsArgs,
|
|
89
90
|
SortedRowIdsListener,
|
|
90
91
|
Store,
|
|
91
92
|
Table,
|
|
@@ -1659,6 +1660,57 @@ export function useSortedRowIds(
|
|
|
1659
1660
|
storeOrStoreId?: StoreOrStoreId,
|
|
1660
1661
|
): Ids;
|
|
1661
1662
|
|
|
1663
|
+
/**
|
|
1664
|
+
* When called with an object as the first argument, the useSortedRowIds method
|
|
1665
|
+
* destructures it to make it easier to skip optional parameters.
|
|
1666
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
1667
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit` parameters.
|
|
1668
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
1669
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1670
|
+
* reference.
|
|
1671
|
+
* @returns An array of the sorted Ids of every Row in the Table.
|
|
1672
|
+
* @example
|
|
1673
|
+
* This example creates a Store outside the application, which is used in the
|
|
1674
|
+
* useSortedRowIds hook by reference. A change to the data in the Store
|
|
1675
|
+
* re-renders the component.
|
|
1676
|
+
*
|
|
1677
|
+
* ```jsx
|
|
1678
|
+
* import React from 'react';
|
|
1679
|
+
* import {createRoot} from 'react-dom/client';
|
|
1680
|
+
* import {createStore} from 'tinybase';
|
|
1681
|
+
* import {useSortedRowIds} from 'tinybase/ui-react';
|
|
1682
|
+
*
|
|
1683
|
+
* const store = createStore().setTables({
|
|
1684
|
+
* pets: {
|
|
1685
|
+
* fido: {species: 'dog'},
|
|
1686
|
+
* felix: {species: 'cat'},
|
|
1687
|
+
* },
|
|
1688
|
+
* });
|
|
1689
|
+
* const App = () => (
|
|
1690
|
+
* <span>
|
|
1691
|
+
* {JSON.stringify(
|
|
1692
|
+
* useSortedRowIds({tableId: 'pets', cellId: 'species'}, store),
|
|
1693
|
+
* )}
|
|
1694
|
+
* </span>
|
|
1695
|
+
* );
|
|
1696
|
+
*
|
|
1697
|
+
* const app = document.createElement('div');
|
|
1698
|
+
* createRoot(app).render(<App />); // !act
|
|
1699
|
+
* console.log(app.innerHTML);
|
|
1700
|
+
* // -> '<span>["felix","fido"]</span>'
|
|
1701
|
+
*
|
|
1702
|
+
* store.setRow('pets', 'cujo', {species: 'wolf'}); // !act
|
|
1703
|
+
* console.log(app.innerHTML);
|
|
1704
|
+
* // -> '<span>["felix","fido","cujo"]</span>'
|
|
1705
|
+
* ```
|
|
1706
|
+
* @category Store hooks
|
|
1707
|
+
* @since v6.1.0
|
|
1708
|
+
*/
|
|
1709
|
+
export function useSortedRowIds(
|
|
1710
|
+
args: SortedRowIdsArgs,
|
|
1711
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
1712
|
+
): Ids;
|
|
1713
|
+
|
|
1662
1714
|
/**
|
|
1663
1715
|
* The useHasRow hook returns a boolean indicating whether a given Row exists in
|
|
1664
1716
|
* the Store, and registers a listener so that any changes to that result will
|
|
@@ -4737,6 +4789,74 @@ export function useSortedRowIdsListener(
|
|
|
4737
4789
|
storeOrStoreId?: StoreOrStoreId,
|
|
4738
4790
|
): void;
|
|
4739
4791
|
|
|
4792
|
+
/**
|
|
4793
|
+
* When called with an object as the first argument, the useSortedRowIds method
|
|
4794
|
+
* destructures it to make it easier to skip optional parameters.
|
|
4795
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
4796
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit` parameters.
|
|
4797
|
+
* @param listener The function that will be called whenever the sorted Row Ids
|
|
4798
|
+
* in the Table change.
|
|
4799
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
4800
|
+
* function, which, if any change, result in the re-registration of the
|
|
4801
|
+
* listener. This parameter defaults to an empty array.
|
|
4802
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4803
|
+
* Store data.
|
|
4804
|
+
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
4805
|
+
* default context Store, provide an Id for a named context Store, or provide an
|
|
4806
|
+
* explicit reference.
|
|
4807
|
+
* @example
|
|
4808
|
+
* This example uses the useSortedRowIdsListener hook to create a listener that
|
|
4809
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
4810
|
+
* listener is removed from the Store.
|
|
4811
|
+
*
|
|
4812
|
+
* ```jsx
|
|
4813
|
+
* import React from 'react';
|
|
4814
|
+
* import {createRoot} from 'react-dom/client';
|
|
4815
|
+
* import {createStore} from 'tinybase';
|
|
4816
|
+
* import {Provider, useSortedRowIdsListener} from 'tinybase/ui-react';
|
|
4817
|
+
*
|
|
4818
|
+
* const App = ({store}) => (
|
|
4819
|
+
* <Provider store={store}>
|
|
4820
|
+
* <Pane />
|
|
4821
|
+
* </Provider>
|
|
4822
|
+
* );
|
|
4823
|
+
* const Pane = () => {
|
|
4824
|
+
* useSortedRowIdsListener({tableId: 'pets', cellId: 'species'}, () =>
|
|
4825
|
+
* console.log('Sorted Row Ids changed'),
|
|
4826
|
+
* );
|
|
4827
|
+
* return <span>App</span>;
|
|
4828
|
+
* };
|
|
4829
|
+
*
|
|
4830
|
+
* const store = createStore().setTables({
|
|
4831
|
+
* pets: {
|
|
4832
|
+
* fido: {species: 'dog'},
|
|
4833
|
+
* felix: {species: 'cat'},
|
|
4834
|
+
* },
|
|
4835
|
+
* });
|
|
4836
|
+
* const app = document.createElement('div');
|
|
4837
|
+
* const root = createRoot(app);
|
|
4838
|
+
* root.render(<App store={store} />); // !act
|
|
4839
|
+
* console.log(store.getListenerStats().sortedRowIds);
|
|
4840
|
+
* // -> 1
|
|
4841
|
+
*
|
|
4842
|
+
* store.setRow('pets', 'cujo', {species: 'wolf'}); // !act
|
|
4843
|
+
* // -> 'Sorted Row Ids changed'
|
|
4844
|
+
*
|
|
4845
|
+
* root.unmount(); // !act
|
|
4846
|
+
* console.log(store.getListenerStats().sortedRowIds);
|
|
4847
|
+
* // -> 0
|
|
4848
|
+
* ```
|
|
4849
|
+
* @category Store hooks
|
|
4850
|
+
* @since v6.1.0
|
|
4851
|
+
*/
|
|
4852
|
+
export function useSortedRowIdsListener(
|
|
4853
|
+
args: SortedRowIdsArgs,
|
|
4854
|
+
listener: SortedRowIdsListener,
|
|
4855
|
+
listenerDeps?: React.DependencyList,
|
|
4856
|
+
mutator?: boolean,
|
|
4857
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
4858
|
+
): void;
|
|
4859
|
+
|
|
4740
4860
|
/**
|
|
4741
4861
|
* The useHasRowListener hook registers a listener function with the Store that
|
|
4742
4862
|
* will be called when a Row is added to or removed from the Store.
|