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
|
@@ -137,6 +137,7 @@ import type {
|
|
|
137
137
|
RowCountListener,
|
|
138
138
|
RowIdsListener,
|
|
139
139
|
RowListener,
|
|
140
|
+
SortedRowIdsArgs,
|
|
140
141
|
SortedRowIdsListener,
|
|
141
142
|
Store,
|
|
142
143
|
Table,
|
|
@@ -1723,7 +1724,8 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
1723
1724
|
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
1724
1725
|
) => Ids;
|
|
1725
1726
|
|
|
1726
|
-
|
|
1727
|
+
useSortedRowIds: {
|
|
1728
|
+
/**
|
|
1727
1729
|
* The useSortedRowIds hook returns the sorted (and optionally, paginated) Ids
|
|
1728
1730
|
* of every Row in a given Table, and registers a listener so that any changes
|
|
1729
1731
|
* to that result will cause a re-render.
|
|
@@ -1859,17 +1861,78 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
1859
1861
|
* @category Store hooks
|
|
1860
1862
|
* @since v2.0.0
|
|
1861
1863
|
*/
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1864
|
+
<
|
|
1865
|
+
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
1866
|
+
CellId extends CellIdFromSchema<Schemas[0], TableId>,
|
|
1867
|
+
>(
|
|
1868
|
+
tableId: TableId,
|
|
1869
|
+
cellId?: CellId,
|
|
1870
|
+
descending?: boolean,
|
|
1871
|
+
offset?: number,
|
|
1872
|
+
limit?: number,
|
|
1873
|
+
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
1874
|
+
): Ids;
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
* When called with an object as the first argument, the useSortedRowIds method
|
|
1878
|
+
* destructures it to make it easier to skip optional parameters.
|
|
1879
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
1880
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit` parameters.
|
|
1881
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
1882
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1883
|
+
* reference.
|
|
1884
|
+
* @returns An array of the sorted Ids of every Row in the Table.
|
|
1885
|
+
* @example
|
|
1886
|
+
* This example creates a Store outside the application, which is used in the
|
|
1887
|
+
* useSortedRowIds hook by reference. A change to the data in the Store
|
|
1888
|
+
* re-renders the component.
|
|
1889
|
+
*
|
|
1890
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
1891
|
+
*
|
|
1892
|
+
* ```ts override
|
|
1893
|
+
* useSortedRowIds(
|
|
1894
|
+
* args: SortedRowIdsArgs,
|
|
1895
|
+
* storeOrStoreId?: StoreOrStoreId,
|
|
1896
|
+
* ): Ids;
|
|
1897
|
+
* ```
|
|
1898
|
+
*
|
|
1899
|
+
* ```jsx
|
|
1900
|
+
* import React from 'react';
|
|
1901
|
+
* import {createRoot} from 'react-dom/client';
|
|
1902
|
+
* import {createStore} from 'tinybase';
|
|
1903
|
+
* import {useSortedRowIds} from 'tinybase/ui-react';
|
|
1904
|
+
*
|
|
1905
|
+
* const store = createStore().setTables({
|
|
1906
|
+
* pets: {
|
|
1907
|
+
* fido: {species: 'dog'},
|
|
1908
|
+
* felix: {species: 'cat'},
|
|
1909
|
+
* },
|
|
1910
|
+
* });
|
|
1911
|
+
* const App = () => (
|
|
1912
|
+
* <span>
|
|
1913
|
+
* {JSON.stringify(
|
|
1914
|
+
* useSortedRowIds({tableId: 'pets', cellId: 'species'}, store),
|
|
1915
|
+
* )}
|
|
1916
|
+
* </span>
|
|
1917
|
+
* );
|
|
1918
|
+
*
|
|
1919
|
+
* const app = document.createElement('div');
|
|
1920
|
+
* createRoot(app).render(<App />); // !act
|
|
1921
|
+
* console.log(app.innerHTML);
|
|
1922
|
+
* // -> '<span>["felix","fido"]</span>'
|
|
1923
|
+
*
|
|
1924
|
+
* store.setRow('pets', 'cujo', {species: 'wolf'}); // !act
|
|
1925
|
+
* console.log(app.innerHTML);
|
|
1926
|
+
* // -> '<span>["felix","fido","cujo"]</span>'
|
|
1927
|
+
* ```
|
|
1928
|
+
* @category Store hooks
|
|
1929
|
+
* @since v6.1.0
|
|
1930
|
+
*/
|
|
1931
|
+
<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
1932
|
+
args: SortedRowIdsArgs<Schemas[0], TableId>,
|
|
1933
|
+
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
1934
|
+
): Ids;
|
|
1935
|
+
};
|
|
1873
1936
|
|
|
1874
1937
|
/**
|
|
1875
1938
|
* The useHasRow hook returns a boolean indicating whether a given Row exists in
|
|
@@ -5329,7 +5392,8 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
5329
5392
|
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
5330
5393
|
) => void;
|
|
5331
5394
|
|
|
5332
|
-
|
|
5395
|
+
useSortedRowIdsListener: {
|
|
5396
|
+
/**
|
|
5333
5397
|
* The useSortedRowIdsListener hook registers a listener function with a Store
|
|
5334
5398
|
* that will be called whenever sorted (and optionally, paginated) Row Ids in a
|
|
5335
5399
|
* Table change.
|
|
@@ -5420,30 +5484,108 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
5420
5484
|
* @category Store hooks
|
|
5421
5485
|
* @since v2.0.0
|
|
5422
5486
|
*/
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5433
|
-
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5445
|
-
|
|
5446
|
-
|
|
5487
|
+
<
|
|
5488
|
+
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
5489
|
+
CellIdOrUndefined extends
|
|
5490
|
+
| CellIdFromSchema<Schemas[0], TableId>
|
|
5491
|
+
| undefined,
|
|
5492
|
+
>(
|
|
5493
|
+
tableId: TableId,
|
|
5494
|
+
cellId: CellIdOrUndefined,
|
|
5495
|
+
descending: boolean,
|
|
5496
|
+
offset: number,
|
|
5497
|
+
limit: number | undefined,
|
|
5498
|
+
listener: SortedRowIdsListener<Schemas, TableId, CellIdOrUndefined>,
|
|
5499
|
+
listenerDeps?: React.DependencyList,
|
|
5500
|
+
mutator?: boolean,
|
|
5501
|
+
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
5502
|
+
): void;
|
|
5503
|
+
|
|
5504
|
+
/**
|
|
5505
|
+
* When called with an object as the first argument, the useSortedRowIds method
|
|
5506
|
+
* destructures it to make it easier to skip optional parameters.
|
|
5507
|
+
* @param args A SortedRowIdsArgs object containing the Id of the Table in the
|
|
5508
|
+
* Store, and optional `cellId`, `descending`, `offset`, and `limit` parameters.
|
|
5509
|
+
* @param listener The function that will be called whenever the sorted Row Ids
|
|
5510
|
+
* in the Table change.
|
|
5511
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
5512
|
+
* function, which, if any change, result in the re-registration of the
|
|
5513
|
+
* listener. This parameter defaults to an empty array.
|
|
5514
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
5515
|
+
* Store data.
|
|
5516
|
+
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
5517
|
+
* default context Store, provide an Id for a named context Store, or provide an
|
|
5518
|
+
* explicit reference.
|
|
5519
|
+
* @example
|
|
5520
|
+
* This example uses the useSortedRowIdsListener hook to create a listener that
|
|
5521
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
5522
|
+
* listener is removed from the Store.
|
|
5523
|
+
*
|
|
5524
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
5525
|
+
*
|
|
5526
|
+
* ```ts override
|
|
5527
|
+
* useSortedRowIdsListener(
|
|
5528
|
+
* args: SortedRowIdsArgs,
|
|
5529
|
+
* listener: SortedRowIdsListener,
|
|
5530
|
+
* listenerDeps?: React.DependencyList,
|
|
5531
|
+
* mutator?: boolean,
|
|
5532
|
+
* storeOrStoreId?: StoreOrStoreId,
|
|
5533
|
+
* ): void;
|
|
5534
|
+
* ```
|
|
5535
|
+
*
|
|
5536
|
+
* ```jsx
|
|
5537
|
+
* import React from 'react';
|
|
5538
|
+
* import {createRoot} from 'react-dom/client';
|
|
5539
|
+
* import {createStore} from 'tinybase';
|
|
5540
|
+
* import {Provider, useSortedRowIdsListener} from 'tinybase/ui-react';
|
|
5541
|
+
*
|
|
5542
|
+
* const App = ({store}) => (
|
|
5543
|
+
* <Provider store={store}>
|
|
5544
|
+
* <Pane />
|
|
5545
|
+
* </Provider>
|
|
5546
|
+
* );
|
|
5547
|
+
* const Pane = () => {
|
|
5548
|
+
* useSortedRowIdsListener({tableId: 'pets', cellId: 'species'}, () =>
|
|
5549
|
+
* console.log('Sorted Row Ids changed'),
|
|
5550
|
+
* );
|
|
5551
|
+
* return <span>App</span>;
|
|
5552
|
+
* };
|
|
5553
|
+
*
|
|
5554
|
+
* const store = createStore().setTables({
|
|
5555
|
+
* pets: {
|
|
5556
|
+
* fido: {species: 'dog'},
|
|
5557
|
+
* felix: {species: 'cat'},
|
|
5558
|
+
* },
|
|
5559
|
+
* });
|
|
5560
|
+
* const app = document.createElement('div');
|
|
5561
|
+
* const root = createRoot(app);
|
|
5562
|
+
* root.render(<App store={store} />); // !act
|
|
5563
|
+
* console.log(store.getListenerStats().sortedRowIds);
|
|
5564
|
+
* // -> 1
|
|
5565
|
+
*
|
|
5566
|
+
* store.setRow('pets', 'cujo', {species: 'wolf'}); // !act
|
|
5567
|
+
* // -> 'Sorted Row Ids changed'
|
|
5568
|
+
*
|
|
5569
|
+
* root.unmount(); // !act
|
|
5570
|
+
* console.log(store.getListenerStats().sortedRowIds);
|
|
5571
|
+
* // -> 0
|
|
5572
|
+
* ```
|
|
5573
|
+
* @category Store hooks
|
|
5574
|
+
* @since v6.1.0
|
|
5575
|
+
*/
|
|
5576
|
+
<
|
|
5577
|
+
TableId extends TableIdFromSchema<Schemas[0]>,
|
|
5578
|
+
CellIdOrUndefined extends
|
|
5579
|
+
| CellIdFromSchema<Schemas[0], TableId>
|
|
5580
|
+
| undefined,
|
|
5581
|
+
>(
|
|
5582
|
+
args: SortedRowIdsArgs<Schemas[0], TableId>,
|
|
5583
|
+
listener: SortedRowIdsListener<Schemas, TableId, CellIdOrUndefined>,
|
|
5584
|
+
listenerDeps?: React.DependencyList,
|
|
5585
|
+
mutator?: boolean,
|
|
5586
|
+
storeOrStoreId?: StoreOrStoreId<Schemas>,
|
|
5587
|
+
): void;
|
|
5588
|
+
};
|
|
5447
5589
|
|
|
5448
5590
|
/**
|
|
5449
5591
|
* The useHasRowListener hook registers a listener function with the Store that
|
package/index.js
CHANGED
|
@@ -1792,6 +1792,27 @@ const createStore = () => {
|
|
|
1792
1792
|
transaction(() => actions(...arrayMap(args, id)));
|
|
1793
1793
|
return store;
|
|
1794
1794
|
};
|
|
1795
|
+
const addSortedRowIdsListenerImpl = (
|
|
1796
|
+
tableId,
|
|
1797
|
+
cellId,
|
|
1798
|
+
otherArgs,
|
|
1799
|
+
listener,
|
|
1800
|
+
mutator,
|
|
1801
|
+
) => {
|
|
1802
|
+
let sortedRowIds = getSortedRowIds(tableId, cellId, ...otherArgs);
|
|
1803
|
+
return addListener(
|
|
1804
|
+
() => {
|
|
1805
|
+
const newSortedRowIds = getSortedRowIds(tableId, cellId, ...otherArgs);
|
|
1806
|
+
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
|
1807
|
+
sortedRowIds = newSortedRowIds;
|
|
1808
|
+
listener(store, tableId, cellId, ...otherArgs, sortedRowIds);
|
|
1809
|
+
}
|
|
1810
|
+
},
|
|
1811
|
+
sortedRowIdsListeners[mutator ? 1 : 0],
|
|
1812
|
+
[tableId, cellId],
|
|
1813
|
+
[getTableIds],
|
|
1814
|
+
);
|
|
1815
|
+
};
|
|
1795
1816
|
const getContent = () => [getTables(), getValues()];
|
|
1796
1817
|
const getTables = () => mapToObj3(tablesMap);
|
|
1797
1818
|
const getTableIds = () => mapKeys(tablesMap);
|
|
@@ -1800,22 +1821,36 @@ const createStore = () => {
|
|
|
1800
1821
|
mapKeys(mapGet(tableCellIds, id(tableId)));
|
|
1801
1822
|
const getRowCount = (tableId) => collSize(mapGet(tablesMap, id(tableId)));
|
|
1802
1823
|
const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
|
|
1803
|
-
const getSortedRowIds = (
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1824
|
+
const getSortedRowIds = (
|
|
1825
|
+
tableIdOrArgs,
|
|
1826
|
+
cellId,
|
|
1827
|
+
descending,
|
|
1828
|
+
offset = 0,
|
|
1829
|
+
limit,
|
|
1830
|
+
) =>
|
|
1831
|
+
isObject(tableIdOrArgs)
|
|
1832
|
+
? getSortedRowIds(
|
|
1833
|
+
tableIdOrArgs.tableId,
|
|
1834
|
+
tableIdOrArgs.cellId,
|
|
1835
|
+
tableIdOrArgs.descending,
|
|
1836
|
+
tableIdOrArgs.offset,
|
|
1837
|
+
tableIdOrArgs.limit,
|
|
1838
|
+
)
|
|
1839
|
+
: arrayMap(
|
|
1840
|
+
slice(
|
|
1841
|
+
arraySort(
|
|
1842
|
+
mapMap(mapGet(tablesMap, id(tableIdOrArgs)), (row, rowId) => [
|
|
1843
|
+
isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
|
|
1844
|
+
rowId,
|
|
1845
|
+
]),
|
|
1846
|
+
([cell1], [cell2]) =>
|
|
1847
|
+
defaultSorter(cell1, cell2) * (descending ? -1 : 1),
|
|
1848
|
+
),
|
|
1849
|
+
offset,
|
|
1850
|
+
isUndefined(limit) ? limit : offset + limit,
|
|
1851
|
+
),
|
|
1852
|
+
([, rowId]) => rowId,
|
|
1853
|
+
);
|
|
1819
1854
|
const getRow = (tableId, rowId) =>
|
|
1820
1855
|
mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
|
1821
1856
|
const getCellIds = (tableId, rowId) =>
|
|
@@ -2207,48 +2242,33 @@ const createStore = () => {
|
|
|
2207
2242
|
mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
|
|
2208
2243
|
const forEachValue = (valueCallback) => mapForEach(valuesMap, valueCallback);
|
|
2209
2244
|
const addSortedRowIdsListener = (
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2245
|
+
tableIdOrArgs,
|
|
2246
|
+
cellIdOrListener,
|
|
2247
|
+
descendingOrMutator,
|
|
2213
2248
|
offset,
|
|
2214
2249
|
limit,
|
|
2215
2250
|
listener,
|
|
2216
2251
|
mutator,
|
|
2217
|
-
) =>
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2252
|
+
) =>
|
|
2253
|
+
isObject(tableIdOrArgs)
|
|
2254
|
+
? addSortedRowIdsListenerImpl(
|
|
2255
|
+
tableIdOrArgs.tableId,
|
|
2256
|
+
tableIdOrArgs.cellId,
|
|
2257
|
+
[
|
|
2258
|
+
tableIdOrArgs.descending ?? false,
|
|
2259
|
+
tableIdOrArgs.offset ?? 0,
|
|
2260
|
+
tableIdOrArgs.limit,
|
|
2261
|
+
],
|
|
2262
|
+
cellIdOrListener,
|
|
2263
|
+
descendingOrMutator,
|
|
2264
|
+
)
|
|
2265
|
+
: addSortedRowIdsListenerImpl(
|
|
2266
|
+
tableIdOrArgs,
|
|
2267
|
+
cellIdOrListener,
|
|
2268
|
+
[descendingOrMutator, offset, limit],
|
|
2269
|
+
listener,
|
|
2270
|
+
mutator,
|
|
2233
2271
|
);
|
|
2234
|
-
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
|
2235
|
-
sortedRowIds = newSortedRowIds;
|
|
2236
|
-
listener(
|
|
2237
|
-
store,
|
|
2238
|
-
tableId,
|
|
2239
|
-
cellId,
|
|
2240
|
-
descending,
|
|
2241
|
-
offset,
|
|
2242
|
-
limit,
|
|
2243
|
-
sortedRowIds,
|
|
2244
|
-
);
|
|
2245
|
-
}
|
|
2246
|
-
},
|
|
2247
|
-
sortedRowIdsListeners[mutator ? 1 : 0],
|
|
2248
|
-
[tableId, cellId],
|
|
2249
|
-
[getTableIds],
|
|
2250
|
-
);
|
|
2251
|
-
};
|
|
2252
2272
|
const addStartTransactionListener = (listener) =>
|
|
2253
2273
|
addListener(listener, startTransactionListeners);
|
|
2254
2274
|
const addWillFinishTransactionListener = (listener) =>
|
package/mergeable-store/index.js
CHANGED
|
@@ -1140,6 +1140,27 @@ const createStore = () => {
|
|
|
1140
1140
|
transaction(() => actions(...arrayMap(args, id)));
|
|
1141
1141
|
return store;
|
|
1142
1142
|
};
|
|
1143
|
+
const addSortedRowIdsListenerImpl = (
|
|
1144
|
+
tableId,
|
|
1145
|
+
cellId,
|
|
1146
|
+
otherArgs,
|
|
1147
|
+
listener,
|
|
1148
|
+
mutator,
|
|
1149
|
+
) => {
|
|
1150
|
+
let sortedRowIds = getSortedRowIds(tableId, cellId, ...otherArgs);
|
|
1151
|
+
return addListener(
|
|
1152
|
+
() => {
|
|
1153
|
+
const newSortedRowIds = getSortedRowIds(tableId, cellId, ...otherArgs);
|
|
1154
|
+
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
|
1155
|
+
sortedRowIds = newSortedRowIds;
|
|
1156
|
+
listener(store, tableId, cellId, ...otherArgs, sortedRowIds);
|
|
1157
|
+
}
|
|
1158
|
+
},
|
|
1159
|
+
sortedRowIdsListeners[mutator ? 1 : 0],
|
|
1160
|
+
[tableId, cellId],
|
|
1161
|
+
[getTableIds],
|
|
1162
|
+
);
|
|
1163
|
+
};
|
|
1143
1164
|
const getContent = () => [getTables(), getValues()];
|
|
1144
1165
|
const getTables = () => mapToObj3(tablesMap);
|
|
1145
1166
|
const getTableIds = () => mapKeys(tablesMap);
|
|
@@ -1148,22 +1169,36 @@ const createStore = () => {
|
|
|
1148
1169
|
mapKeys(mapGet(tableCellIds, id(tableId)));
|
|
1149
1170
|
const getRowCount = (tableId) => collSize(mapGet(tablesMap, id(tableId)));
|
|
1150
1171
|
const getRowIds = (tableId) => mapKeys(mapGet(tablesMap, id(tableId)));
|
|
1151
|
-
const getSortedRowIds = (
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1172
|
+
const getSortedRowIds = (
|
|
1173
|
+
tableIdOrArgs,
|
|
1174
|
+
cellId,
|
|
1175
|
+
descending,
|
|
1176
|
+
offset = 0,
|
|
1177
|
+
limit,
|
|
1178
|
+
) =>
|
|
1179
|
+
isObject(tableIdOrArgs)
|
|
1180
|
+
? getSortedRowIds(
|
|
1181
|
+
tableIdOrArgs.tableId,
|
|
1182
|
+
tableIdOrArgs.cellId,
|
|
1183
|
+
tableIdOrArgs.descending,
|
|
1184
|
+
tableIdOrArgs.offset,
|
|
1185
|
+
tableIdOrArgs.limit,
|
|
1186
|
+
)
|
|
1187
|
+
: arrayMap(
|
|
1188
|
+
slice(
|
|
1189
|
+
arraySort(
|
|
1190
|
+
mapMap(mapGet(tablesMap, id(tableIdOrArgs)), (row, rowId) => [
|
|
1191
|
+
isUndefined(cellId) ? rowId : mapGet(row, id(cellId)),
|
|
1192
|
+
rowId,
|
|
1193
|
+
]),
|
|
1194
|
+
([cell1], [cell2]) =>
|
|
1195
|
+
defaultSorter(cell1, cell2) * (descending ? -1 : 1),
|
|
1196
|
+
),
|
|
1197
|
+
offset,
|
|
1198
|
+
isUndefined(limit) ? limit : offset + limit,
|
|
1199
|
+
),
|
|
1200
|
+
([, rowId]) => rowId,
|
|
1201
|
+
);
|
|
1167
1202
|
const getRow = (tableId, rowId) =>
|
|
1168
1203
|
mapToObj(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)));
|
|
1169
1204
|
const getCellIds = (tableId, rowId) =>
|
|
@@ -1555,48 +1590,33 @@ const createStore = () => {
|
|
|
1555
1590
|
mapForEach(mapGet(mapGet(tablesMap, id(tableId)), id(rowId)), cellCallback);
|
|
1556
1591
|
const forEachValue = (valueCallback) => mapForEach(valuesMap, valueCallback);
|
|
1557
1592
|
const addSortedRowIdsListener = (
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1593
|
+
tableIdOrArgs,
|
|
1594
|
+
cellIdOrListener,
|
|
1595
|
+
descendingOrMutator,
|
|
1561
1596
|
offset,
|
|
1562
1597
|
limit,
|
|
1563
1598
|
listener,
|
|
1564
1599
|
mutator,
|
|
1565
|
-
) =>
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1600
|
+
) =>
|
|
1601
|
+
isObject(tableIdOrArgs)
|
|
1602
|
+
? addSortedRowIdsListenerImpl(
|
|
1603
|
+
tableIdOrArgs.tableId,
|
|
1604
|
+
tableIdOrArgs.cellId,
|
|
1605
|
+
[
|
|
1606
|
+
tableIdOrArgs.descending ?? false,
|
|
1607
|
+
tableIdOrArgs.offset ?? 0,
|
|
1608
|
+
tableIdOrArgs.limit,
|
|
1609
|
+
],
|
|
1610
|
+
cellIdOrListener,
|
|
1611
|
+
descendingOrMutator,
|
|
1612
|
+
)
|
|
1613
|
+
: addSortedRowIdsListenerImpl(
|
|
1614
|
+
tableIdOrArgs,
|
|
1615
|
+
cellIdOrListener,
|
|
1616
|
+
[descendingOrMutator, offset, limit],
|
|
1617
|
+
listener,
|
|
1618
|
+
mutator,
|
|
1581
1619
|
);
|
|
1582
|
-
if (!arrayIsEqual(newSortedRowIds, sortedRowIds)) {
|
|
1583
|
-
sortedRowIds = newSortedRowIds;
|
|
1584
|
-
listener(
|
|
1585
|
-
store,
|
|
1586
|
-
tableId,
|
|
1587
|
-
cellId,
|
|
1588
|
-
descending,
|
|
1589
|
-
offset,
|
|
1590
|
-
limit,
|
|
1591
|
-
sortedRowIds,
|
|
1592
|
-
);
|
|
1593
|
-
}
|
|
1594
|
-
},
|
|
1595
|
-
sortedRowIdsListeners[mutator ? 1 : 0],
|
|
1596
|
-
[tableId, cellId],
|
|
1597
|
-
[getTableIds],
|
|
1598
|
-
);
|
|
1599
|
-
};
|
|
1600
1620
|
const addStartTransactionListener = (listener) =>
|
|
1601
1621
|
addListener(listener, startTransactionListeners);
|
|
1602
1622
|
const addWillFinishTransactionListener = (listener) =>
|