tinybase 6.1.0-beta.5 → 6.1.1
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 +575 -7
- package/@types/ui-react/with-schemas/index.d.ts +184 -40
- 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 +17 -17
- package/releases.md +60 -36
- 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
|
@@ -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.
|
|
@@ -6616,7 +6736,81 @@ export function useIndexesOrIndexesById(
|
|
|
6616
6736
|
indexesOrIndexesId?: IndexesOrIndexesId,
|
|
6617
6737
|
): Indexes | undefined;
|
|
6618
6738
|
|
|
6619
|
-
|
|
6739
|
+
/**
|
|
6740
|
+
* The useProvideIndexes hook is used to add an Indexes object by Id to a
|
|
6741
|
+
* Provider component, but imperatively from a component within it.
|
|
6742
|
+
*
|
|
6743
|
+
* Normally you will register an Indexes object by Id in a context by using the
|
|
6744
|
+
* `indexesById` prop of the top-level Provider component. This hook, however,
|
|
6745
|
+
* lets you dynamically add a new Indexes object to the context, from within a
|
|
6746
|
+
* descendent component. This is useful for applications where the set of
|
|
6747
|
+
* Indexes objects is not known at the time of the first render of the root
|
|
6748
|
+
* Provider.
|
|
6749
|
+
*
|
|
6750
|
+
* A Indexes object added to the Provider context in this way will be available
|
|
6751
|
+
* to other components within the context (using the useIndexes hook and so on).
|
|
6752
|
+
* If you use the same Id as an existing Indexes object registration, the new
|
|
6753
|
+
* one will take priority over one provided by the `indexesById` prop.
|
|
6754
|
+
*
|
|
6755
|
+
* Note that other components that consume an Indexes object registered like
|
|
6756
|
+
* this should defend against it being undefined at first. On the first render,
|
|
6757
|
+
* the other component will likely not yet have completed the registration. In
|
|
6758
|
+
* the example below, we use the null-safe `useIndexes('petIndexes')?` to do
|
|
6759
|
+
* this.
|
|
6760
|
+
* @param indexesId The Id of the Indexes object to be registered with the
|
|
6761
|
+
* Provider.
|
|
6762
|
+
* @param indexes The Indexes object to be registered.
|
|
6763
|
+
* @example
|
|
6764
|
+
* This example creates a Provider context. A child component registers an
|
|
6765
|
+
* Indexes object into it which is then consumable by a peer child component.
|
|
6766
|
+
*
|
|
6767
|
+
* ```jsx
|
|
6768
|
+
* import React from 'react';
|
|
6769
|
+
* import {createRoot} from 'react-dom/client';
|
|
6770
|
+
* import {createIndexes, createStore} from 'tinybase';
|
|
6771
|
+
* import {
|
|
6772
|
+
* Provider,
|
|
6773
|
+
* useCreateIndexes,
|
|
6774
|
+
* useCreateStore,
|
|
6775
|
+
* useIndexes,
|
|
6776
|
+
* useProvideIndexes,
|
|
6777
|
+
* } from 'tinybase/ui-react';
|
|
6778
|
+
*
|
|
6779
|
+
* const App = () => (
|
|
6780
|
+
* <Provider>
|
|
6781
|
+
* <RegisterIndexes />
|
|
6782
|
+
* <ConsumeIndexes />
|
|
6783
|
+
* </Provider>
|
|
6784
|
+
* );
|
|
6785
|
+
* const RegisterIndexes = () => {
|
|
6786
|
+
* const store = useCreateStore(() =>
|
|
6787
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
6788
|
+
* );
|
|
6789
|
+
* const indexes = useCreateIndexes(store, (store) =>
|
|
6790
|
+
* createIndexes(store).setIndexDefinition(
|
|
6791
|
+
* 'petsByColor',
|
|
6792
|
+
* 'pets',
|
|
6793
|
+
* 'color',
|
|
6794
|
+
* ),
|
|
6795
|
+
* );
|
|
6796
|
+
* useProvideIndexes('petIndexes', indexes);
|
|
6797
|
+
* return null;
|
|
6798
|
+
* };
|
|
6799
|
+
* const ConsumeIndexes = () => (
|
|
6800
|
+
* <span>
|
|
6801
|
+
* {JSON.stringify(useIndexes('petIndexes')?.getSliceIds('petsByColor'))}
|
|
6802
|
+
* </span>
|
|
6803
|
+
* );
|
|
6804
|
+
*
|
|
6805
|
+
* const app = document.createElement('div');
|
|
6806
|
+
* const root = createRoot(app);
|
|
6807
|
+
* root.render(<App />); // !act
|
|
6808
|
+
* console.log(app.innerHTML);
|
|
6809
|
+
* // -> '<span>["brown"]</span>'
|
|
6810
|
+
* ```
|
|
6811
|
+
* @category Indexes hooks
|
|
6812
|
+
* @since v5.3.0
|
|
6813
|
+
*/
|
|
6620
6814
|
export function useProvideIndexes(indexesId: Id, indexes: Indexes): void;
|
|
6621
6815
|
|
|
6622
6816
|
/**
|
|
@@ -7423,7 +7617,89 @@ export function useRelationshipsOrRelationshipsById(
|
|
|
7423
7617
|
relationshipsOrRelationshipsId?: RelationshipsOrRelationshipsId,
|
|
7424
7618
|
): Relationships | undefined;
|
|
7425
7619
|
|
|
7426
|
-
|
|
7620
|
+
/**
|
|
7621
|
+
* The useProvideRelationships hook is used to add a Relationships object by Id
|
|
7622
|
+
* to a Provider component, but imperatively from a component within it.
|
|
7623
|
+
*
|
|
7624
|
+
* Normally you will register a Relationships object by Id in a context by using
|
|
7625
|
+
* the `relationshipsById` prop of the top-level Provider component. This hook,
|
|
7626
|
+
* however, lets you dynamically add a new Relationships object to the context,
|
|
7627
|
+
* from within a component. This is useful for applications where the set of
|
|
7628
|
+
* Relationships objects is not known at the time of the first render of the
|
|
7629
|
+
* root Provider.
|
|
7630
|
+
*
|
|
7631
|
+
* A Relationships object added to the Provider context in this way will be
|
|
7632
|
+
* available to other components within the context (using the useRelationships
|
|
7633
|
+
* hook and so on). If you use the same Id as an existing Relationships object
|
|
7634
|
+
* registration, the new one will take priority over one provided by the
|
|
7635
|
+
* `relationshipsById` prop.
|
|
7636
|
+
*
|
|
7637
|
+
* Note that other components that consume a Relationships object registered
|
|
7638
|
+
* like this should defend against it being undefined at first. On the first
|
|
7639
|
+
* render, the other component will likely not yet have completed the
|
|
7640
|
+
* registration. In the example below, we use the null-safe
|
|
7641
|
+
* `useRelationships('petRelationships')?` to do this.
|
|
7642
|
+
* @param relationshipsId The Id of the Relationships object to be registered
|
|
7643
|
+
* with the Provider.
|
|
7644
|
+
* @param relationships The Relationships object to be registered.
|
|
7645
|
+
* @example
|
|
7646
|
+
* This example creates a Provider context. A child component registers a
|
|
7647
|
+
* Relationships object into it which is then consumable by a peer child
|
|
7648
|
+
* component.
|
|
7649
|
+
*
|
|
7650
|
+
* ```jsx
|
|
7651
|
+
* import React from 'react';
|
|
7652
|
+
* import {createRoot} from 'react-dom/client';
|
|
7653
|
+
* import {createRelationships, createStore} from 'tinybase';
|
|
7654
|
+
* import {
|
|
7655
|
+
* Provider,
|
|
7656
|
+
* useCreateRelationships,
|
|
7657
|
+
* useCreateStore,
|
|
7658
|
+
* useProvideRelationships,
|
|
7659
|
+
* useRelationships,
|
|
7660
|
+
* } from 'tinybase/ui-react';
|
|
7661
|
+
*
|
|
7662
|
+
* const App = () => (
|
|
7663
|
+
* <Provider>
|
|
7664
|
+
* <RegisterRelationships />
|
|
7665
|
+
* <ConsumeRelationships />
|
|
7666
|
+
* </Provider>
|
|
7667
|
+
* );
|
|
7668
|
+
* const RegisterRelationships = () => {
|
|
7669
|
+
* const store = useCreateStore(() =>
|
|
7670
|
+
* createStore()
|
|
7671
|
+
* .setTable('pets', {fido: {species: 'dog'}})
|
|
7672
|
+
* .setTable('species', {dog: {price: 5}}),
|
|
7673
|
+
* );
|
|
7674
|
+
* const relationships = useCreateRelationships(store, (store) =>
|
|
7675
|
+
* createRelationships(store).setRelationshipDefinition(
|
|
7676
|
+
* 'petSpecies',
|
|
7677
|
+
* 'pets',
|
|
7678
|
+
* 'species',
|
|
7679
|
+
* 'species',
|
|
7680
|
+
* ),
|
|
7681
|
+
* );
|
|
7682
|
+
* useProvideRelationships('petRelationships', relationships);
|
|
7683
|
+
* return null;
|
|
7684
|
+
* };
|
|
7685
|
+
* const ConsumeRelationships = () => (
|
|
7686
|
+
* <span>
|
|
7687
|
+
* {useRelationships('petRelationships')?.getRemoteRowId(
|
|
7688
|
+
* 'petSpecies',
|
|
7689
|
+
* 'fido',
|
|
7690
|
+
* )}
|
|
7691
|
+
* </span>
|
|
7692
|
+
* );
|
|
7693
|
+
*
|
|
7694
|
+
* const app = document.createElement('div');
|
|
7695
|
+
* const root = createRoot(app);
|
|
7696
|
+
* root.render(<App />); // !act
|
|
7697
|
+
* console.log(app.innerHTML);
|
|
7698
|
+
* // -> '<span>dog</span>'
|
|
7699
|
+
* ```
|
|
7700
|
+
* @category Relationships hooks
|
|
7701
|
+
* @since v5.3.0
|
|
7702
|
+
*/
|
|
7427
7703
|
export function useProvideRelationships(
|
|
7428
7704
|
relationshipsId: Id,
|
|
7429
7705
|
relationships: Relationships,
|
|
@@ -8477,7 +8753,82 @@ export function useQueriesOrQueriesById(
|
|
|
8477
8753
|
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
8478
8754
|
): Queries | undefined;
|
|
8479
8755
|
|
|
8480
|
-
|
|
8756
|
+
/**
|
|
8757
|
+
* The useProvideQueries hook is used to add a Queries object by Id to a
|
|
8758
|
+
* Provider component, but imperatively from a component within it.
|
|
8759
|
+
*
|
|
8760
|
+
* Normally you will register a Queries object by Id in a context by using the
|
|
8761
|
+
* `queriesById` prop of the top-level Provider component. This hook, however,
|
|
8762
|
+
* lets you dynamically add a new Queries object to the context, from within a
|
|
8763
|
+
* component. This is useful for applications where the set of Queries objects
|
|
8764
|
+
* is not known at the time of the first render of the root Provider.
|
|
8765
|
+
*
|
|
8766
|
+
* A Queries object added to the Provider context in this way will be available
|
|
8767
|
+
* to other components within the context (using the useQueries hook and so on).
|
|
8768
|
+
* If you use the same Id as an existing Queries object registration, the new
|
|
8769
|
+
* one will take priority over one provided by the `queriesById` prop.
|
|
8770
|
+
*
|
|
8771
|
+
* Note that other components that consume a Queries object registered like this
|
|
8772
|
+
* should defend against it being undefined at first. On the first render, the
|
|
8773
|
+
* other component will likely not yet have completed the registration. In the
|
|
8774
|
+
* example below, we use the null-safe `useQueries('petQueries')?` to do this.
|
|
8775
|
+
* @param queriesId The Id of the Queries object to be registered with the
|
|
8776
|
+
* Provider.
|
|
8777
|
+
* @param queries The Queries object to be registered.
|
|
8778
|
+
* @example
|
|
8779
|
+
* This example creates a Provider context. A child component registers a
|
|
8780
|
+
* Queries object into it which is then consumable by a peer child component.
|
|
8781
|
+
*
|
|
8782
|
+
* ```jsx
|
|
8783
|
+
* import React from 'react';
|
|
8784
|
+
* import {createRoot} from 'react-dom/client';
|
|
8785
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
8786
|
+
* import {
|
|
8787
|
+
* Provider,
|
|
8788
|
+
* useCreateQueries,
|
|
8789
|
+
* useCreateStore,
|
|
8790
|
+
* useProvideQueries,
|
|
8791
|
+
* useQueries,
|
|
8792
|
+
* } from 'tinybase/ui-react';
|
|
8793
|
+
*
|
|
8794
|
+
* const App = () => (
|
|
8795
|
+
* <Provider>
|
|
8796
|
+
* <RegisterQueries />
|
|
8797
|
+
* <ConsumeQueries />
|
|
8798
|
+
* </Provider>
|
|
8799
|
+
* );
|
|
8800
|
+
* const RegisterQueries = () => {
|
|
8801
|
+
* const store = useCreateStore(() =>
|
|
8802
|
+
* createStore().setRow('pets', 'fido', {color: 'brown', legs: 4}),
|
|
8803
|
+
* );
|
|
8804
|
+
* const queries = useCreateQueries(store, (store) =>
|
|
8805
|
+
* createQueries(store).setQueryDefinition(
|
|
8806
|
+
* 'brownLegs',
|
|
8807
|
+
* 'pets',
|
|
8808
|
+
* ({select, where}) => {
|
|
8809
|
+
* select('legs');
|
|
8810
|
+
* where('color', 'brown');
|
|
8811
|
+
* },
|
|
8812
|
+
* ),
|
|
8813
|
+
* );
|
|
8814
|
+
* useProvideQueries('petQueries', queries);
|
|
8815
|
+
* return null;
|
|
8816
|
+
* };
|
|
8817
|
+
* const ConsumeQueries = () => (
|
|
8818
|
+
* <span>
|
|
8819
|
+
* {JSON.stringify(useQueries('petQueries')?.getResultTable('brownLegs'))}
|
|
8820
|
+
* </span>
|
|
8821
|
+
* );
|
|
8822
|
+
*
|
|
8823
|
+
* const app = document.createElement('div');
|
|
8824
|
+
* const root = createRoot(app);
|
|
8825
|
+
* root.render(<App />); // !act
|
|
8826
|
+
* console.log(app.innerHTML);
|
|
8827
|
+
* // -> '<span>{\"fido\":{\"legs\":4}}</span>'
|
|
8828
|
+
* ```
|
|
8829
|
+
* @category Queries hooks
|
|
8830
|
+
* @since v5.3.0
|
|
8831
|
+
*/
|
|
8481
8832
|
export function useProvideQueries(queriesId: Id, queries: Queries): void;
|
|
8482
8833
|
|
|
8483
8834
|
/**
|
|
@@ -10664,7 +11015,77 @@ export function useCheckpointsOrCheckpointsById(
|
|
|
10664
11015
|
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
|
|
10665
11016
|
): Checkpoints | undefined;
|
|
10666
11017
|
|
|
10667
|
-
|
|
11018
|
+
/**
|
|
11019
|
+
* The useProvideCheckpoints hook is used to add a Checkpoints object by Id to a
|
|
11020
|
+
* Provider component, but imperatively from a component within it.
|
|
11021
|
+
*
|
|
11022
|
+
* Normally you will register a Checkpoints object by Id in a context by using
|
|
11023
|
+
* the `checkpointsById` prop of the top-level Provider component. This hook,
|
|
11024
|
+
* however, lets you dynamically add a new Checkpoints object to the context,
|
|
11025
|
+
* from within a component. This is useful for applications where the set of
|
|
11026
|
+
* Checkpoints objects is not known at the time of the first render of the root
|
|
11027
|
+
* Provider.
|
|
11028
|
+
*
|
|
11029
|
+
* A Checkpoints object added to the Provider context in this way will be
|
|
11030
|
+
* available to other components within the context (using the useCheckpoints
|
|
11031
|
+
* hook and so on). If you use the same Id as an existing Checkpoints object
|
|
11032
|
+
* registration, the new one will take priority over one provided by the
|
|
11033
|
+
* `checkpointsById` prop.
|
|
11034
|
+
*
|
|
11035
|
+
* Note that other components that consume a Checkpoints object registered like
|
|
11036
|
+
* this should defend against it being undefined at first. On the first render,
|
|
11037
|
+
* the other component will likely not yet have completed the registration. In
|
|
11038
|
+
* the example below, we use the null-safe `useCheckpoints('petCheckpoints')?`
|
|
11039
|
+
* to do this.
|
|
11040
|
+
* @param checkpointsId The Id of the Checkpoints object to be registered with
|
|
11041
|
+
* the Provider.
|
|
11042
|
+
* @param checkpoints The Checkpoints object to be registered.
|
|
11043
|
+
* @example
|
|
11044
|
+
* This example creates a Provider context. A child component registers a
|
|
11045
|
+
* Checkpoints object into it which is then consumable by a peer child
|
|
11046
|
+
* component.
|
|
11047
|
+
*
|
|
11048
|
+
* ```jsx
|
|
11049
|
+
* import React from 'react';
|
|
11050
|
+
* import {createRoot} from 'react-dom/client';
|
|
11051
|
+
* import {createCheckpoints, createStore} from 'tinybase';
|
|
11052
|
+
* import {
|
|
11053
|
+
* Provider,
|
|
11054
|
+
* useCheckpoints,
|
|
11055
|
+
* useCreateCheckpoints,
|
|
11056
|
+
* useCreateStore,
|
|
11057
|
+
* useProvideCheckpoints,
|
|
11058
|
+
* } from 'tinybase/ui-react';
|
|
11059
|
+
*
|
|
11060
|
+
* const App = () => (
|
|
11061
|
+
* <Provider>
|
|
11062
|
+
* <RegisterCheckpoints />
|
|
11063
|
+
* <ConsumeCheckpoints />
|
|
11064
|
+
* </Provider>
|
|
11065
|
+
* );
|
|
11066
|
+
* const RegisterCheckpoints = () => {
|
|
11067
|
+
* const store = useCreateStore(() =>
|
|
11068
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
11069
|
+
* );
|
|
11070
|
+
* const checkpoints = useCreateCheckpoints(store, createCheckpoints);
|
|
11071
|
+
* useProvideCheckpoints('petCheckpoints', checkpoints);
|
|
11072
|
+
* return null;
|
|
11073
|
+
* };
|
|
11074
|
+
* const ConsumeCheckpoints = () => (
|
|
11075
|
+
* <span>
|
|
11076
|
+
* {JSON.stringify(useCheckpoints('petCheckpoints')?.getCheckpointIds())}
|
|
11077
|
+
* </span>
|
|
11078
|
+
* );
|
|
11079
|
+
*
|
|
11080
|
+
* const app = document.createElement('div');
|
|
11081
|
+
* const root = createRoot(app);
|
|
11082
|
+
* root.render(<App />); // !act
|
|
11083
|
+
* console.log(app.innerHTML);
|
|
11084
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
11085
|
+
* ```
|
|
11086
|
+
* @category Checkpoints hooks
|
|
11087
|
+
* @since v5.3.0
|
|
11088
|
+
*/
|
|
10668
11089
|
export function useProvideCheckpoints(
|
|
10669
11090
|
checkpointsId: Id,
|
|
10670
11091
|
checkpoints: Checkpoints,
|
|
@@ -11627,7 +12048,7 @@ export function useCreatePersister<
|
|
|
11627
12048
|
store: PersistedStore<Persist>,
|
|
11628
12049
|
) => PersisterOrUndefined | Promise<PersisterOrUndefined>,
|
|
11629
12050
|
createDeps?: React.DependencyList,
|
|
11630
|
-
then?: (persister: Persister<Persist>) => Promise<
|
|
12051
|
+
then?: (persister: Persister<Persist>) => Promise<any>,
|
|
11631
12052
|
thenDeps?: React.DependencyList,
|
|
11632
12053
|
destroy?: (persister: Persister<Persist>) => void,
|
|
11633
12054
|
destroyDeps?: React.DependencyList,
|
|
@@ -11812,7 +12233,80 @@ export function usePersisterOrPersisterById(
|
|
|
11812
12233
|
persisterOrPersisterId?: PersisterOrPersisterId,
|
|
11813
12234
|
): AnyPersister | undefined;
|
|
11814
12235
|
|
|
11815
|
-
|
|
12236
|
+
/**
|
|
12237
|
+
* The useProvidePersister hook is used to add a Persister object by Id to a
|
|
12238
|
+
* Provider component, but imperatively from a component within it.
|
|
12239
|
+
*
|
|
12240
|
+
* Normally you will register a Persister object by Id in a context by using the
|
|
12241
|
+
* `persistersById` prop of the top-level Provider component. This hook,
|
|
12242
|
+
* however, lets you dynamically add a new Persister object to the context, from
|
|
12243
|
+
* within a component. This is useful for applications where the set of
|
|
12244
|
+
* Persister objects is not known at the time of the first render of the root
|
|
12245
|
+
* Provider.
|
|
12246
|
+
*
|
|
12247
|
+
* A Persister object added to the Provider context in this way will be
|
|
12248
|
+
* available to other components within the context (using the usePersister hook
|
|
12249
|
+
* and so on). If you use the same Id as an existing Persister object
|
|
12250
|
+
* registration, the new one will take priority over one provided by the
|
|
12251
|
+
* `persistersById` prop.
|
|
12252
|
+
*
|
|
12253
|
+
* Note that other components that consume a Persister object registered like
|
|
12254
|
+
* this should defend against it being undefined at first. On the first render,
|
|
12255
|
+
* the other component will likely not yet have completed the registration. In
|
|
12256
|
+
* the example below, we use the null-safe `usePersister('petPersister')?` to do
|
|
12257
|
+
* this.
|
|
12258
|
+
* @param persisterId The Id of the Persister object to be registered with the
|
|
12259
|
+
* Provider.
|
|
12260
|
+
* @param persister The Persister object to be registered.
|
|
12261
|
+
* @example
|
|
12262
|
+
* This example creates a Provider context. A child component registers a
|
|
12263
|
+
* Persister object into it which is then consumable by a peer child
|
|
12264
|
+
* component.
|
|
12265
|
+
*
|
|
12266
|
+
* ```jsx
|
|
12267
|
+
* import React from 'react';
|
|
12268
|
+
* import {createRoot} from 'react-dom/client';
|
|
12269
|
+
* import {createStore} from 'tinybase';
|
|
12270
|
+
* import {createSessionPersister} from 'tinybase/persisters/persister-browser';
|
|
12271
|
+
* import {
|
|
12272
|
+
* Provider,
|
|
12273
|
+
* useCreatePersister,
|
|
12274
|
+
* useCreateStore,
|
|
12275
|
+
* usePersister,
|
|
12276
|
+
* useProvidePersister,
|
|
12277
|
+
* } from 'tinybase/ui-react';
|
|
12278
|
+
*
|
|
12279
|
+
* const App = () => (
|
|
12280
|
+
* <Provider>
|
|
12281
|
+
* <RegisterPersister />
|
|
12282
|
+
* <ConsumePersister />
|
|
12283
|
+
* </Provider>
|
|
12284
|
+
* );
|
|
12285
|
+
* const RegisterPersister = () => {
|
|
12286
|
+
* const store = useCreateStore(() =>
|
|
12287
|
+
* createStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
12288
|
+
* );
|
|
12289
|
+
* const persister = useCreatePersister(store, (store) =>
|
|
12290
|
+
* createSessionPersister(store, 'pets'),
|
|
12291
|
+
* );
|
|
12292
|
+
* useProvidePersister('petPersister', persister);
|
|
12293
|
+
* return null;
|
|
12294
|
+
* };
|
|
12295
|
+
* const ConsumePersister = () => (
|
|
12296
|
+
* <span>{usePersister('petPersister')?.getStatus()}</span>
|
|
12297
|
+
* );
|
|
12298
|
+
*
|
|
12299
|
+
* const app = document.createElement('div');
|
|
12300
|
+
* const root = createRoot(app);
|
|
12301
|
+
* root.render(<App />); // !act
|
|
12302
|
+
*
|
|
12303
|
+
* // ... // !act
|
|
12304
|
+
* console.log(app.innerHTML);
|
|
12305
|
+
* // -> '<span>0</span>'
|
|
12306
|
+
* ```
|
|
12307
|
+
* @category Persister hooks
|
|
12308
|
+
* @since v5.3.0
|
|
12309
|
+
*/
|
|
11816
12310
|
export function useProvidePersister(
|
|
11817
12311
|
persisterId: Id,
|
|
11818
12312
|
persister: AnyPersister,
|
|
@@ -12315,7 +12809,81 @@ export function useSynchronizerOrSynchronizerById(
|
|
|
12315
12809
|
synchronizerOrSynchronizerId?: SynchronizerOrSynchronizerId,
|
|
12316
12810
|
): Synchronizer | undefined;
|
|
12317
12811
|
|
|
12318
|
-
|
|
12812
|
+
/**
|
|
12813
|
+
* The useProvideSynchronizer hook is used to add a Synchronizer object by Id to
|
|
12814
|
+
* a Provider component, but imperatively from a component within it.
|
|
12815
|
+
*
|
|
12816
|
+
* Normally you will register a Synchronizer object by Id in a context by using
|
|
12817
|
+
* the `synchronizersById` prop of the top-level Provider component. This hook,
|
|
12818
|
+
* however, lets you dynamically add a new Synchronizer object to the context,
|
|
12819
|
+
* from within a component. This is useful for applications where the set of
|
|
12820
|
+
* Synchronizer objects is not known at the time of the first render of the root
|
|
12821
|
+
* Provider.
|
|
12822
|
+
*
|
|
12823
|
+
* A Synchronizer object added to the Provider context in this way will be
|
|
12824
|
+
* available to other components within the context (using the useSynchronizer
|
|
12825
|
+
* hook and so on). If you use the same Id as an existing Synchronizer object
|
|
12826
|
+
* registration, the new one will take priority over one provided by the
|
|
12827
|
+
* `synchronizersById` prop.
|
|
12828
|
+
*
|
|
12829
|
+
* Note that other components that consume a Synchronizer object registered like
|
|
12830
|
+
* this should defend against it being undefined at first. On the first render,
|
|
12831
|
+
* the other component will likely not yet have completed the registration. In
|
|
12832
|
+
* the example below, we use the null-safe `useSynchronizer('petSynchronizer')?`
|
|
12833
|
+
* to do this.
|
|
12834
|
+
* @param synchronizerId The Id of the Synchronizer object to be registered with
|
|
12835
|
+
* the Provider.
|
|
12836
|
+
* @param synchronizer The Synchronizer object to be registered.
|
|
12837
|
+
* @example
|
|
12838
|
+
* This example creates a Provider context. A child component registers a
|
|
12839
|
+
* Synchronizer object into it which is then consumable by a peer child
|
|
12840
|
+
* component.
|
|
12841
|
+
*
|
|
12842
|
+
* ```jsx
|
|
12843
|
+
* import React from 'react';
|
|
12844
|
+
* import {createRoot} from 'react-dom/client';
|
|
12845
|
+
* import {createMergeableStore} from 'tinybase';
|
|
12846
|
+
* import {createLocalSynchronizer} from 'tinybase/synchronizers/synchronizer-local';
|
|
12847
|
+
* import {
|
|
12848
|
+
* Provider,
|
|
12849
|
+
* useCreateStore,
|
|
12850
|
+
* useCreateSynchronizer,
|
|
12851
|
+
* useProvideSynchronizer,
|
|
12852
|
+
* useSynchronizer,
|
|
12853
|
+
* } from 'tinybase/ui-react';
|
|
12854
|
+
*
|
|
12855
|
+
* const App = () => (
|
|
12856
|
+
* <Provider>
|
|
12857
|
+
* <RegisterSynchronizer />
|
|
12858
|
+
* <ConsumeSynchronizer />
|
|
12859
|
+
* </Provider>
|
|
12860
|
+
* );
|
|
12861
|
+
* const RegisterSynchronizer = () => {
|
|
12862
|
+
* const store = useCreateStore(() =>
|
|
12863
|
+
* createMergeableStore().setCell('pets', 'fido', 'color', 'brown'),
|
|
12864
|
+
* );
|
|
12865
|
+
* const synchronizer = useCreateSynchronizer(
|
|
12866
|
+
* store,
|
|
12867
|
+
* createLocalSynchronizer,
|
|
12868
|
+
* );
|
|
12869
|
+
* useProvideSynchronizer('petSynchronizer', synchronizer);
|
|
12870
|
+
* return null;
|
|
12871
|
+
* };
|
|
12872
|
+
* const ConsumeSynchronizer = () => (
|
|
12873
|
+
* <span>{useSynchronizer('petSynchronizer')?.getStatus()}</span>
|
|
12874
|
+
* );
|
|
12875
|
+
*
|
|
12876
|
+
* const app = document.createElement('div');
|
|
12877
|
+
* const root = createRoot(app);
|
|
12878
|
+
* root.render(<App />); // !act
|
|
12879
|
+
*
|
|
12880
|
+
* // ... // !act
|
|
12881
|
+
* console.log(app.innerHTML);
|
|
12882
|
+
* // -> '<span>0</span>'
|
|
12883
|
+
* ```
|
|
12884
|
+
* @category Synchronizer hooks
|
|
12885
|
+
* @since v5.3.0
|
|
12886
|
+
*/
|
|
12319
12887
|
export function useProvideSynchronizer(
|
|
12320
12888
|
synchronizerId: Id,
|
|
12321
12889
|
synchronizer: Synchronizer,
|