tinybase 1.3.4 → 2.0.0-beta.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/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.js +67 -54
- package/lib/debug/indexes.js +104 -67
- package/lib/debug/metrics.js +185 -129
- package/lib/debug/persisters.js +2 -1
- package/lib/debug/queries.d.ts +3054 -0
- package/lib/debug/queries.js +880 -0
- package/lib/debug/relationships.d.ts +6 -5
- package/lib/debug/relationships.js +102 -66
- package/lib/debug/store.d.ts +137 -66
- package/lib/debug/store.js +215 -119
- package/lib/debug/tinybase.d.ts +1 -0
- package/lib/debug/tinybase.js +892 -175
- package/lib/debug/ui-react.d.ts +2004 -195
- package/lib/debug/ui-react.js +273 -77
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/queries.d.ts +3054 -0
- package/lib/queries.js +1 -0
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +6 -5
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +137 -66
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.d.ts +1 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/ui-react.d.ts +2004 -195
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -0
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/package.json +22 -22
- package/readme.md +2 -2
package/lib/debug/ui-react.d.ts
CHANGED
|
@@ -53,6 +53,14 @@ import {
|
|
|
53
53
|
RemoteRowIdListener,
|
|
54
54
|
} from './relationships.d';
|
|
55
55
|
import {MetricListener, Metrics} from './metrics.d';
|
|
56
|
+
import {
|
|
57
|
+
Queries,
|
|
58
|
+
ResultCellIdsListener,
|
|
59
|
+
ResultCellListener,
|
|
60
|
+
ResultRowIdsListener,
|
|
61
|
+
ResultRowListener,
|
|
62
|
+
ResultTableListener,
|
|
63
|
+
} from './queries.d';
|
|
56
64
|
import {Persister} from './persisters.d';
|
|
57
65
|
|
|
58
66
|
/**
|
|
@@ -129,6 +137,25 @@ export type IndexesOrIndexesId = Indexes | Id;
|
|
|
129
137
|
*/
|
|
130
138
|
export type RelationshipsOrRelationshipsId = Relationships | Id;
|
|
131
139
|
|
|
140
|
+
/**
|
|
141
|
+
* The QueriesOrQueriesId type is used when you need to refer to a Queries
|
|
142
|
+
* object in a React hook or component.
|
|
143
|
+
*
|
|
144
|
+
* In some simple cases you will already have a direct reference to the Queries
|
|
145
|
+
* object.
|
|
146
|
+
*
|
|
147
|
+
* This module also includes a Provider component that can be used to wrap
|
|
148
|
+
* multiple Queries objects into a context that can be used throughout the app.
|
|
149
|
+
* In this case you will want to refer to a Queries object by its Id in that
|
|
150
|
+
* context.
|
|
151
|
+
*
|
|
152
|
+
* Many hooks and components in this ui-react module take this type as a
|
|
153
|
+
* parameter or a prop, allowing you to pass in either the Store or its Id.
|
|
154
|
+
*
|
|
155
|
+
* @category Identity
|
|
156
|
+
*/
|
|
157
|
+
export type QueriesOrQueriesId = Queries | Id;
|
|
158
|
+
|
|
132
159
|
/**
|
|
133
160
|
* The CheckpointsOrCheckpointsId type is used when you need to refer to a
|
|
134
161
|
* Checkpoints object in a React hook or component.
|
|
@@ -399,6 +426,9 @@ export function useTables(storeOrStoreId?: StoreOrStoreId): Tables;
|
|
|
399
426
|
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
400
427
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
401
428
|
* reference.
|
|
429
|
+
* @param trackReorder Since v2.0.0, an optional boolean that indicates that the
|
|
430
|
+
* listener should be called if the set of Ids remains the same but their order
|
|
431
|
+
* changes. See the addTableIdsListener method for more details.
|
|
402
432
|
* @returns An array of the Ids of every Table in the Store.
|
|
403
433
|
* @example
|
|
404
434
|
* This example creates a Store outside the application, which is used in the
|
|
@@ -456,7 +486,10 @@ export function useTables(storeOrStoreId?: StoreOrStoreId): Tables;
|
|
|
456
486
|
* ```
|
|
457
487
|
* @category Store hooks
|
|
458
488
|
*/
|
|
459
|
-
export function useTableIds(
|
|
489
|
+
export function useTableIds(
|
|
490
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
491
|
+
trackReorder?: boolean,
|
|
492
|
+
): Ids;
|
|
460
493
|
|
|
461
494
|
/**
|
|
462
495
|
* The useTable hook returns an object containing the entire data of a single
|
|
@@ -557,6 +590,9 @@ export function useTable(tableId: Id, storeOrStoreId?: StoreOrStoreId): Table;
|
|
|
557
590
|
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
558
591
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
559
592
|
* reference.
|
|
593
|
+
* @param trackReorder Since v2.0.0, an optional boolean that indicates that the
|
|
594
|
+
* listener should be called if the set of Ids remains the same but their order
|
|
595
|
+
* changes. See the addRowIdsListener method for more details.
|
|
560
596
|
* @returns An array of the Ids of every Row in the Table.
|
|
561
597
|
* @example
|
|
562
598
|
* This example creates a Store outside the application, which is used in the
|
|
@@ -616,7 +652,11 @@ export function useTable(tableId: Id, storeOrStoreId?: StoreOrStoreId): Table;
|
|
|
616
652
|
* ```
|
|
617
653
|
* @category Store hooks
|
|
618
654
|
*/
|
|
619
|
-
export function useRowIds(
|
|
655
|
+
export function useRowIds(
|
|
656
|
+
tableId: Id,
|
|
657
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
658
|
+
trackReorder?: boolean,
|
|
659
|
+
): Ids;
|
|
620
660
|
|
|
621
661
|
/**
|
|
622
662
|
* The useRow hook returns an object containing the entire data of a single Row
|
|
@@ -725,6 +765,9 @@ export function useRow(
|
|
|
725
765
|
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
726
766
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
727
767
|
* reference.
|
|
768
|
+
* @param trackReorder Since v2.0.0, an optional boolean that indicates that the
|
|
769
|
+
* listener should be called if the set of Ids remains the same but their order
|
|
770
|
+
* changes. See the addCellIdsListener method for more details.
|
|
728
771
|
* @returns An array of the Ids of every Cell in the Row.
|
|
729
772
|
* @example
|
|
730
773
|
* This example creates a Store outside the application, which is used in the
|
|
@@ -792,6 +835,7 @@ export function useCellIds(
|
|
|
792
835
|
tableId: Id,
|
|
793
836
|
rowId: Id,
|
|
794
837
|
storeOrStoreId?: StoreOrStoreId,
|
|
838
|
+
trackReorder?: boolean,
|
|
795
839
|
): Ids;
|
|
796
840
|
|
|
797
841
|
/**
|
|
@@ -1798,6 +1842,9 @@ export function useTablesListener(
|
|
|
1798
1842
|
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
1799
1843
|
* function, which, if any change, result in the re-registration of the
|
|
1800
1844
|
* listener. This parameter defaults to an empty array.
|
|
1845
|
+
* @param trackReorder Since v2.0.0, an optional boolean that indicates that the
|
|
1846
|
+
* listener should be called if the set of Ids remains the same but their order
|
|
1847
|
+
* changes. See the addTableIdsListener method for more details.
|
|
1801
1848
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
1802
1849
|
* Store data.
|
|
1803
1850
|
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
@@ -1837,6 +1884,7 @@ export function useTablesListener(
|
|
|
1837
1884
|
export function useTableIdsListener(
|
|
1838
1885
|
listener: TableIdsListener,
|
|
1839
1886
|
listenerDeps?: React.DependencyList,
|
|
1887
|
+
trackReorder?: boolean,
|
|
1840
1888
|
mutator?: boolean,
|
|
1841
1889
|
storeOrStoreId?: StoreOrStoreId,
|
|
1842
1890
|
): void;
|
|
@@ -1929,6 +1977,9 @@ export function useTableListener(
|
|
|
1929
1977
|
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
1930
1978
|
* function, which, if any change, result in the re-registration of the
|
|
1931
1979
|
* listener. This parameter defaults to an empty array.
|
|
1980
|
+
* @param trackReorder Since v2.0.0, an optional boolean that indicates that the
|
|
1981
|
+
* listener should be called if the set of Ids remains the same but their order
|
|
1982
|
+
* changes. See the addRowIdsListener method for more details.
|
|
1932
1983
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
1933
1984
|
* Store data.
|
|
1934
1985
|
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
@@ -1969,6 +2020,7 @@ export function useRowIdsListener(
|
|
|
1969
2020
|
tableId: IdOrNull,
|
|
1970
2021
|
listener: RowIdsListener,
|
|
1971
2022
|
listenerDeps?: React.DependencyList,
|
|
2023
|
+
trackReorder?: boolean,
|
|
1972
2024
|
mutator?: boolean,
|
|
1973
2025
|
storeOrStoreId?: StoreOrStoreId,
|
|
1974
2026
|
): void;
|
|
@@ -2077,6 +2129,9 @@ export function useRowListener(
|
|
|
2077
2129
|
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
2078
2130
|
* function, which, if any change, result in the re-registration of the
|
|
2079
2131
|
* listener. This parameter defaults to an empty array.
|
|
2132
|
+
* @param trackReorder Since v2.0.0, an optional boolean that indicates that the
|
|
2133
|
+
* listener should be called if the set of Ids remains the same but their order
|
|
2134
|
+
* changes. See the addCellIdsListener method for more details.
|
|
2080
2135
|
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2081
2136
|
* Store data.
|
|
2082
2137
|
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
@@ -2120,6 +2175,7 @@ export function useCellIdsListener(
|
|
|
2120
2175
|
rowId: IdOrNull,
|
|
2121
2176
|
listener: CellIdsListener,
|
|
2122
2177
|
listenerDeps?: React.DependencyList,
|
|
2178
|
+
trackReorder?: boolean,
|
|
2123
2179
|
mutator?: boolean,
|
|
2124
2180
|
storeOrStoreId?: StoreOrStoreId,
|
|
2125
2181
|
): void;
|
|
@@ -3898,307 +3954,1521 @@ export function useLinkedRowIdsListener(
|
|
|
3898
3954
|
): void;
|
|
3899
3955
|
|
|
3900
3956
|
/**
|
|
3901
|
-
* The
|
|
3902
|
-
*
|
|
3957
|
+
* The useCreateQueries hook is used to create a Queries object within a React
|
|
3958
|
+
* application with convenient memoization.
|
|
3903
3959
|
*
|
|
3904
|
-
* It is possible to create a
|
|
3905
|
-
*
|
|
3906
|
-
*
|
|
3907
|
-
*
|
|
3908
|
-
*
|
|
3909
|
-
* memoization.
|
|
3960
|
+
* It is possible to create a Queries object outside of the React app with the
|
|
3961
|
+
* regular createQueries function and pass it in, but you may prefer to create
|
|
3962
|
+
* it within the app, perhaps inside the top-level component. To defend against
|
|
3963
|
+
* a new Queries object being created every time the app renders or re-renders,
|
|
3964
|
+
* the useCreateQueries hook wraps the creation in a memoization.
|
|
3910
3965
|
*
|
|
3911
|
-
* The
|
|
3912
|
-
*
|
|
3913
|
-
*
|
|
3966
|
+
* The useCreateQueries hook is a very thin wrapper around the React `useMemo`
|
|
3967
|
+
* hook, defaulting to the provided Store as its dependency, so that by default,
|
|
3968
|
+
* the creation only occurs once per Store.
|
|
3914
3969
|
*
|
|
3915
3970
|
* If your `create` function contains other dependencies, the changing of which
|
|
3916
|
-
* should also cause the
|
|
3917
|
-
*
|
|
3918
|
-
*
|
|
3971
|
+
* should also cause the Queries object to be recreated, you can provide them in
|
|
3972
|
+
* an array in the optional second parameter, just as you would for any React
|
|
3973
|
+
* hook with dependencies.
|
|
3919
3974
|
*
|
|
3920
|
-
* This hook ensures the
|
|
3975
|
+
* This hook ensures the Queries object is destroyed whenever a new one is
|
|
3921
3976
|
* created or the component is unmounted.
|
|
3922
3977
|
*
|
|
3923
|
-
* @param store A reference to the Store for which to create a new
|
|
3978
|
+
* @param store A reference to the Store for which to create a new Queries
|
|
3924
3979
|
* object.
|
|
3925
|
-
* @param create
|
|
3926
|
-
* object
|
|
3927
|
-
* listeners, and returning it.
|
|
3980
|
+
* @param create An optional callback for performing post-creation steps on the
|
|
3981
|
+
* Queries object, such as adding definitions or listeners.
|
|
3928
3982
|
* @param createDeps An optional array of dependencies for the `create`
|
|
3929
3983
|
* function, which, if any change, result in its rerun. This parameter defaults
|
|
3930
3984
|
* to an empty array.
|
|
3931
|
-
* @returns A reference to the
|
|
3985
|
+
* @returns A reference to the Queries object.
|
|
3932
3986
|
* @example
|
|
3933
|
-
* This example creates a
|
|
3934
|
-
* application. Even though the App component is rendered twice, the
|
|
3935
|
-
*
|
|
3987
|
+
* This example creates a Queries object at the top level of a React
|
|
3988
|
+
* application. Even though the App component is rendered twice, the Queries
|
|
3989
|
+
* object creation only occurs once by default.
|
|
3936
3990
|
*
|
|
3937
3991
|
* ```jsx
|
|
3938
3992
|
* const App = () => {
|
|
3939
|
-
* const store = useCreateStore(
|
|
3940
|
-
*
|
|
3941
|
-
*
|
|
3942
|
-
*
|
|
3993
|
+
* const store = useCreateStore(() =>
|
|
3994
|
+
* createStore().setTable('pets', {
|
|
3995
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
3996
|
+
* felix: {species: 'cat', color: 'black'},
|
|
3997
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
3998
|
+
* }),
|
|
3999
|
+
* );
|
|
4000
|
+
* const queries = useCreateQueries(store, (store) => {
|
|
4001
|
+
* console.log('Queries created');
|
|
4002
|
+
* return createQueries(store).setQueryDefinition(
|
|
4003
|
+
* 'dogColors',
|
|
4004
|
+
* 'pets',
|
|
4005
|
+
* ({select, where}) => {
|
|
4006
|
+
* select('color');
|
|
4007
|
+
* where('species', 'dog');
|
|
4008
|
+
* },
|
|
4009
|
+
* );
|
|
3943
4010
|
* });
|
|
3944
|
-
* return
|
|
4011
|
+
* return (
|
|
4012
|
+
* <span>{queries.getResultCell('dogColors', 'fido', 'color')}</span>
|
|
4013
|
+
* );
|
|
3945
4014
|
* };
|
|
3946
4015
|
*
|
|
3947
4016
|
* const app = document.createElement('div');
|
|
3948
4017
|
* ReactDOM.render(<App />, app); // !act
|
|
3949
|
-
* // -> '
|
|
4018
|
+
* // -> 'Queries created'
|
|
3950
4019
|
*
|
|
3951
4020
|
* ReactDOM.render(<App />, app); // !act
|
|
3952
|
-
* // No second
|
|
4021
|
+
* // No second Queries creation
|
|
3953
4022
|
*
|
|
3954
4023
|
* console.log(app.innerHTML);
|
|
3955
|
-
* // -> '<span>
|
|
4024
|
+
* // -> '<span>brown</span>'
|
|
3956
4025
|
* ```
|
|
3957
4026
|
* @example
|
|
3958
|
-
* This example creates a
|
|
4027
|
+
* This example creates a Queries object at the top level of a React
|
|
3959
4028
|
* application. The App component is rendered twice, each with a different
|
|
3960
|
-
* top-level prop. The
|
|
3961
|
-
* dependency, and so the
|
|
3962
|
-
* render.
|
|
4029
|
+
* top-level prop. The useCreateQueries hook takes the `resultCell` prop as a
|
|
4030
|
+
* dependency, and so the Queries object is created again on the second render.
|
|
3963
4031
|
*
|
|
3964
4032
|
* ```jsx
|
|
3965
|
-
* const App = (
|
|
3966
|
-
* const store = useCreateStore(
|
|
3967
|
-
*
|
|
3968
|
-
*
|
|
3969
|
-
*
|
|
3970
|
-
*
|
|
3971
|
-
*
|
|
3972
|
-
*
|
|
3973
|
-
*
|
|
4033
|
+
* const App = () => {
|
|
4034
|
+
* const store = useCreateStore(() =>
|
|
4035
|
+
* createStore().setTable('pets', {
|
|
4036
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4037
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4038
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4039
|
+
* }),
|
|
4040
|
+
* );
|
|
4041
|
+
* const queries = useCreateQueries(store, (store) => {
|
|
4042
|
+
* console.log('Queries created');
|
|
4043
|
+
* return createQueries(store).setQueryDefinition(
|
|
4044
|
+
* 'dogColors',
|
|
4045
|
+
* 'pets',
|
|
4046
|
+
* ({select, where}) => {
|
|
4047
|
+
* select('color');
|
|
4048
|
+
* where('species', 'dog');
|
|
4049
|
+
* },
|
|
4050
|
+
* );
|
|
4051
|
+
* });
|
|
4052
|
+
* return (
|
|
4053
|
+
* <span>{queries.getResultCell('dogColors', 'fido', 'color')}</span>
|
|
3974
4054
|
* );
|
|
3975
|
-
* return <span>{JSON.stringify(checkpoints.getCheckpointIds())}</span>;
|
|
3976
4055
|
* };
|
|
3977
4056
|
*
|
|
3978
4057
|
* const app = document.createElement('div');
|
|
3979
|
-
* ReactDOM.render(<App
|
|
3980
|
-
* // -> '
|
|
3981
|
-
*
|
|
3982
|
-
* console.log(app.innerHTML);
|
|
3983
|
-
* // -> '<span>[[],"0",[]]</span>'
|
|
4058
|
+
* ReactDOM.render(<App />, app); // !act
|
|
4059
|
+
* // -> 'Queries created'
|
|
3984
4060
|
*
|
|
3985
|
-
* ReactDOM.render(<App
|
|
3986
|
-
* //
|
|
4061
|
+
* ReactDOM.render(<App />, app); // !act
|
|
4062
|
+
* // No second Queries creation
|
|
3987
4063
|
*
|
|
3988
4064
|
* console.log(app.innerHTML);
|
|
3989
|
-
* // -> '<span>
|
|
4065
|
+
* // -> '<span>brown</span>'
|
|
3990
4066
|
* ```
|
|
3991
|
-
* @category
|
|
4067
|
+
* @category Queries hooks
|
|
4068
|
+
* @since v2.0.0-beta
|
|
3992
4069
|
*/
|
|
3993
|
-
export function
|
|
4070
|
+
export function useCreateQueries(
|
|
3994
4071
|
store: Store,
|
|
3995
|
-
create: (store: Store) =>
|
|
4072
|
+
create: (store: Store) => Queries,
|
|
3996
4073
|
createDeps?: React.DependencyList,
|
|
3997
|
-
):
|
|
4074
|
+
): Queries;
|
|
3998
4075
|
|
|
3999
4076
|
/**
|
|
4000
|
-
* The
|
|
4001
|
-
*
|
|
4077
|
+
* The useQueries hook is used to get a reference to a Queries object from
|
|
4078
|
+
* within a Provider component context.
|
|
4002
4079
|
*
|
|
4003
4080
|
* A Provider component is used to wrap part of an application in a context. It
|
|
4004
|
-
* can contain a default
|
|
4005
|
-
*
|
|
4006
|
-
*
|
|
4081
|
+
* can contain a default Queries object (or a set of Queries objects named by
|
|
4082
|
+
* Id) that can be easily accessed without having to be passed down as props
|
|
4083
|
+
* through every component.
|
|
4007
4084
|
*
|
|
4008
|
-
* The
|
|
4009
|
-
*
|
|
4010
|
-
*
|
|
4085
|
+
* The useQueries hook lets you either get a reference to the default Queries
|
|
4086
|
+
* object (when called without an parameter), or one of the Queries objects that
|
|
4087
|
+
* are named by Id (when called with an Id parameter).
|
|
4011
4088
|
*
|
|
4012
|
-
* @param id An optional Id for accessing a
|
|
4013
|
-
*
|
|
4014
|
-
* @returns A reference to the
|
|
4015
|
-
*
|
|
4089
|
+
* @param id An optional Id for accessing a Queries object that was named with
|
|
4090
|
+
* an Id in the Provider.
|
|
4091
|
+
* @returns A reference to the Queries object (or `undefined` if not within a
|
|
4092
|
+
* Provider context, or if the requested Queries object does not exist)
|
|
4016
4093
|
* @example
|
|
4017
|
-
* This example creates a Provider context into which a default
|
|
4018
|
-
*
|
|
4019
|
-
*
|
|
4020
|
-
*
|
|
4094
|
+
* This example creates a Provider context into which a default Queries object
|
|
4095
|
+
* is provided. A component within it then uses the useQueries hook to get a
|
|
4096
|
+
* reference to the Queries object again, without the need to have it passed as
|
|
4097
|
+
* a prop.
|
|
4021
4098
|
*
|
|
4022
4099
|
* ```jsx
|
|
4023
|
-
* const App = ({
|
|
4024
|
-
* <Provider
|
|
4100
|
+
* const App = ({queries}) => (
|
|
4101
|
+
* <Provider queries={queries}>
|
|
4025
4102
|
* <Pane />
|
|
4026
4103
|
* </Provider>
|
|
4027
4104
|
* );
|
|
4028
|
-
* const Pane = () => (
|
|
4029
|
-
* <span>{useCheckpoints().getListenerStats().checkpointIds}</span>
|
|
4030
|
-
* );
|
|
4105
|
+
* const Pane = () => <span>{useQueries().getListenerStats().table}</span>;
|
|
4031
4106
|
*
|
|
4032
|
-
* const
|
|
4107
|
+
* const queries = createQueries(createStore());
|
|
4033
4108
|
* const app = document.createElement('div');
|
|
4034
|
-
* ReactDOM.render(<App
|
|
4109
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4035
4110
|
* console.log(app.innerHTML);
|
|
4036
4111
|
* // -> '<span>0</span>'
|
|
4037
4112
|
* ```
|
|
4038
4113
|
* @example
|
|
4039
|
-
* This example creates a Provider context into which a
|
|
4040
|
-
* provided, named by Id. A component within it then uses the
|
|
4041
|
-
*
|
|
4042
|
-
*
|
|
4114
|
+
* This example creates a Provider context into which a Queries object is
|
|
4115
|
+
* provided, named by Id. A component within it then uses the useQueries hook
|
|
4116
|
+
* with that Id to get a reference to the Queries object again, without the need
|
|
4117
|
+
* to have it passed as a prop.
|
|
4043
4118
|
*
|
|
4044
4119
|
* ```jsx
|
|
4045
|
-
* const App = ({
|
|
4046
|
-
* <Provider
|
|
4120
|
+
* const App = ({queries}) => (
|
|
4121
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
4047
4122
|
* <Pane />
|
|
4048
4123
|
* </Provider>
|
|
4049
4124
|
* );
|
|
4050
4125
|
* const Pane = () => (
|
|
4051
|
-
* <span>
|
|
4052
|
-
* {useCheckpoints('petStore').getListenerStats().checkpointIds}
|
|
4053
|
-
* </span>
|
|
4126
|
+
* <span>{useQueries('petQueries').getListenerStats().table}</span>
|
|
4054
4127
|
* );
|
|
4055
4128
|
*
|
|
4056
|
-
* const
|
|
4129
|
+
* const queries = createQueries(createStore());
|
|
4057
4130
|
* const app = document.createElement('div');
|
|
4058
|
-
* ReactDOM.render(<App
|
|
4131
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4059
4132
|
* console.log(app.innerHTML);
|
|
4060
4133
|
* // -> '<span>0</span>'
|
|
4061
4134
|
* ```
|
|
4062
|
-
* @category
|
|
4135
|
+
* @category Queries hooks
|
|
4063
4136
|
*/
|
|
4064
|
-
export function
|
|
4137
|
+
export function useQueries(id?: Id): Queries | undefined;
|
|
4065
4138
|
|
|
4066
4139
|
/**
|
|
4067
|
-
* The
|
|
4068
|
-
*
|
|
4069
|
-
*
|
|
4070
|
-
*
|
|
4140
|
+
* The useResultTable hook returns an object containing the entire data of the
|
|
4141
|
+
* result Table of the given query, and registers a listener so that any changes
|
|
4142
|
+
* to that result will cause a re-render.
|
|
4071
4143
|
*
|
|
4072
4144
|
* A Provider component is used to wrap part of an application in a context, and
|
|
4073
|
-
* it can contain a default
|
|
4074
|
-
*
|
|
4075
|
-
*
|
|
4076
|
-
*
|
|
4077
|
-
*
|
|
4145
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
4146
|
+
* Id. The useResultTable hook lets you indicate which Queries object to get
|
|
4147
|
+
* data for: omit the final optional final parameter for the default context
|
|
4148
|
+
* Queries object, provide an Id for a named context Queries object, or provide
|
|
4149
|
+
* a Queries object explicitly by reference.
|
|
4078
4150
|
*
|
|
4079
4151
|
* When first rendered, this hook will create a listener so that changes to the
|
|
4080
|
-
*
|
|
4081
|
-
*
|
|
4152
|
+
* query result will cause a re-render. When the component containing this hook
|
|
4153
|
+
* is unmounted, the listener will be automatically removed.
|
|
4082
4154
|
*
|
|
4083
|
-
* @param
|
|
4084
|
-
*
|
|
4085
|
-
*
|
|
4086
|
-
*
|
|
4087
|
-
*
|
|
4155
|
+
* @param queryId The Id of the query.
|
|
4156
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
4157
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
4158
|
+
* object, or provide an explicit reference.
|
|
4159
|
+
* @returns An object containing the entire data of the result Table.
|
|
4088
4160
|
* @example
|
|
4089
|
-
* This example creates a
|
|
4090
|
-
*
|
|
4091
|
-
*
|
|
4161
|
+
* This example creates a Queries object outside the application, which is used
|
|
4162
|
+
* in the useTable hook by reference. A change to the data in the query
|
|
4163
|
+
* re-renders the component.
|
|
4092
4164
|
*
|
|
4093
4165
|
* ```jsx
|
|
4094
|
-
* const store = createStore().setTable('pets', {
|
|
4095
|
-
*
|
|
4166
|
+
* const store = createStore().setTable('pets', {
|
|
4167
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4168
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4169
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4170
|
+
* });
|
|
4171
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4172
|
+
* 'dogColors',
|
|
4173
|
+
* 'pets',
|
|
4174
|
+
* ({select, where}) => {
|
|
4175
|
+
* select('color');
|
|
4176
|
+
* where('species', 'dog');
|
|
4177
|
+
* },
|
|
4178
|
+
* );
|
|
4096
4179
|
* const App = () => (
|
|
4097
|
-
* <span>{JSON.stringify(
|
|
4180
|
+
* <span>{JSON.stringify(useResultTable('dogColors', queries))}</span>
|
|
4098
4181
|
* );
|
|
4099
4182
|
*
|
|
4100
4183
|
* const app = document.createElement('div');
|
|
4101
4184
|
* ReactDOM.render(<App />, app); // !act
|
|
4102
4185
|
* console.log(app.innerHTML);
|
|
4103
|
-
* // -> '<span>
|
|
4104
|
-
*
|
|
4105
|
-
* store.setCell('pets', 'fido', 'sold', true); // !act
|
|
4106
|
-
* console.log(app.innerHTML);
|
|
4107
|
-
* // -> '<span>[["0"],null,[]]</span>'
|
|
4186
|
+
* // -> '<span>{"fido":{"color":"brown"},"cujo":{"color":"black"}}</span>'
|
|
4108
4187
|
*
|
|
4109
|
-
*
|
|
4188
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
4110
4189
|
* console.log(app.innerHTML);
|
|
4111
|
-
* // -> '<span>
|
|
4190
|
+
* // -> '<span>{"fido":{"color":"walnut"},"cujo":{"color":"black"}}</span>'
|
|
4112
4191
|
* ```
|
|
4113
4192
|
* @example
|
|
4114
|
-
* This example creates a Provider context into which a default
|
|
4115
|
-
*
|
|
4116
|
-
* hook.
|
|
4193
|
+
* This example creates a Provider context into which a default Queries object
|
|
4194
|
+
* is provided. A component within it then uses the useResultTable hook.
|
|
4117
4195
|
*
|
|
4118
4196
|
* ```jsx
|
|
4119
|
-
* const App = ({
|
|
4120
|
-
* <Provider
|
|
4197
|
+
* const App = ({queries}) => (
|
|
4198
|
+
* <Provider queries={queries}>
|
|
4121
4199
|
* <Pane />
|
|
4122
4200
|
* </Provider>
|
|
4123
4201
|
* );
|
|
4124
|
-
* const Pane = () =>
|
|
4125
|
-
*
|
|
4126
|
-
* const checkpoints = createCheckpoints(
|
|
4127
|
-
* createStore().setTable('pets', {fido: {species: 'dog'}}),
|
|
4202
|
+
* const Pane = () => (
|
|
4203
|
+
* <span>{JSON.stringify(useResultTable('dogColors'))}</span>
|
|
4128
4204
|
* );
|
|
4129
4205
|
*
|
|
4206
|
+
* const queries = createQueries(
|
|
4207
|
+
* createStore().setTable('pets', {
|
|
4208
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4209
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4210
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4211
|
+
* }),
|
|
4212
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4213
|
+
* select('color');
|
|
4214
|
+
* where('species', 'dog');
|
|
4215
|
+
* });
|
|
4130
4216
|
* const app = document.createElement('div');
|
|
4131
|
-
* ReactDOM.render(<App
|
|
4217
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4132
4218
|
* console.log(app.innerHTML);
|
|
4133
|
-
* // -> '<span>
|
|
4219
|
+
* // -> '<span>{"fido":{"color":"brown"},"cujo":{"color":"black"}}</span>'
|
|
4134
4220
|
* ```
|
|
4135
4221
|
* @example
|
|
4136
|
-
* This example creates a Provider context into which a
|
|
4137
|
-
*
|
|
4222
|
+
* This example creates a Provider context into which a Queries object is
|
|
4223
|
+
* provided, named by Id. A component within it then uses the useResultTable
|
|
4138
4224
|
* hook.
|
|
4139
4225
|
*
|
|
4140
4226
|
* ```jsx
|
|
4141
|
-
* const App = ({
|
|
4142
|
-
* <Provider
|
|
4227
|
+
* const App = ({queries}) => (
|
|
4228
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
4143
4229
|
* <Pane />
|
|
4144
4230
|
* </Provider>
|
|
4145
4231
|
* );
|
|
4146
4232
|
* const Pane = () => (
|
|
4147
|
-
* <span>{JSON.stringify(
|
|
4148
|
-
* );
|
|
4149
|
-
*
|
|
4150
|
-
* const checkpoints = createCheckpoints(
|
|
4151
|
-
* createStore().setTable('pets', {fido: {species: 'dog'}}),
|
|
4233
|
+
* <span>{JSON.stringify(useResultTable('dogColors', 'petQueries'))}</span>
|
|
4152
4234
|
* );
|
|
4153
4235
|
*
|
|
4236
|
+
* const queries = createQueries(
|
|
4237
|
+
* createStore().setTable('pets', {
|
|
4238
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4239
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4240
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4241
|
+
* }),
|
|
4242
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4243
|
+
* select('color');
|
|
4244
|
+
* where('species', 'dog');
|
|
4245
|
+
* });
|
|
4154
4246
|
* const app = document.createElement('div');
|
|
4155
|
-
* ReactDOM.render(<App
|
|
4247
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4156
4248
|
* console.log(app.innerHTML);
|
|
4157
|
-
* // -> '<span>
|
|
4249
|
+
* // -> '<span>{"fido":{"color":"brown"},"cujo":{"color":"black"}}</span>'
|
|
4158
4250
|
* ```
|
|
4159
|
-
* @category
|
|
4251
|
+
* @category Queries hooks
|
|
4160
4252
|
*/
|
|
4161
|
-
export function
|
|
4162
|
-
|
|
4163
|
-
|
|
4253
|
+
export function useResultTable(
|
|
4254
|
+
queryId: Id,
|
|
4255
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4256
|
+
): Table;
|
|
4164
4257
|
|
|
4165
4258
|
/**
|
|
4166
|
-
* The
|
|
4167
|
-
* listener so that any changes to
|
|
4259
|
+
* The useResultRowIds hook returns the Ids of every Row in the result Table of
|
|
4260
|
+
* the given query, and registers a listener so that any changes to those Ids
|
|
4261
|
+
* will cause a re-render.
|
|
4168
4262
|
*
|
|
4169
4263
|
* A Provider component is used to wrap part of an application in a context, and
|
|
4170
|
-
* it can contain a default
|
|
4171
|
-
*
|
|
4172
|
-
*
|
|
4173
|
-
*
|
|
4174
|
-
*
|
|
4264
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
4265
|
+
* Id. The useResultRowIds hook lets you indicate which Queries object to get
|
|
4266
|
+
* data for: omit the final optional final parameter for the default context
|
|
4267
|
+
* Queries object, provide an Id for a named context Queries object, or provide
|
|
4268
|
+
* a Queries object explicitly by reference.
|
|
4175
4269
|
*
|
|
4176
4270
|
* When first rendered, this hook will create a listener so that changes to the
|
|
4177
|
-
*
|
|
4178
|
-
* unmounted, the listener will be automatically removed.
|
|
4271
|
+
* result Row Ids will cause a re-render. When the component containing this
|
|
4272
|
+
* hook is unmounted, the listener will be automatically removed.
|
|
4179
4273
|
*
|
|
4180
|
-
* @param
|
|
4181
|
-
* @param
|
|
4182
|
-
*
|
|
4183
|
-
*
|
|
4184
|
-
* @
|
|
4185
|
-
*
|
|
4274
|
+
* @param queryId The Id of the query.
|
|
4275
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
4276
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
4277
|
+
* object, or provide an explicit reference.
|
|
4278
|
+
* @param trackReorder An optional boolean that indicates that the listener
|
|
4279
|
+
* should be called if the set of Ids remains the same but their order changes.
|
|
4280
|
+
* See the addResultRowIdsListener method for more details.
|
|
4281
|
+
* @returns An array of the Ids of every Row in the result of the query.
|
|
4186
4282
|
* @example
|
|
4187
|
-
* This example creates a
|
|
4188
|
-
*
|
|
4283
|
+
* This example creates a Queries object outside the application, which is used
|
|
4284
|
+
* in the useResultRowIds hook by reference. A change to the data in the query
|
|
4189
4285
|
* re-renders the component.
|
|
4190
4286
|
*
|
|
4191
4287
|
* ```jsx
|
|
4192
|
-
* const store = createStore().setTable('pets', {
|
|
4193
|
-
*
|
|
4194
|
-
*
|
|
4288
|
+
* const store = createStore().setTable('pets', {
|
|
4289
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4290
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4291
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4292
|
+
* });
|
|
4293
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4294
|
+
* 'dogColors',
|
|
4295
|
+
* 'pets',
|
|
4296
|
+
* ({select, where}) => {
|
|
4297
|
+
* select('color');
|
|
4298
|
+
* where('species', 'dog');
|
|
4299
|
+
* },
|
|
4300
|
+
* );
|
|
4301
|
+
* const App = () => (
|
|
4302
|
+
* <span>{JSON.stringify(useResultRowIds('dogColors', queries))}</span>
|
|
4303
|
+
* );
|
|
4195
4304
|
*
|
|
4196
4305
|
* const app = document.createElement('div');
|
|
4197
4306
|
* ReactDOM.render(<App />, app); // !act
|
|
4198
4307
|
* console.log(app.innerHTML);
|
|
4199
|
-
* // -> '<span
|
|
4308
|
+
* // -> '<span>["fido","cujo"]</span>'
|
|
4200
4309
|
*
|
|
4201
|
-
* store.setCell('pets', '
|
|
4310
|
+
* store.setCell('pets', 'cujo', 'species', 'wolf'); // !act
|
|
4311
|
+
* console.log(app.innerHTML);
|
|
4312
|
+
* // -> '<span>["fido"]</span>'
|
|
4313
|
+
* ```
|
|
4314
|
+
* @example
|
|
4315
|
+
* This example creates a Provider context into which a default Queries object
|
|
4316
|
+
* is provided. A component within it then uses the useResultRowIds hook.
|
|
4317
|
+
*
|
|
4318
|
+
* ```jsx
|
|
4319
|
+
* const App = ({queries}) => (
|
|
4320
|
+
* <Provider queries={queries}>
|
|
4321
|
+
* <Pane />
|
|
4322
|
+
* </Provider>
|
|
4323
|
+
* );
|
|
4324
|
+
* const Pane = () => (
|
|
4325
|
+
* <span>{JSON.stringify(useResultRowIds('dogColors'))}</span>
|
|
4326
|
+
* );
|
|
4327
|
+
*
|
|
4328
|
+
* const queries = createQueries(
|
|
4329
|
+
* createStore().setTable('pets', {
|
|
4330
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4331
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4332
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4333
|
+
* }),
|
|
4334
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4335
|
+
* select('color');
|
|
4336
|
+
* where('species', 'dog');
|
|
4337
|
+
* });
|
|
4338
|
+
* const app = document.createElement('div');
|
|
4339
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4340
|
+
* console.log(app.innerHTML);
|
|
4341
|
+
* // -> '<span>["fido","cujo"]</span>'
|
|
4342
|
+
* ```
|
|
4343
|
+
* @example
|
|
4344
|
+
* This example creates a Provider context into which a Queries object is
|
|
4345
|
+
* provided, named by Id. A component within it then uses the useResultRowIds
|
|
4346
|
+
* hook.
|
|
4347
|
+
*
|
|
4348
|
+
* ```jsx
|
|
4349
|
+
* const App = ({queries}) => (
|
|
4350
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
4351
|
+
* <Pane />
|
|
4352
|
+
* </Provider>
|
|
4353
|
+
* );
|
|
4354
|
+
* const Pane = () => (
|
|
4355
|
+
* <span>{JSON.stringify(useResultRowIds('dogColors', 'petQueries'))}</span>
|
|
4356
|
+
* );
|
|
4357
|
+
*
|
|
4358
|
+
* const queries = createQueries(
|
|
4359
|
+
* createStore().setTable('pets', {
|
|
4360
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4361
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4362
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4363
|
+
* }),
|
|
4364
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4365
|
+
* select('color');
|
|
4366
|
+
* where('species', 'dog');
|
|
4367
|
+
* });
|
|
4368
|
+
* const app = document.createElement('div');
|
|
4369
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4370
|
+
* console.log(app.innerHTML);
|
|
4371
|
+
* // -> '<span>["fido","cujo"]</span>'
|
|
4372
|
+
* ```
|
|
4373
|
+
* @category Queries hooks
|
|
4374
|
+
*/
|
|
4375
|
+
export function useResultRowIds(
|
|
4376
|
+
queryId: Id,
|
|
4377
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4378
|
+
trackReorder?: boolean,
|
|
4379
|
+
): Ids;
|
|
4380
|
+
|
|
4381
|
+
/**
|
|
4382
|
+
* The useResultRow hook returns an object containing the entire data of a
|
|
4383
|
+
* single Row in the result Table of the given query, and registers a listener
|
|
4384
|
+
* so that any changes to that Row will cause a re-render.
|
|
4385
|
+
*
|
|
4386
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
4387
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
4388
|
+
* Id. The useResultRow hook lets you indicate which Queries object to get data
|
|
4389
|
+
* for: omit the final optional final parameter for the default context Queries
|
|
4390
|
+
* object, provide an Id for a named context Queries object, or provide a
|
|
4391
|
+
* Queries object explicitly by reference.
|
|
4392
|
+
*
|
|
4393
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
4394
|
+
* result Row will cause a re-render. When the component containing this hook is
|
|
4395
|
+
* unmounted, the listener will be automatically removed.
|
|
4396
|
+
*
|
|
4397
|
+
* @param queryId The Id of the query.
|
|
4398
|
+
* @param rowId The Id of the Row in the result Table.
|
|
4399
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
4400
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
4401
|
+
* object, or provide an explicit reference.
|
|
4402
|
+
* @returns An object containing the entire data of the Row in the result Table
|
|
4403
|
+
* of the query.
|
|
4404
|
+
* @example
|
|
4405
|
+
* This example creates a Queries object outside the application, which is used
|
|
4406
|
+
* in the useResultRow hook by reference. A change to the data in the query
|
|
4407
|
+
* re-renders the component.
|
|
4408
|
+
*
|
|
4409
|
+
* ```jsx
|
|
4410
|
+
* const store = createStore().setTable('pets', {
|
|
4411
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4412
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4413
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4414
|
+
* });
|
|
4415
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4416
|
+
* 'dogColors',
|
|
4417
|
+
* 'pets',
|
|
4418
|
+
* ({select, where}) => {
|
|
4419
|
+
* select('color');
|
|
4420
|
+
* where('species', 'dog');
|
|
4421
|
+
* },
|
|
4422
|
+
* );
|
|
4423
|
+
* const App = () => (
|
|
4424
|
+
* <span>{JSON.stringify(useResultRow('dogColors', 'fido', queries))}</span>
|
|
4425
|
+
* );
|
|
4426
|
+
*
|
|
4427
|
+
* const app = document.createElement('div');
|
|
4428
|
+
* ReactDOM.render(<App />, app); // !act
|
|
4429
|
+
* console.log(app.innerHTML);
|
|
4430
|
+
* // -> '<span>{"color":"brown"}</span>'
|
|
4431
|
+
*
|
|
4432
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
4433
|
+
* console.log(app.innerHTML);
|
|
4434
|
+
* // -> '<span>{"color":"walnut"}</span>'
|
|
4435
|
+
* ```
|
|
4436
|
+
* @example
|
|
4437
|
+
* This example creates a Provider context into which a default Queries object
|
|
4438
|
+
* is provided. A component within it then uses the useResultRow hook.
|
|
4439
|
+
*
|
|
4440
|
+
* ```jsx
|
|
4441
|
+
* const App = ({queries}) => (
|
|
4442
|
+
* <Provider queries={queries}>
|
|
4443
|
+
* <Pane />
|
|
4444
|
+
* </Provider>
|
|
4445
|
+
* );
|
|
4446
|
+
* const Pane = () => (
|
|
4447
|
+
* <span>{JSON.stringify(useResultRow('dogColors', 'fido'))}</span>
|
|
4448
|
+
* );
|
|
4449
|
+
*
|
|
4450
|
+
* const queries = createQueries(
|
|
4451
|
+
* createStore().setTable('pets', {
|
|
4452
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4453
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4454
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4455
|
+
* }),
|
|
4456
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4457
|
+
* select('color');
|
|
4458
|
+
* where('species', 'dog');
|
|
4459
|
+
* });
|
|
4460
|
+
* const app = document.createElement('div');
|
|
4461
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4462
|
+
* console.log(app.innerHTML);
|
|
4463
|
+
* // -> '<span>{"color":"brown"}</span>'
|
|
4464
|
+
* ```
|
|
4465
|
+
* @example
|
|
4466
|
+
* This example creates a Provider context into which a Queries object is
|
|
4467
|
+
* provided, named by Id. A component within it then uses the useResultRow
|
|
4468
|
+
* hook.
|
|
4469
|
+
*
|
|
4470
|
+
* ```jsx
|
|
4471
|
+
* const App = ({queries}) => (
|
|
4472
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
4473
|
+
* <Pane />
|
|
4474
|
+
* </Provider>
|
|
4475
|
+
* );
|
|
4476
|
+
* const Pane = () => (
|
|
4477
|
+
* <span>
|
|
4478
|
+
* {JSON.stringify(useResultRow('dogColors', 'fido', 'petQueries'))}
|
|
4479
|
+
* </span>
|
|
4480
|
+
* );
|
|
4481
|
+
*
|
|
4482
|
+
* const queries = createQueries(
|
|
4483
|
+
* createStore().setTable('pets', {
|
|
4484
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4485
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4486
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4487
|
+
* }),
|
|
4488
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4489
|
+
* select('color');
|
|
4490
|
+
* where('species', 'dog');
|
|
4491
|
+
* });
|
|
4492
|
+
* const app = document.createElement('div');
|
|
4493
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4494
|
+
* console.log(app.innerHTML);
|
|
4495
|
+
* // -> '<span>{"color":"brown"}</span>'
|
|
4496
|
+
* ```
|
|
4497
|
+
* @category Queries hooks
|
|
4498
|
+
*/
|
|
4499
|
+
export function useResultRow(
|
|
4500
|
+
queryId: Id,
|
|
4501
|
+
rowId: Id,
|
|
4502
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4503
|
+
): Row;
|
|
4504
|
+
|
|
4505
|
+
/**
|
|
4506
|
+
* The useResultCellIds hook returns the Ids of every Cell in a given Row in the
|
|
4507
|
+
* result Table of the given query, and registers a listener so that any changes
|
|
4508
|
+
* to those Ids will cause a re-render.
|
|
4509
|
+
*
|
|
4510
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
4511
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
4512
|
+
* Id. The useResultCellIds hook lets you indicate which Queries object to get
|
|
4513
|
+
* data for: omit the final optional final parameter for the default context
|
|
4514
|
+
* Queries object, provide an Id for a named context Queries object, or provide
|
|
4515
|
+
* a Queries object explicitly by reference.
|
|
4516
|
+
*
|
|
4517
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
4518
|
+
* result Cell Ids will cause a re-render. When the component containing this
|
|
4519
|
+
* hook is unmounted, the listener will be automatically removed.
|
|
4520
|
+
*
|
|
4521
|
+
* @param queryId The Id of the query.
|
|
4522
|
+
* @param rowId The Id of the Row in the result Table.
|
|
4523
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
4524
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
4525
|
+
* object, or provide an explicit reference.
|
|
4526
|
+
* @returns An array of the Ids of every Cell in the Row in the result of the
|
|
4527
|
+
* query.
|
|
4528
|
+
* @example
|
|
4529
|
+
* This example creates a Queries object outside the application, which is used
|
|
4530
|
+
* in the useResultCellIds hook by reference. A change to the data in the query
|
|
4531
|
+
* re-renders the component.
|
|
4532
|
+
*
|
|
4533
|
+
* ```jsx
|
|
4534
|
+
* const store = createStore().setTable('pets', {
|
|
4535
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4536
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4537
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4538
|
+
* });
|
|
4539
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4540
|
+
* 'dogColors',
|
|
4541
|
+
* 'pets',
|
|
4542
|
+
* ({select, where}) => {
|
|
4543
|
+
* select('species');
|
|
4544
|
+
* select('color');
|
|
4545
|
+
* select('legs');
|
|
4546
|
+
* where('species', 'dog');
|
|
4547
|
+
* },
|
|
4548
|
+
* );
|
|
4549
|
+
* const App = () => (
|
|
4550
|
+
* <span>
|
|
4551
|
+
* {JSON.stringify(useResultCellIds('dogColors', 'fido', queries))}
|
|
4552
|
+
* </span>
|
|
4553
|
+
* );
|
|
4554
|
+
*
|
|
4555
|
+
* const app = document.createElement('div');
|
|
4556
|
+
* ReactDOM.render(<App />, app); // !act
|
|
4557
|
+
* console.log(app.innerHTML);
|
|
4558
|
+
* // -> '<span>["species","color"]</span>'
|
|
4559
|
+
*
|
|
4560
|
+
* store.setCell('pets', 'fido', 'legs', 4); // !act
|
|
4561
|
+
* console.log(app.innerHTML);
|
|
4562
|
+
* // -> '<span>["species","color","legs"]</span>'
|
|
4563
|
+
* ```
|
|
4564
|
+
* @example
|
|
4565
|
+
* This example creates a Provider context into which a default Queries object
|
|
4566
|
+
* is provided. A component within it then uses the useResultCellIds hook.
|
|
4567
|
+
*
|
|
4568
|
+
* ```jsx
|
|
4569
|
+
* const App = ({queries}) => (
|
|
4570
|
+
* <Provider queries={queries}>
|
|
4571
|
+
* <Pane />
|
|
4572
|
+
* </Provider>
|
|
4573
|
+
* );
|
|
4574
|
+
* const Pane = () => (
|
|
4575
|
+
* <span>{JSON.stringify(useResultCellIds('dogColors', 'fido'))}</span>
|
|
4576
|
+
* );
|
|
4577
|
+
*
|
|
4578
|
+
* const queries = createQueries(
|
|
4579
|
+
* createStore().setTable('pets', {
|
|
4580
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4581
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4582
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4583
|
+
* }),
|
|
4584
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4585
|
+
* select('species');
|
|
4586
|
+
* select('color');
|
|
4587
|
+
* where('species', 'dog');
|
|
4588
|
+
* });
|
|
4589
|
+
* const app = document.createElement('div');
|
|
4590
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4591
|
+
* console.log(app.innerHTML);
|
|
4592
|
+
* // -> '<span>["species","color"]</span>'
|
|
4593
|
+
* ```
|
|
4594
|
+
* @example
|
|
4595
|
+
* This example creates a Provider context into which a Queries object is
|
|
4596
|
+
* provided, named by Id. A component within it then uses the useResultCellIds
|
|
4597
|
+
* hook.
|
|
4598
|
+
*
|
|
4599
|
+
* ```jsx
|
|
4600
|
+
* const App = ({queries}) => (
|
|
4601
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
4602
|
+
* <Pane />
|
|
4603
|
+
* </Provider>
|
|
4604
|
+
* );
|
|
4605
|
+
* const Pane = () => (
|
|
4606
|
+
* <span>
|
|
4607
|
+
* {JSON.stringify(useResultCellIds('dogColors', 'fido', 'petQueries'))}
|
|
4608
|
+
* </span>
|
|
4609
|
+
* );
|
|
4610
|
+
*
|
|
4611
|
+
* const queries = createQueries(
|
|
4612
|
+
* createStore().setTable('pets', {
|
|
4613
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4614
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4615
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4616
|
+
* }),
|
|
4617
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4618
|
+
* select('species');
|
|
4619
|
+
* select('color');
|
|
4620
|
+
* where('species', 'dog');
|
|
4621
|
+
* });
|
|
4622
|
+
* const app = document.createElement('div');
|
|
4623
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4624
|
+
* console.log(app.innerHTML);
|
|
4625
|
+
* // -> '<span>["species","color"]</span>'
|
|
4626
|
+
* ```
|
|
4627
|
+
* @category Queries hooks
|
|
4628
|
+
*/
|
|
4629
|
+
export function useResultCellIds(
|
|
4630
|
+
queryId: Id,
|
|
4631
|
+
rowId: Id,
|
|
4632
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4633
|
+
): Ids;
|
|
4634
|
+
|
|
4635
|
+
/**
|
|
4636
|
+
* The useResultCell hook returns the value of a single Cell in a given Row in
|
|
4637
|
+
* the result Table of the given query, and registers a listener so that any
|
|
4638
|
+
* changes to that value will cause a re-render.
|
|
4639
|
+
*
|
|
4640
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
4641
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
4642
|
+
* Id. The useResultCell hook lets you indicate which Queries object to get data
|
|
4643
|
+
* for: omit the final optional final parameter for the default context Queries
|
|
4644
|
+
* object, provide an Id for a named context Queries object, or provide a
|
|
4645
|
+
* Queries object explicitly by reference.
|
|
4646
|
+
*
|
|
4647
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
4648
|
+
* result Cell will cause a re-render. When the component containing this hook
|
|
4649
|
+
* is unmounted, the listener will be automatically removed.
|
|
4650
|
+
*
|
|
4651
|
+
* @param queryId The Id of the query.
|
|
4652
|
+
* @param rowId The Id of the Row in the result Table.
|
|
4653
|
+
* @param cellId The Id of the Cell in the Row.
|
|
4654
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
4655
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
4656
|
+
* object, or provide an explicit reference.
|
|
4657
|
+
* @returns The value of the Cell, or `undefined`.
|
|
4658
|
+
* @example
|
|
4659
|
+
* This example creates a Queries object outside the application, which is used
|
|
4660
|
+
* in the useResultCell hook by reference. A change to the data in the query
|
|
4661
|
+
* re-renders the component.
|
|
4662
|
+
*
|
|
4663
|
+
* ```jsx
|
|
4664
|
+
* const store = createStore().setTable('pets', {
|
|
4665
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4666
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4667
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4668
|
+
* });
|
|
4669
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4670
|
+
* 'dogColors',
|
|
4671
|
+
* 'pets',
|
|
4672
|
+
* ({select, where}) => {
|
|
4673
|
+
* select('species');
|
|
4674
|
+
* select('color');
|
|
4675
|
+
* select('legs');
|
|
4676
|
+
* where('species', 'dog');
|
|
4677
|
+
* },
|
|
4678
|
+
* );
|
|
4679
|
+
* const App = () => (
|
|
4680
|
+
* <span>{useResultCell('dogColors', 'fido', 'color', queries)}</span>
|
|
4681
|
+
* );
|
|
4682
|
+
*
|
|
4683
|
+
* const app = document.createElement('div');
|
|
4684
|
+
* ReactDOM.render(<App />, app); // !act
|
|
4685
|
+
* console.log(app.innerHTML);
|
|
4686
|
+
* // -> '<span>brown</span>'
|
|
4687
|
+
*
|
|
4688
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
4689
|
+
* console.log(app.innerHTML);
|
|
4690
|
+
* // -> '<span>walnut</span>'
|
|
4691
|
+
* ```
|
|
4692
|
+
* @example
|
|
4693
|
+
* This example creates a Provider context into which a default Queries object
|
|
4694
|
+
* is provided. A component within it then uses the useResultCell hook.
|
|
4695
|
+
*
|
|
4696
|
+
* ```jsx
|
|
4697
|
+
* const App = ({queries}) => (
|
|
4698
|
+
* <Provider queries={queries}>
|
|
4699
|
+
* <Pane />
|
|
4700
|
+
* </Provider>
|
|
4701
|
+
* );
|
|
4702
|
+
* const Pane = () => (
|
|
4703
|
+
* <span>{useResultCell('dogColors', 'fido', 'color')}</span>
|
|
4704
|
+
* );
|
|
4705
|
+
*
|
|
4706
|
+
* const queries = createQueries(
|
|
4707
|
+
* createStore().setTable('pets', {
|
|
4708
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4709
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4710
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4711
|
+
* }),
|
|
4712
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4713
|
+
* select('species');
|
|
4714
|
+
* select('color');
|
|
4715
|
+
* where('species', 'dog');
|
|
4716
|
+
* });
|
|
4717
|
+
* const app = document.createElement('div');
|
|
4718
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4719
|
+
* console.log(app.innerHTML);
|
|
4720
|
+
* // -> '<span>brown</span>'
|
|
4721
|
+
* ```
|
|
4722
|
+
* @example
|
|
4723
|
+
* This example creates a Provider context into which a Queries object is
|
|
4724
|
+
* provided, named by Id. A component within it then uses the useResultCell
|
|
4725
|
+
* hook.
|
|
4726
|
+
*
|
|
4727
|
+
* ```jsx
|
|
4728
|
+
* const App = ({queries}) => (
|
|
4729
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
4730
|
+
* <Pane />
|
|
4731
|
+
* </Provider>
|
|
4732
|
+
* );
|
|
4733
|
+
* const Pane = () => (
|
|
4734
|
+
* <span>{useResultCell('dogColors', 'fido', 'color', 'petQueries')}</span>
|
|
4735
|
+
* );
|
|
4736
|
+
*
|
|
4737
|
+
* const queries = createQueries(
|
|
4738
|
+
* createStore().setTable('pets', {
|
|
4739
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4740
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4741
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4742
|
+
* }),
|
|
4743
|
+
* ).setQueryDefinition('dogColors', 'pets', ({select, where}) => {
|
|
4744
|
+
* select('species');
|
|
4745
|
+
* select('color');
|
|
4746
|
+
* where('species', 'dog');
|
|
4747
|
+
* });
|
|
4748
|
+
* const app = document.createElement('div');
|
|
4749
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4750
|
+
* console.log(app.innerHTML);
|
|
4751
|
+
* // -> '<span>brown</span>'
|
|
4752
|
+
* ```
|
|
4753
|
+
* @category Queries hooks
|
|
4754
|
+
*/
|
|
4755
|
+
export function useResultCell(
|
|
4756
|
+
queryId: Id,
|
|
4757
|
+
rowId: Id,
|
|
4758
|
+
cellId: Id,
|
|
4759
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4760
|
+
): Cell | undefined;
|
|
4761
|
+
|
|
4762
|
+
/**
|
|
4763
|
+
* The useResultTableListener hook registers a listener function with a Queries
|
|
4764
|
+
* object that will be called whenever data in a result Table changes.
|
|
4765
|
+
*
|
|
4766
|
+
* This hook is useful for situations where a component needs to register its
|
|
4767
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
4768
|
+
* more easily done with the useResultTable hook).
|
|
4769
|
+
*
|
|
4770
|
+
* You can either listen to a single result Table (by specifying a query Id as
|
|
4771
|
+
* the method's first parameter) or changes to any result Table (by providing a
|
|
4772
|
+
* `null` wildcard).
|
|
4773
|
+
*
|
|
4774
|
+
* Unlike the addResultTableListener method, which returns a listener Id and
|
|
4775
|
+
* requires you to remove it manually, the useResultTableListener hook manages
|
|
4776
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
4777
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
4778
|
+
* Queries object will be deleted.
|
|
4779
|
+
*
|
|
4780
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
4781
|
+
* @param listener The function that will be called whenever data in the
|
|
4782
|
+
* matching result Table changes.
|
|
4783
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
4784
|
+
* function, which, if any change, result in the re-registration of the
|
|
4785
|
+
* listener. This parameter defaults to an empty array.
|
|
4786
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
4787
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
4788
|
+
* context Queries object, or provide an explicit reference.
|
|
4789
|
+
* @example
|
|
4790
|
+
* This example uses the useResultTableListener hook to create a listener that
|
|
4791
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
4792
|
+
* listener is removed from the Queries object.
|
|
4793
|
+
*
|
|
4794
|
+
* ```jsx
|
|
4795
|
+
* const App = ({queries}) => (
|
|
4796
|
+
* <Provider queries={queries}>
|
|
4797
|
+
* <Pane />
|
|
4798
|
+
* </Provider>
|
|
4799
|
+
* );
|
|
4800
|
+
* const Pane = () => {
|
|
4801
|
+
* useResultTableListener('petColors', () =>
|
|
4802
|
+
* console.log('Result table changed'),
|
|
4803
|
+
* );
|
|
4804
|
+
* return <span>App</span>;
|
|
4805
|
+
* };
|
|
4806
|
+
*
|
|
4807
|
+
* const store = createStore().setTable('pets', {
|
|
4808
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4809
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4810
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4811
|
+
* });
|
|
4812
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4813
|
+
* 'petColors',
|
|
4814
|
+
* 'pets',
|
|
4815
|
+
* ({select}) => select('color'),
|
|
4816
|
+
* );
|
|
4817
|
+
* const app = document.createElement('div');
|
|
4818
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4819
|
+
* console.log(queries.getListenerStats().table);
|
|
4820
|
+
* // -> 1
|
|
4821
|
+
*
|
|
4822
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
4823
|
+
* // -> 'Result table changed'
|
|
4824
|
+
*
|
|
4825
|
+
* ReactDOM.unmountComponentAtNode(app); // !act
|
|
4826
|
+
* console.log(queries.getListenerStats().table);
|
|
4827
|
+
* // -> 0
|
|
4828
|
+
* ```
|
|
4829
|
+
* @category Queries hooks
|
|
4830
|
+
*/
|
|
4831
|
+
export function useResultTableListener(
|
|
4832
|
+
queryId: IdOrNull,
|
|
4833
|
+
listener: ResultTableListener,
|
|
4834
|
+
listenerDeps?: React.DependencyList,
|
|
4835
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4836
|
+
): void;
|
|
4837
|
+
|
|
4838
|
+
/**
|
|
4839
|
+
* The useResultRowIdsListener hook registers a listener function with a Queries
|
|
4840
|
+
* object that will be called whenever the Row Ids in a result Table change.
|
|
4841
|
+
*
|
|
4842
|
+
* This hook is useful for situations where a component needs to register its
|
|
4843
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
4844
|
+
* more easily done with the useResultRowIds hook).
|
|
4845
|
+
*
|
|
4846
|
+
* You can either listen to a single result Table (by specifying a query Id as
|
|
4847
|
+
* the method's first parameter) or changes to any result Table (by providing a
|
|
4848
|
+
* `null` wildcard).
|
|
4849
|
+
*
|
|
4850
|
+
* Unlike the addResultRowIdsListener method, which returns a listener Id and
|
|
4851
|
+
* requires you to remove it manually, the useResultRowIdsListener hook manages
|
|
4852
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
4853
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
4854
|
+
* Queries object will be deleted.
|
|
4855
|
+
*
|
|
4856
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
4857
|
+
* @param listener The function that will be called whenever the Row Ids in the
|
|
4858
|
+
* matching result Table change.
|
|
4859
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
4860
|
+
* function, which, if any change, result in the re-registration of the
|
|
4861
|
+
* listener. This parameter defaults to an empty array.
|
|
4862
|
+
* @param trackReorder An optional boolean that indicates that the listener
|
|
4863
|
+
* should be called if the set of Ids remains the same but their order changes.
|
|
4864
|
+
* See the addResultRowIdsListener method for more details.
|
|
4865
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
4866
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
4867
|
+
* context Queries object, or provide an explicit reference.
|
|
4868
|
+
* @example
|
|
4869
|
+
* This example uses the useResultRowIdsListener hook to create a listener that
|
|
4870
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
4871
|
+
* listener is removed from the Queries object.
|
|
4872
|
+
*
|
|
4873
|
+
* ```jsx
|
|
4874
|
+
* const App = ({queries}) => (
|
|
4875
|
+
* <Provider queries={queries}>
|
|
4876
|
+
* <Pane />
|
|
4877
|
+
* </Provider>
|
|
4878
|
+
* );
|
|
4879
|
+
* const Pane = () => {
|
|
4880
|
+
* useResultRowIdsListener('petColors', () =>
|
|
4881
|
+
* console.log('Result row Ids changed'),
|
|
4882
|
+
* );
|
|
4883
|
+
* return <span>App</span>;
|
|
4884
|
+
* };
|
|
4885
|
+
*
|
|
4886
|
+
* const store = createStore().setTable('pets', {
|
|
4887
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4888
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4889
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4890
|
+
* });
|
|
4891
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4892
|
+
* 'petColors',
|
|
4893
|
+
* 'pets',
|
|
4894
|
+
* ({select}) => select('color'),
|
|
4895
|
+
* );
|
|
4896
|
+
* const app = document.createElement('div');
|
|
4897
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4898
|
+
* console.log(queries.getListenerStats().rowIds);
|
|
4899
|
+
* // -> 1
|
|
4900
|
+
*
|
|
4901
|
+
* store.setRow('pets', 'rex', {species: 'dog', color: 'tan'}); // !act
|
|
4902
|
+
* // -> 'Result row Ids changed'
|
|
4903
|
+
*
|
|
4904
|
+
* ReactDOM.unmountComponentAtNode(app); // !act
|
|
4905
|
+
* console.log(queries.getListenerStats().rowIds);
|
|
4906
|
+
* // -> 0
|
|
4907
|
+
* ```
|
|
4908
|
+
* @category Queries hooks
|
|
4909
|
+
*/
|
|
4910
|
+
export function useResultRowIdsListener(
|
|
4911
|
+
queryId: IdOrNull,
|
|
4912
|
+
listener: ResultRowIdsListener,
|
|
4913
|
+
listenerDeps?: React.DependencyList,
|
|
4914
|
+
trackReorder?: boolean,
|
|
4915
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4916
|
+
): void;
|
|
4917
|
+
|
|
4918
|
+
/**
|
|
4919
|
+
* The useResultRowListener hook registers a listener function with a Queries
|
|
4920
|
+
* object that will be called whenever data in a result Row changes.
|
|
4921
|
+
*
|
|
4922
|
+
* This hook is useful for situations where a component needs to register its
|
|
4923
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
4924
|
+
* more easily done with the useResultRow hook).
|
|
4925
|
+
*
|
|
4926
|
+
* You can either listen to a single result Row (by specifying a query Id and
|
|
4927
|
+
* Row Id as the method's first two parameters) or changes to any result Row (by
|
|
4928
|
+
* providing `null` wildcards).
|
|
4929
|
+
*
|
|
4930
|
+
* Both, either, or neither of the `queryId` and `rowId` parameters can be
|
|
4931
|
+
* wildcarded with `null`. You can listen to a specific result Row in a specific
|
|
4932
|
+
* query, any result Row in a specific query, a specific result Row in any
|
|
4933
|
+
* query, or any result Row in any query.
|
|
4934
|
+
*
|
|
4935
|
+
* Unlike the addResultRowListener method, which returns a listener Id and
|
|
4936
|
+
* requires you to remove it manually, the useResultRowListener hook manages
|
|
4937
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
4938
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
4939
|
+
* Queries object will be deleted.
|
|
4940
|
+
*
|
|
4941
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
4942
|
+
* @param rowId The Id of the result Row to listen to, or `null` as a wildcard.
|
|
4943
|
+
* @param listener The function that will be called whenever data in the
|
|
4944
|
+
* matching result Row changes.
|
|
4945
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
4946
|
+
* function, which, if any change, result in the re-registration of the
|
|
4947
|
+
* listener. This parameter defaults to an empty array.
|
|
4948
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
4949
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
4950
|
+
* context Queries object, or provide an explicit reference.
|
|
4951
|
+
* @example
|
|
4952
|
+
* This example uses the useResultRowListener hook to create a listener that
|
|
4953
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
4954
|
+
* listener is removed from the Queries object.
|
|
4955
|
+
*
|
|
4956
|
+
* ```jsx
|
|
4957
|
+
* const App = ({queries}) => (
|
|
4958
|
+
* <Provider queries={queries}>
|
|
4959
|
+
* <Pane />
|
|
4960
|
+
* </Provider>
|
|
4961
|
+
* );
|
|
4962
|
+
* const Pane = () => {
|
|
4963
|
+
* useResultRowListener('petColors', 'fido', () =>
|
|
4964
|
+
* console.log('Result row changed'),
|
|
4965
|
+
* );
|
|
4966
|
+
* return <span>App</span>;
|
|
4967
|
+
* };
|
|
4968
|
+
*
|
|
4969
|
+
* const store = createStore().setTable('pets', {
|
|
4970
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
4971
|
+
* felix: {species: 'cat', color: 'black'},
|
|
4972
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
4973
|
+
* });
|
|
4974
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
4975
|
+
* 'petColors',
|
|
4976
|
+
* 'pets',
|
|
4977
|
+
* ({select}) => select('color'),
|
|
4978
|
+
* );
|
|
4979
|
+
* const app = document.createElement('div');
|
|
4980
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
4981
|
+
* console.log(queries.getListenerStats().row);
|
|
4982
|
+
* // -> 1
|
|
4983
|
+
*
|
|
4984
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
4985
|
+
* // -> 'Result row changed'
|
|
4986
|
+
*
|
|
4987
|
+
* ReactDOM.unmountComponentAtNode(app); // !act
|
|
4988
|
+
* console.log(queries.getListenerStats().row);
|
|
4989
|
+
* // -> 0
|
|
4990
|
+
* ```
|
|
4991
|
+
* @category Queries hooks
|
|
4992
|
+
*/
|
|
4993
|
+
export function useResultRowListener(
|
|
4994
|
+
queryId: IdOrNull,
|
|
4995
|
+
rowId: IdOrNull,
|
|
4996
|
+
listener: ResultRowListener,
|
|
4997
|
+
listenerDeps?: React.DependencyList,
|
|
4998
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
4999
|
+
): void;
|
|
5000
|
+
|
|
5001
|
+
/**
|
|
5002
|
+
* The useResultCellIdsListener hook registers a listener function with a
|
|
5003
|
+
* Queries object that will be called whenever the Cell Ids in a result Row
|
|
5004
|
+
* change.
|
|
5005
|
+
*
|
|
5006
|
+
* This hook is useful for situations where a component needs to register its
|
|
5007
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
5008
|
+
* more easily done with the useResultCellIds hook).
|
|
5009
|
+
*
|
|
5010
|
+
* Both, either, or neither of the `queryId` and `rowId` parameters can be
|
|
5011
|
+
* wildcarded with `null`. You can listen to a specific result Row in a specific
|
|
5012
|
+
* query, any result Row in a specific query, a specific result Row in any
|
|
5013
|
+
* query, or any result Row in any query.
|
|
5014
|
+
*
|
|
5015
|
+
* Unlike the addResultCellIdsListener method, which returns a listener Id and
|
|
5016
|
+
* requires you to remove it manually, the useResultCellIdsListener hook manages
|
|
5017
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
5018
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
5019
|
+
* Queries object will be deleted.
|
|
5020
|
+
*
|
|
5021
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
5022
|
+
* @param rowId The Id of the result Row to listen to, or `null` as a wildcard.
|
|
5023
|
+
* @param listener The function that will be called whenever the Row Ids in the
|
|
5024
|
+
* matching result Table change.
|
|
5025
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
5026
|
+
* function, which, if any change, result in the re-registration of the
|
|
5027
|
+
* listener. This parameter defaults to an empty array.
|
|
5028
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
5029
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
5030
|
+
* context Queries object, or provide an explicit reference.
|
|
5031
|
+
* @example
|
|
5032
|
+
* This example uses the useResultCellIdsListener hook to create a listener that
|
|
5033
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
5034
|
+
* listener is removed from the Queries object.
|
|
5035
|
+
*
|
|
5036
|
+
* ```jsx
|
|
5037
|
+
* const App = ({queries}) => (
|
|
5038
|
+
* <Provider queries={queries}>
|
|
5039
|
+
* <Pane />
|
|
5040
|
+
* </Provider>
|
|
5041
|
+
* );
|
|
5042
|
+
* const Pane = () => {
|
|
5043
|
+
* useResultCellIdsListener('petColors', 'fido', () =>
|
|
5044
|
+
* console.log('Result cell Ids changed'),
|
|
5045
|
+
* );
|
|
5046
|
+
* return <span>App</span>;
|
|
5047
|
+
* };
|
|
5048
|
+
*
|
|
5049
|
+
* const store = createStore().setTable('pets', {
|
|
5050
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
5051
|
+
* felix: {species: 'cat', color: 'black'},
|
|
5052
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
5053
|
+
* });
|
|
5054
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
5055
|
+
* 'petColors',
|
|
5056
|
+
* 'pets',
|
|
5057
|
+
* ({select, where}) => {
|
|
5058
|
+
* select('color');
|
|
5059
|
+
* select('legs');
|
|
5060
|
+
* },
|
|
5061
|
+
* );
|
|
5062
|
+
* const app = document.createElement('div');
|
|
5063
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
5064
|
+
* console.log(queries.getListenerStats().cellIds);
|
|
5065
|
+
* // -> 1
|
|
5066
|
+
*
|
|
5067
|
+
* store.setCell('pets', 'fido', 'legs', 4); // !act
|
|
5068
|
+
* // -> 'Result cell Ids changed'
|
|
5069
|
+
*
|
|
5070
|
+
* ReactDOM.unmountComponentAtNode(app); // !act
|
|
5071
|
+
* console.log(queries.getListenerStats().cellIds);
|
|
5072
|
+
* // -> 0
|
|
5073
|
+
* ```
|
|
5074
|
+
* @category Queries hooks
|
|
5075
|
+
*/
|
|
5076
|
+
export function useResultCellIdsListener(
|
|
5077
|
+
queryId: IdOrNull,
|
|
5078
|
+
rowId: IdOrNull,
|
|
5079
|
+
listener: ResultCellIdsListener,
|
|
5080
|
+
listenerDeps?: React.DependencyList,
|
|
5081
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
5082
|
+
): void;
|
|
5083
|
+
|
|
5084
|
+
/**
|
|
5085
|
+
* The useResultCellListener hook registers a listener function with a Queries
|
|
5086
|
+
* object that will be called whenever data in a Cell changes.
|
|
5087
|
+
*
|
|
5088
|
+
* This hook is useful for situations where a component needs to register its
|
|
5089
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
5090
|
+
* more easily done with the useResultCell hook).
|
|
5091
|
+
*
|
|
5092
|
+
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
5093
|
+
* and Cell Id as the method's first three parameters) or changes to any Cell
|
|
5094
|
+
* (by providing `null` wildcards).
|
|
5095
|
+
*
|
|
5096
|
+
* All, some, or none of the `queryId`, `rowId`, and `cellId` parameters can be
|
|
5097
|
+
* wildcarded with `null`. You can listen to a specific Cell in a specific
|
|
5098
|
+
* result Row in a specific query, any Cell in any result Row in any query, for
|
|
5099
|
+
* example - or every other combination of wildcards.
|
|
5100
|
+
*
|
|
5101
|
+
* Unlike the addResultCellListener method, which returns a listener Id and
|
|
5102
|
+
* requires you to remove it manually, the useResultCellListener hook manages
|
|
5103
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
5104
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
5105
|
+
* Queries object will be deleted.
|
|
5106
|
+
*
|
|
5107
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
5108
|
+
* @param rowId The Id of the result Row to listen to, or `null` as a wildcard.
|
|
5109
|
+
* @param cellId The Id of the result Cell to listen to, or `null` as a
|
|
5110
|
+
* wildcard.
|
|
5111
|
+
* @param listener The function that will be called whenever data in the
|
|
5112
|
+
* matching result Cell changes.
|
|
5113
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
5114
|
+
* function, which, if any change, result in the re-registration of the
|
|
5115
|
+
* listener. This parameter defaults to an empty array.
|
|
5116
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
5117
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
5118
|
+
* context Queries object, or provide an explicit reference.
|
|
5119
|
+
* @example
|
|
5120
|
+
* This example uses the useResultCellListener hook to create a listener that
|
|
5121
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
5122
|
+
* listener is removed from the Queries object.
|
|
5123
|
+
*
|
|
5124
|
+
* ```jsx
|
|
5125
|
+
* const App = ({queries}) => (
|
|
5126
|
+
* <Provider queries={queries}>
|
|
5127
|
+
* <Pane />
|
|
5128
|
+
* </Provider>
|
|
5129
|
+
* );
|
|
5130
|
+
* const Pane = () => {
|
|
5131
|
+
* useResultCellListener('petColors', 'fido', 'color', () =>
|
|
5132
|
+
* console.log('Result cell changed'),
|
|
5133
|
+
* );
|
|
5134
|
+
* return <span>App</span>;
|
|
5135
|
+
* };
|
|
5136
|
+
*
|
|
5137
|
+
* const store = createStore().setTable('pets', {
|
|
5138
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
5139
|
+
* felix: {species: 'cat', color: 'black'},
|
|
5140
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
5141
|
+
* });
|
|
5142
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
5143
|
+
* 'petColors',
|
|
5144
|
+
* 'pets',
|
|
5145
|
+
* ({select}) => select('color'),
|
|
5146
|
+
* );
|
|
5147
|
+
* const app = document.createElement('div');
|
|
5148
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
5149
|
+
* console.log(queries.getListenerStats().cell);
|
|
5150
|
+
* // -> 1
|
|
5151
|
+
*
|
|
5152
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
5153
|
+
* // -> 'Result cell changed'
|
|
5154
|
+
*
|
|
5155
|
+
* ReactDOM.unmountComponentAtNode(app); // !act
|
|
5156
|
+
* console.log(queries.getListenerStats().cell);
|
|
5157
|
+
* // -> 0
|
|
5158
|
+
* ```
|
|
5159
|
+
* @category Queries hooks
|
|
5160
|
+
*/
|
|
5161
|
+
export function useResultCellListener(
|
|
5162
|
+
queryId: IdOrNull,
|
|
5163
|
+
rowId: IdOrNull,
|
|
5164
|
+
cellId: IdOrNull,
|
|
5165
|
+
listener: ResultCellListener,
|
|
5166
|
+
listenerDeps?: React.DependencyList,
|
|
5167
|
+
queriesOrQueriesId?: QueriesOrQueriesId,
|
|
5168
|
+
): void;
|
|
5169
|
+
|
|
5170
|
+
/**
|
|
5171
|
+
* The useCreateCheckpoints hook is used to create a Checkpoints object within a
|
|
5172
|
+
* React application with convenient memoization.
|
|
5173
|
+
*
|
|
5174
|
+
* It is possible to create a Checkpoints object outside of the React app with
|
|
5175
|
+
* the regular createCheckpoints function and pass it in, but you may prefer to
|
|
5176
|
+
* create it within the app, perhaps inside the top-level component. To defend
|
|
5177
|
+
* against a new Checkpoints object being created every time the app renders or
|
|
5178
|
+
* re-renders, the useCreateCheckpoints hook wraps the creation in a
|
|
5179
|
+
* memoization.
|
|
5180
|
+
*
|
|
5181
|
+
* The useCreateCheckpoints hook is a very thin wrapper around the React
|
|
5182
|
+
* `useMemo` hook, defaulting to the provided Store as its dependency, so that
|
|
5183
|
+
* by default, the creation only occurs once per Store.
|
|
5184
|
+
*
|
|
5185
|
+
* If your `create` function contains other dependencies, the changing of which
|
|
5186
|
+
* should also cause the Checkpoints object to be recreated, you can provide
|
|
5187
|
+
* them in an array in the optional second parameter, just as you would for any
|
|
5188
|
+
* React hook with dependencies.
|
|
5189
|
+
*
|
|
5190
|
+
* This hook ensures the Checkpoints object is destroyed whenever a new one is
|
|
5191
|
+
* created or the component is unmounted.
|
|
5192
|
+
*
|
|
5193
|
+
* @param store A reference to the Store for which to create a new Checkpoints
|
|
5194
|
+
* object.
|
|
5195
|
+
* @param create A function for performing the creation steps of the Checkpoints
|
|
5196
|
+
* object for the Store, plus any additional steps such as adding definitions or
|
|
5197
|
+
* listeners, and returning it.
|
|
5198
|
+
* @param createDeps An optional array of dependencies for the `create`
|
|
5199
|
+
* function, which, if any change, result in its rerun. This parameter defaults
|
|
5200
|
+
* to an empty array.
|
|
5201
|
+
* @returns A reference to the Checkpoints object.
|
|
5202
|
+
* @example
|
|
5203
|
+
* This example creates a Checkpoints object at the top level of a React
|
|
5204
|
+
* application. Even though the App component is rendered twice, the
|
|
5205
|
+
* Checkpoints object creation only occurs once by default.
|
|
5206
|
+
*
|
|
5207
|
+
* ```jsx
|
|
5208
|
+
* const App = () => {
|
|
5209
|
+
* const store = useCreateStore(createStore);
|
|
5210
|
+
* const checkpoints = useCreateCheckpoints(store, (store) => {
|
|
5211
|
+
* console.log('Checkpoints created');
|
|
5212
|
+
* return createCheckpoints(store).setSize(10);
|
|
5213
|
+
* });
|
|
5214
|
+
* return <span>{JSON.stringify(checkpoints.getCheckpointIds())}</span>;
|
|
5215
|
+
* };
|
|
5216
|
+
*
|
|
5217
|
+
* const app = document.createElement('div');
|
|
5218
|
+
* ReactDOM.render(<App />, app); // !act
|
|
5219
|
+
* // -> 'Checkpoints created'
|
|
5220
|
+
*
|
|
5221
|
+
* ReactDOM.render(<App />, app); // !act
|
|
5222
|
+
* // No second Checkpoints creation
|
|
5223
|
+
*
|
|
5224
|
+
* console.log(app.innerHTML);
|
|
5225
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
5226
|
+
* ```
|
|
5227
|
+
* @example
|
|
5228
|
+
* This example creates a Checkpoints object at the top level of a React
|
|
5229
|
+
* application. The App component is rendered twice, each with a different
|
|
5230
|
+
* top-level prop. The useCreateCheckpoints hook takes the size prop as a
|
|
5231
|
+
* dependency, and so the Checkpoints object is created again on the second
|
|
5232
|
+
* render.
|
|
5233
|
+
*
|
|
5234
|
+
* ```jsx
|
|
5235
|
+
* const App = ({size}) => {
|
|
5236
|
+
* const store = useCreateStore(createStore);
|
|
5237
|
+
* const checkpoints = useCreateCheckpoints(
|
|
5238
|
+
* store,
|
|
5239
|
+
* (store) => {
|
|
5240
|
+
* console.log(`Checkpoints created, size ${size}`);
|
|
5241
|
+
* return createCheckpoints(store).setSize(size);
|
|
5242
|
+
* },
|
|
5243
|
+
* [size],
|
|
5244
|
+
* );
|
|
5245
|
+
* return <span>{JSON.stringify(checkpoints.getCheckpointIds())}</span>;
|
|
5246
|
+
* };
|
|
5247
|
+
*
|
|
5248
|
+
* const app = document.createElement('div');
|
|
5249
|
+
* ReactDOM.render(<App size={20} />, app); // !act
|
|
5250
|
+
* // -> 'Checkpoints created, size 20'
|
|
5251
|
+
*
|
|
5252
|
+
* console.log(app.innerHTML);
|
|
5253
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
5254
|
+
*
|
|
5255
|
+
* ReactDOM.render(<App size={50} />, app); // !act
|
|
5256
|
+
* // -> 'Checkpoints created, size 50'
|
|
5257
|
+
*
|
|
5258
|
+
* console.log(app.innerHTML);
|
|
5259
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
5260
|
+
* ```
|
|
5261
|
+
* @category Checkpoints hooks
|
|
5262
|
+
*/
|
|
5263
|
+
export function useCreateCheckpoints(
|
|
5264
|
+
store: Store,
|
|
5265
|
+
create: (store: Store) => Checkpoints,
|
|
5266
|
+
createDeps?: React.DependencyList,
|
|
5267
|
+
): Checkpoints;
|
|
5268
|
+
|
|
5269
|
+
/**
|
|
5270
|
+
* The useCheckpoints hook is used to get a reference to a Checkpoints object
|
|
5271
|
+
* from within a Provider component context.
|
|
5272
|
+
*
|
|
5273
|
+
* A Provider component is used to wrap part of an application in a context. It
|
|
5274
|
+
* can contain a default Checkpoints object (or a set of Checkpoints objects
|
|
5275
|
+
* named by Id) that can be easily accessed without having to be passed down as
|
|
5276
|
+
* props through every component.
|
|
5277
|
+
*
|
|
5278
|
+
* The useCheckpoints hook lets you either get a reference to the default
|
|
5279
|
+
* Checkpoints object (when called without an parameter), or one of the
|
|
5280
|
+
* Checkpoints objects that are named by Id (when called with an Id parameter).
|
|
5281
|
+
*
|
|
5282
|
+
* @param id An optional Id for accessing a Checkpoints object that was named
|
|
5283
|
+
* with an Id in the Provider.
|
|
5284
|
+
* @returns A reference to the Checkpoints object (or `undefined` if not within
|
|
5285
|
+
* a Provider context, or if the requested Checkpoints object does not exist)
|
|
5286
|
+
* @example
|
|
5287
|
+
* This example creates a Provider context into which a default Checkpoint
|
|
5288
|
+
* object is provided. A component within it then uses the useCheckpoints hook
|
|
5289
|
+
* to get a reference to the Checkpoints object again, without the need to have
|
|
5290
|
+
* it passed as a prop.
|
|
5291
|
+
*
|
|
5292
|
+
* ```jsx
|
|
5293
|
+
* const App = ({checkpoints}) => (
|
|
5294
|
+
* <Provider checkpoints={checkpoints}>
|
|
5295
|
+
* <Pane />
|
|
5296
|
+
* </Provider>
|
|
5297
|
+
* );
|
|
5298
|
+
* const Pane = () => (
|
|
5299
|
+
* <span>{useCheckpoints().getListenerStats().checkpointIds}</span>
|
|
5300
|
+
* );
|
|
5301
|
+
*
|
|
5302
|
+
* const checkpoints = createCheckpoints(createStore());
|
|
5303
|
+
* const app = document.createElement('div');
|
|
5304
|
+
* ReactDOM.render(<App checkpoints={checkpoints} />, app); // !act
|
|
5305
|
+
* console.log(app.innerHTML);
|
|
5306
|
+
* // -> '<span>0</span>'
|
|
5307
|
+
* ```
|
|
5308
|
+
* @example
|
|
5309
|
+
* This example creates a Provider context into which a Checkpoints object is
|
|
5310
|
+
* provided, named by Id. A component within it then uses the useCheckpoints
|
|
5311
|
+
* hook with that Id to get a reference to the Checkpoints object again, without
|
|
5312
|
+
* the need to have it passed as a prop.
|
|
5313
|
+
*
|
|
5314
|
+
* ```jsx
|
|
5315
|
+
* const App = ({checkpoints}) => (
|
|
5316
|
+
* <Provider checkpointsById={{petStore: checkpoints}}>
|
|
5317
|
+
* <Pane />
|
|
5318
|
+
* </Provider>
|
|
5319
|
+
* );
|
|
5320
|
+
* const Pane = () => (
|
|
5321
|
+
* <span>
|
|
5322
|
+
* {useCheckpoints('petStore').getListenerStats().checkpointIds}
|
|
5323
|
+
* </span>
|
|
5324
|
+
* );
|
|
5325
|
+
*
|
|
5326
|
+
* const checkpoints = createCheckpoints(createStore());
|
|
5327
|
+
* const app = document.createElement('div');
|
|
5328
|
+
* ReactDOM.render(<App checkpoints={checkpoints} />, app); // !act
|
|
5329
|
+
* console.log(app.innerHTML);
|
|
5330
|
+
* // -> '<span>0</span>'
|
|
5331
|
+
* ```
|
|
5332
|
+
* @category Checkpoints hooks
|
|
5333
|
+
*/
|
|
5334
|
+
export function useCheckpoints(id?: Id): Checkpoints | undefined;
|
|
5335
|
+
|
|
5336
|
+
/**
|
|
5337
|
+
* The useCheckpointIds hook returns an array of the checkpoint Ids being
|
|
5338
|
+
* managed by this Checkpoints object, and registers a listener so that any
|
|
5339
|
+
* changes to that result will cause a re-render.
|
|
5340
|
+
*
|
|
5341
|
+
*
|
|
5342
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
5343
|
+
* it can contain a default Checkpoints object or a set of Checkpoints objects
|
|
5344
|
+
* named by Id. The useCheckpointIds hook lets you indicate which Checkpoints
|
|
5345
|
+
* object to get data for: omit the optional parameter for the default context
|
|
5346
|
+
* Checkpoints object, provide an Id for a named context Checkpoints object, or
|
|
5347
|
+
* provide a Checkpoints object explicitly by reference.
|
|
5348
|
+
*
|
|
5349
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
5350
|
+
* checkpoint Ids will cause a re-render. When the component containing this
|
|
5351
|
+
* hook is unmounted, the listener will be automatically removed.
|
|
5352
|
+
*
|
|
5353
|
+
* @param checkpointsOrCheckpointsId The Checkpoints object to be accessed: omit
|
|
5354
|
+
* for the default context Checkpoints object, provide an Id for a named context
|
|
5355
|
+
* Checkpoints object, or provide an explicit reference.
|
|
5356
|
+
* @returns A CheckpointIds array, containing the checkpoint Ids managed by this
|
|
5357
|
+
* Checkpoints object.
|
|
5358
|
+
* @example
|
|
5359
|
+
* This example creates a Checkpoints object outside the application, which is
|
|
5360
|
+
* used in the useCheckpointIds hook by reference. A change to the checkpoint
|
|
5361
|
+
* Ids re-renders the component.
|
|
5362
|
+
*
|
|
5363
|
+
* ```jsx
|
|
5364
|
+
* const store = createStore().setTable('pets', {fido: {species: 'dog'}});
|
|
5365
|
+
* const checkpoints = createCheckpoints(store);
|
|
5366
|
+
* const App = () => (
|
|
5367
|
+
* <span>{JSON.stringify(useCheckpointIds(checkpoints))}</span>
|
|
5368
|
+
* );
|
|
5369
|
+
*
|
|
5370
|
+
* const app = document.createElement('div');
|
|
5371
|
+
* ReactDOM.render(<App />, app); // !act
|
|
5372
|
+
* console.log(app.innerHTML);
|
|
5373
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
5374
|
+
*
|
|
5375
|
+
* store.setCell('pets', 'fido', 'sold', true); // !act
|
|
5376
|
+
* console.log(app.innerHTML);
|
|
5377
|
+
* // -> '<span>[["0"],null,[]]</span>'
|
|
5378
|
+
*
|
|
5379
|
+
* checkpoints.addCheckpoint('sale'); // !act
|
|
5380
|
+
* console.log(app.innerHTML);
|
|
5381
|
+
* // -> '<span>[["0"],"1",[]]</span>'
|
|
5382
|
+
* ```
|
|
5383
|
+
* @example
|
|
5384
|
+
* This example creates a Provider context into which a default Checkpoints
|
|
5385
|
+
* object is provided. A component within it then uses the useCheckpointIds
|
|
5386
|
+
* hook.
|
|
5387
|
+
*
|
|
5388
|
+
* ```jsx
|
|
5389
|
+
* const App = ({checkpoints}) => (
|
|
5390
|
+
* <Provider checkpoints={checkpoints}>
|
|
5391
|
+
* <Pane />
|
|
5392
|
+
* </Provider>
|
|
5393
|
+
* );
|
|
5394
|
+
* const Pane = () => <span>{JSON.stringify(useCheckpointIds())}</span>;
|
|
5395
|
+
*
|
|
5396
|
+
* const checkpoints = createCheckpoints(
|
|
5397
|
+
* createStore().setTable('pets', {fido: {species: 'dog'}}),
|
|
5398
|
+
* );
|
|
5399
|
+
*
|
|
5400
|
+
* const app = document.createElement('div');
|
|
5401
|
+
* ReactDOM.render(<App checkpoints={checkpoints} />, app); // !act
|
|
5402
|
+
* console.log(app.innerHTML);
|
|
5403
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
5404
|
+
* ```
|
|
5405
|
+
* @example
|
|
5406
|
+
* This example creates a Provider context into which a default Checkpoints
|
|
5407
|
+
* object is provided. A component within it then uses the useCheckpointIds
|
|
5408
|
+
* hook.
|
|
5409
|
+
*
|
|
5410
|
+
* ```jsx
|
|
5411
|
+
* const App = ({checkpoints}) => (
|
|
5412
|
+
* <Provider checkpointsById={{petCheckpoints: checkpoints}}>
|
|
5413
|
+
* <Pane />
|
|
5414
|
+
* </Provider>
|
|
5415
|
+
* );
|
|
5416
|
+
* const Pane = () => (
|
|
5417
|
+
* <span>{JSON.stringify(useCheckpointIds('petCheckpoints'))}</span>
|
|
5418
|
+
* );
|
|
5419
|
+
*
|
|
5420
|
+
* const checkpoints = createCheckpoints(
|
|
5421
|
+
* createStore().setTable('pets', {fido: {species: 'dog'}}),
|
|
5422
|
+
* );
|
|
5423
|
+
*
|
|
5424
|
+
* const app = document.createElement('div');
|
|
5425
|
+
* ReactDOM.render(<App checkpoints={checkpoints} />, app); // !act
|
|
5426
|
+
* console.log(app.innerHTML);
|
|
5427
|
+
* // -> '<span>[[],"0",[]]</span>'
|
|
5428
|
+
* ```
|
|
5429
|
+
* @category Checkpoints hooks
|
|
5430
|
+
*/
|
|
5431
|
+
export function useCheckpointIds(
|
|
5432
|
+
checkpointsOrCheckpointsId?: CheckpointsOrCheckpointsId,
|
|
5433
|
+
): CheckpointIds;
|
|
5434
|
+
|
|
5435
|
+
/**
|
|
5436
|
+
* The useCheckpoint hook returns the label for a checkpoint, and registers a
|
|
5437
|
+
* listener so that any changes to that result will cause a re-render.
|
|
5438
|
+
*
|
|
5439
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
5440
|
+
* it can contain a default Checkpoints object or a set of Checkpoints objects
|
|
5441
|
+
* named by Id. The useCheckpoint hook lets you indicate which Checkpoints
|
|
5442
|
+
* object to get data for: omit the optional final parameter for the default
|
|
5443
|
+
* context Checkpoints object, provide an Id for a named context Checkpoints
|
|
5444
|
+
* object, or provide a Checkpoints object explicitly by reference.
|
|
5445
|
+
*
|
|
5446
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
5447
|
+
* label will cause a re-render. When the component containing this hook is
|
|
5448
|
+
* unmounted, the listener will be automatically removed.
|
|
5449
|
+
*
|
|
5450
|
+
* @param checkpointId The Id of the checkpoint.
|
|
5451
|
+
* @param checkpointsOrCheckpointsId The Checkpoints object to be accessed: omit
|
|
5452
|
+
* for the default context Checkpoints object, provide an Id for a named context
|
|
5453
|
+
* Checkpoints object, or provide an explicit reference.
|
|
5454
|
+
* @returns A string label for the requested checkpoint, an empty string if it
|
|
5455
|
+
* was never set, or `undefined` if the checkpoint does not exist.
|
|
5456
|
+
* @example
|
|
5457
|
+
* This example creates a Checkpoints object outside the application, which is
|
|
5458
|
+
* used in the useCheckpoint hook by reference. A change to the checkpoint label
|
|
5459
|
+
* re-renders the component.
|
|
5460
|
+
*
|
|
5461
|
+
* ```jsx
|
|
5462
|
+
* const store = createStore().setTable('pets', {fido: {species: 'dog'}});
|
|
5463
|
+
* const checkpoints = createCheckpoints(store);
|
|
5464
|
+
* const App = () => <span>{useCheckpoint('1', checkpoints)}</span>;
|
|
5465
|
+
*
|
|
5466
|
+
* const app = document.createElement('div');
|
|
5467
|
+
* ReactDOM.render(<App />, app); // !act
|
|
5468
|
+
* console.log(app.innerHTML);
|
|
5469
|
+
* // -> '<span></span>'
|
|
5470
|
+
*
|
|
5471
|
+
* store.setCell('pets', 'fido', 'sold', true); // !act
|
|
4202
5472
|
* checkpoints.addCheckpoint('sale'); // !act
|
|
4203
5473
|
* console.log(app.innerHTML);
|
|
4204
5474
|
* // -> '<span>sale</span>'
|
|
@@ -4898,6 +6168,12 @@ export type TablesProps = {
|
|
|
4898
6168
|
* for a named context Store, or provide an explicit reference.
|
|
4899
6169
|
*/
|
|
4900
6170
|
readonly store?: StoreOrStoreId;
|
|
6171
|
+
/**
|
|
6172
|
+
* An optional boolean that indicates that the component should re-render if
|
|
6173
|
+
* the set of Table Ids in the Store remains the same but their order changes.
|
|
6174
|
+
* See the addTableIdsListener method for more details.
|
|
6175
|
+
*/
|
|
6176
|
+
readonly trackReorder?: boolean;
|
|
4901
6177
|
/**
|
|
4902
6178
|
* A component for rendering each Table in the Store (to override the default
|
|
4903
6179
|
* TableView component).
|
|
@@ -4935,6 +6211,12 @@ export type TableProps = {
|
|
|
4935
6211
|
* for a named context Store, or provide an explicit reference.
|
|
4936
6212
|
*/
|
|
4937
6213
|
readonly store?: StoreOrStoreId;
|
|
6214
|
+
/**
|
|
6215
|
+
* An optional boolean that indicates that the component should re-render if
|
|
6216
|
+
* the set of Row Ids in the Table remains the same but their order changes.
|
|
6217
|
+
* See the addRowIdsListener method for more details.
|
|
6218
|
+
*/
|
|
6219
|
+
readonly trackReorder?: boolean;
|
|
4938
6220
|
/**
|
|
4939
6221
|
* A custom component for rendering each Row in the Table (to override the
|
|
4940
6222
|
* default RowView component).
|
|
@@ -4976,6 +6258,12 @@ export type RowProps = {
|
|
|
4976
6258
|
* for a named context Store, or provide an explicit reference.
|
|
4977
6259
|
*/
|
|
4978
6260
|
readonly store?: StoreOrStoreId;
|
|
6261
|
+
/**
|
|
6262
|
+
* An optional boolean that indicates that the component should re-render if
|
|
6263
|
+
* the set of Cell Ids remains the same but their order changes. See the
|
|
6264
|
+
* addCellIdsListener method for more details.
|
|
6265
|
+
*/
|
|
6266
|
+
readonly trackReorder?: boolean;
|
|
4979
6267
|
/**
|
|
4980
6268
|
* A custom component for rendering each Cell in the Row (to override the
|
|
4981
6269
|
* default CellView component).
|
|
@@ -5220,38 +6508,159 @@ export type LocalRowsProps = {
|
|
|
5220
6508
|
*
|
|
5221
6509
|
* @category Props
|
|
5222
6510
|
*/
|
|
5223
|
-
export type LinkedRowsProps = {
|
|
5224
|
-
/**
|
|
5225
|
-
* The Id of the Relationship in the Relationships object.
|
|
5226
|
-
*/
|
|
5227
|
-
readonly relationshipId: Id;
|
|
6511
|
+
export type LinkedRowsProps = {
|
|
6512
|
+
/**
|
|
6513
|
+
* The Id of the Relationship in the Relationships object.
|
|
6514
|
+
*/
|
|
6515
|
+
readonly relationshipId: Id;
|
|
6516
|
+
/**
|
|
6517
|
+
* The Id of the first Row in the linked list Relationship.
|
|
6518
|
+
*/
|
|
6519
|
+
readonly firstRowId: Id;
|
|
6520
|
+
/**
|
|
6521
|
+
* The Relationships object to be accessed: omit for the default context
|
|
6522
|
+
* Relationships object, provide an Id for a named context Relationships
|
|
6523
|
+
* object, or provide an explicit reference.
|
|
6524
|
+
*/
|
|
6525
|
+
readonly relationships?: RelationshipsOrRelationshipsId;
|
|
6526
|
+
/**
|
|
6527
|
+
* A component for rendering each (remote, local, or linked) Row in the
|
|
6528
|
+
* Relationship.
|
|
6529
|
+
*/
|
|
6530
|
+
readonly rowComponent?: ComponentType<RowProps>;
|
|
6531
|
+
/**
|
|
6532
|
+
* A function for generating extra props for each Row component based on its
|
|
6533
|
+
* Id.
|
|
6534
|
+
*/
|
|
6535
|
+
readonly getRowComponentProps?: (rowId: Id) => ExtraProps;
|
|
6536
|
+
/**
|
|
6537
|
+
* A component or string to separate each Row component.
|
|
6538
|
+
*/
|
|
6539
|
+
readonly separator?: ReactElement | string;
|
|
6540
|
+
/**
|
|
6541
|
+
* Whether the component should also render the Id of the Row in the
|
|
6542
|
+
* Relationship, and its descendent objects, to assist with debugging.
|
|
6543
|
+
*/
|
|
6544
|
+
readonly debugIds?: boolean;
|
|
6545
|
+
};
|
|
6546
|
+
|
|
6547
|
+
/**
|
|
6548
|
+
* ResultTableProps props are used for components that refer to a single query
|
|
6549
|
+
* result Table, such as the ResultTableView component.
|
|
6550
|
+
*
|
|
6551
|
+
* @category Props
|
|
6552
|
+
*/
|
|
6553
|
+
export type ResultTableProps = {
|
|
6554
|
+
/**
|
|
6555
|
+
* The Id of the query in the Queries object for which the result Table will
|
|
6556
|
+
* be rendered.
|
|
6557
|
+
*/
|
|
6558
|
+
readonly queryId: Id;
|
|
6559
|
+
/**
|
|
6560
|
+
* The Queries object to be accessed: omit for the default context Queries
|
|
6561
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
6562
|
+
* explicit reference.
|
|
6563
|
+
*/
|
|
6564
|
+
readonly queries?: QueriesOrQueriesId;
|
|
6565
|
+
/**
|
|
6566
|
+
* An optional boolean that indicates that the component should re-render if
|
|
6567
|
+
* the set of Row Ids in the result Table remains the same but their order
|
|
6568
|
+
* changes. See the addResultRowIdsListener method for more details.
|
|
6569
|
+
*/
|
|
6570
|
+
readonly trackReorder?: boolean;
|
|
6571
|
+
/**
|
|
6572
|
+
* A custom component for rendering each Row in the Table (to override the
|
|
6573
|
+
* default ResultRowView component).
|
|
6574
|
+
*/
|
|
6575
|
+
readonly resultRowComponent?: ComponentType<ResultRowProps>;
|
|
6576
|
+
/**
|
|
6577
|
+
* A function for generating extra props for each custom Row component based
|
|
6578
|
+
* on its Id.
|
|
6579
|
+
*/
|
|
6580
|
+
readonly getResultRowComponentProps?: (rowId: Id) => ExtraProps;
|
|
6581
|
+
/**
|
|
6582
|
+
* A component or string to separate each Row component.
|
|
6583
|
+
*/
|
|
6584
|
+
readonly separator?: ReactElement | string;
|
|
6585
|
+
/**
|
|
6586
|
+
* Whether the component should also render the Id of the query, and its
|
|
6587
|
+
* descendent objects, to assist with debugging.
|
|
6588
|
+
*/
|
|
6589
|
+
readonly debugIds?: boolean;
|
|
6590
|
+
};
|
|
6591
|
+
|
|
6592
|
+
/**
|
|
6593
|
+
* ResultRowProps props are used for components that refer to a single Row in a
|
|
6594
|
+
* query result Table, such as the ResultRowView component.
|
|
6595
|
+
*
|
|
6596
|
+
* @category Props
|
|
6597
|
+
*/
|
|
6598
|
+
export type ResultRowProps = {
|
|
6599
|
+
/**
|
|
6600
|
+
* The Id of the query in the Queries object for which the result Table will
|
|
6601
|
+
* be rendered.
|
|
6602
|
+
*/
|
|
6603
|
+
readonly queryId: Id;
|
|
6604
|
+
/**
|
|
6605
|
+
* The Id of the Row in the result Table to be rendered.
|
|
6606
|
+
*/
|
|
6607
|
+
readonly rowId: Id;
|
|
6608
|
+
/**
|
|
6609
|
+
* The Queries object to be accessed: omit for the default context Queries
|
|
6610
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
6611
|
+
* explicit reference.
|
|
6612
|
+
*/
|
|
6613
|
+
readonly queries?: QueriesOrQueriesId;
|
|
6614
|
+
/**
|
|
6615
|
+
* A custom component for rendering each Cell in the Row (to override the
|
|
6616
|
+
* default CellView component).
|
|
6617
|
+
*/
|
|
6618
|
+
readonly resultCellComponent?: ComponentType<ResultCellProps>;
|
|
6619
|
+
/**
|
|
6620
|
+
* A function for generating extra props for each custom Cell component based
|
|
6621
|
+
* on its Id.
|
|
6622
|
+
*/
|
|
6623
|
+
readonly getResultCellComponentProps?: (cellId: Id) => ExtraProps;
|
|
6624
|
+
/**
|
|
6625
|
+
* A component or string to separate each Cell component.
|
|
6626
|
+
*/
|
|
6627
|
+
readonly separator?: ReactElement | string;
|
|
6628
|
+
/**
|
|
6629
|
+
* Whether the component should also render the Id of the Row, and its
|
|
6630
|
+
* descendent objects, to assist with debugging.
|
|
6631
|
+
*/
|
|
6632
|
+
readonly debugIds?: boolean;
|
|
6633
|
+
};
|
|
6634
|
+
|
|
6635
|
+
/**
|
|
6636
|
+
* ResultRowProps props are used for components that refer to a single Cell in a
|
|
6637
|
+
* Row of a result Table, such as the ResultCellView component.
|
|
6638
|
+
*
|
|
6639
|
+
* @category Props
|
|
6640
|
+
*/
|
|
6641
|
+
export type ResultCellProps = {
|
|
5228
6642
|
/**
|
|
5229
|
-
* The Id of the
|
|
5230
|
-
|
|
5231
|
-
readonly firstRowId: Id;
|
|
5232
|
-
/**
|
|
5233
|
-
* The Relationships object to be accessed: omit for the default context
|
|
5234
|
-
* Relationships object, provide an Id for a named context Relationships
|
|
5235
|
-
* object, or provide an explicit reference.
|
|
6643
|
+
* The Id of the query in the Queries object for which the result Table will
|
|
6644
|
+
* be rendered.
|
|
5236
6645
|
*/
|
|
5237
|
-
readonly
|
|
6646
|
+
readonly queryId: Id;
|
|
5238
6647
|
/**
|
|
5239
|
-
*
|
|
5240
|
-
* Relationship.
|
|
6648
|
+
* The Id of the Row in the Table.
|
|
5241
6649
|
*/
|
|
5242
|
-
readonly
|
|
6650
|
+
readonly rowId: Id;
|
|
5243
6651
|
/**
|
|
5244
|
-
*
|
|
5245
|
-
* Id.
|
|
6652
|
+
* The Id of the Cell in the Row to be rendered.
|
|
5246
6653
|
*/
|
|
5247
|
-
readonly
|
|
6654
|
+
readonly cellId: Id;
|
|
5248
6655
|
/**
|
|
5249
|
-
*
|
|
6656
|
+
* The Queries object to be accessed: omit for the default context Queries
|
|
6657
|
+
* object, provide an Id for a named context Queries object, or provide an
|
|
6658
|
+
* explicit reference.
|
|
5250
6659
|
*/
|
|
5251
|
-
readonly
|
|
6660
|
+
readonly queries?: QueriesOrQueriesId;
|
|
5252
6661
|
/**
|
|
5253
|
-
* Whether the component should also render the Id of the
|
|
5254
|
-
*
|
|
6662
|
+
* Whether the component should also render the Id of the Cell to assist with
|
|
6663
|
+
* debugging.
|
|
5255
6664
|
*/
|
|
5256
6665
|
readonly debugIds?: boolean;
|
|
5257
6666
|
};
|
|
@@ -5430,6 +6839,16 @@ export type ProviderProps = {
|
|
|
5430
6839
|
* within the Provider context by their Id.
|
|
5431
6840
|
*/
|
|
5432
6841
|
readonly relationshipsById?: {[relationshipsId: Id]: Relationships};
|
|
6842
|
+
/**
|
|
6843
|
+
* A default single Queries object that will be available within the Provider
|
|
6844
|
+
* context.
|
|
6845
|
+
*/
|
|
6846
|
+
readonly queries?: Queries;
|
|
6847
|
+
/**
|
|
6848
|
+
* An object containing multiple Queries objects that will be available within
|
|
6849
|
+
* the Provider context by their Id.
|
|
6850
|
+
*/
|
|
6851
|
+
readonly queriesById?: {[queriesId: Id]: Queries};
|
|
5433
6852
|
/**
|
|
5434
6853
|
* A default single Checkpoints object that will be available within the
|
|
5435
6854
|
* Provider context.
|
|
@@ -6727,6 +8146,396 @@ export function LocalRowsView(props: LocalRowsProps): ComponentReturnType;
|
|
|
6727
8146
|
*/
|
|
6728
8147
|
export function LinkedRowsView(props: LinkedRowsProps): ComponentReturnType;
|
|
6729
8148
|
|
|
8149
|
+
/**
|
|
8150
|
+
* The ResultCellView component renders the value of a single Cell in a given
|
|
8151
|
+
* Row, in a given query's result Table, and registers a listener so that any
|
|
8152
|
+
* changes to that result will cause a re-render.
|
|
8153
|
+
*
|
|
8154
|
+
* The component's props identify which Cell to render based on query Id, Row
|
|
8155
|
+
* Id, Cell Id, and Queries object (which is either the default context Queries
|
|
8156
|
+
* object, a named context Queries object, or an explicit reference).
|
|
8157
|
+
*
|
|
8158
|
+
* A Cell contains a string, number, or boolean, so the value is rendered
|
|
8159
|
+
* directly without further decoration. You can create your own
|
|
8160
|
+
* ResultCellView-like component to customize the way that a Cell is rendered:
|
|
8161
|
+
* see the ResultRowView component for more details.
|
|
8162
|
+
*
|
|
8163
|
+
* This component uses the useResultCell hook under the covers, which means that
|
|
8164
|
+
* any changes to the specified Cell will cause a re-render.
|
|
8165
|
+
*
|
|
8166
|
+
* @param props The props for this component.
|
|
8167
|
+
* @returns A rendering of the result Cell, or nothing, if not present.
|
|
8168
|
+
* @example
|
|
8169
|
+
* This example creates a Queries object outside the application, which is used
|
|
8170
|
+
* in the ResultCellView component by reference. A change to the data in the
|
|
8171
|
+
* Store re-renders the component.
|
|
8172
|
+
*
|
|
8173
|
+
* ```jsx
|
|
8174
|
+
* const store = createStore().setTable('pets', {
|
|
8175
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8176
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8177
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
8178
|
+
* });
|
|
8179
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
8180
|
+
* 'petColors',
|
|
8181
|
+
* 'pets',
|
|
8182
|
+
* ({select}) => select('color'),
|
|
8183
|
+
* );
|
|
8184
|
+
* const App = () => (
|
|
8185
|
+
* <span>
|
|
8186
|
+
* <ResultCellView
|
|
8187
|
+
* queryId="petColors"
|
|
8188
|
+
* rowId="fido"
|
|
8189
|
+
* cellId="color"
|
|
8190
|
+
* queries={queries}
|
|
8191
|
+
* />
|
|
8192
|
+
* </span>
|
|
8193
|
+
* );
|
|
8194
|
+
*
|
|
8195
|
+
* const app = document.createElement('div');
|
|
8196
|
+
* ReactDOM.render(<App />, app); // !act
|
|
8197
|
+
* console.log(app.innerHTML);
|
|
8198
|
+
* // -> '<span>brown</span>'
|
|
8199
|
+
*
|
|
8200
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
8201
|
+
* console.log(app.innerHTML);
|
|
8202
|
+
* // -> '<span>walnut</span>'
|
|
8203
|
+
* ```
|
|
8204
|
+
* @example
|
|
8205
|
+
* This example creates a Provider context into which a default Queries object
|
|
8206
|
+
* is provided. The ResultCellView component within it then renders the Cell
|
|
8207
|
+
* (with its Id for readability).
|
|
8208
|
+
*
|
|
8209
|
+
* ```jsx
|
|
8210
|
+
* const App = ({queries}) => (
|
|
8211
|
+
* <Provider queries={queries}>
|
|
8212
|
+
* <Pane />
|
|
8213
|
+
* </Provider>
|
|
8214
|
+
* );
|
|
8215
|
+
* const Pane = () => (
|
|
8216
|
+
* <span>
|
|
8217
|
+
* <ResultCellView
|
|
8218
|
+
* queryId="petColors"
|
|
8219
|
+
* rowId="fido"
|
|
8220
|
+
* cellId="color"
|
|
8221
|
+
* debugIds={true}
|
|
8222
|
+
* />
|
|
8223
|
+
* </span>
|
|
8224
|
+
* );
|
|
8225
|
+
*
|
|
8226
|
+
* const queries = createQueries(
|
|
8227
|
+
* createStore().setTable('pets', {
|
|
8228
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8229
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8230
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
8231
|
+
* }),
|
|
8232
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
8233
|
+
* const app = document.createElement('div');
|
|
8234
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
8235
|
+
* console.log(app.innerHTML);
|
|
8236
|
+
* // -> '<span>color:{brown}</span>'
|
|
8237
|
+
* ```
|
|
8238
|
+
* @example
|
|
8239
|
+
* This example creates a Provider context into which a default Queries object
|
|
8240
|
+
* is provided. The ResultCellView component within it then attempts to render a
|
|
8241
|
+
* non-existent Cell.
|
|
8242
|
+
*
|
|
8243
|
+
* ```jsx
|
|
8244
|
+
* const App = ({queries}) => (
|
|
8245
|
+
* <Provider queries={queries}>
|
|
8246
|
+
* <Pane />
|
|
8247
|
+
* </Provider>
|
|
8248
|
+
* );
|
|
8249
|
+
* const Pane = () => (
|
|
8250
|
+
* <span>
|
|
8251
|
+
* <ResultCellView queryId="petColors" rowId="fido" cellId="height" />
|
|
8252
|
+
* </span>
|
|
8253
|
+
* );
|
|
8254
|
+
*
|
|
8255
|
+
* const queries = createQueries(
|
|
8256
|
+
* createStore().setTable('pets', {
|
|
8257
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8258
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8259
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
8260
|
+
* }),
|
|
8261
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
8262
|
+
* const app = document.createElement('div');
|
|
8263
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
8264
|
+
* console.log(app.innerHTML);
|
|
8265
|
+
* // -> '<span></span>'
|
|
8266
|
+
* ```
|
|
8267
|
+
* @category Queries components
|
|
8268
|
+
*/
|
|
8269
|
+
export function ResultCellView(props: ResultCellProps): ComponentReturnType;
|
|
8270
|
+
|
|
8271
|
+
/**
|
|
8272
|
+
* The ResultRowView component renders the contents of a single Row in a given
|
|
8273
|
+
* query's result Table, and registers a listener so that any changes to that
|
|
8274
|
+
* result will cause a re-render.
|
|
8275
|
+
*
|
|
8276
|
+
* The component's props identify which Row to render based on query Id, Row Id,
|
|
8277
|
+
* and Queries object (which is either the default context Queries object, a
|
|
8278
|
+
* named context Queries object, or an explicit reference).
|
|
8279
|
+
*
|
|
8280
|
+
* This component renders a Row by iterating over its Cell values. By default
|
|
8281
|
+
* these are in turn rendered with the ResultCellView component, but you can
|
|
8282
|
+
* override this behavior by providing a `resultCellComponent` prop, a custom
|
|
8283
|
+
* component of your own that will render a Cell based on ResultCellProps. You
|
|
8284
|
+
* can also pass additional props to your custom component with the
|
|
8285
|
+
* `getResultCellComponentProps` callback prop.
|
|
8286
|
+
*
|
|
8287
|
+
* You can create your own ResultRowView-like component to customize the way
|
|
8288
|
+
* that a result Row is rendered: see the ResultTableView component for more
|
|
8289
|
+
* details.
|
|
8290
|
+
*
|
|
8291
|
+
* This component uses the useResultCellIds hook under the covers, which means
|
|
8292
|
+
* that any changes to the structure of the result Row will cause a re-render.
|
|
8293
|
+
*
|
|
8294
|
+
* @param props The props for this component.
|
|
8295
|
+
* @returns A rendering of the result Row, or nothing, if not present.
|
|
8296
|
+
* @example
|
|
8297
|
+
* This example creates a Queries object outside the application, which is used
|
|
8298
|
+
* in the ResultRowView component by reference. A change to the data in the
|
|
8299
|
+
* Store re-renders the component.
|
|
8300
|
+
*
|
|
8301
|
+
* ```jsx
|
|
8302
|
+
* const store = createStore().setTable('pets', {
|
|
8303
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8304
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8305
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
8306
|
+
* });
|
|
8307
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
8308
|
+
* 'petColors',
|
|
8309
|
+
* 'pets',
|
|
8310
|
+
* ({select}) => {
|
|
8311
|
+
* select('species');
|
|
8312
|
+
* select('color');
|
|
8313
|
+
* },
|
|
8314
|
+
* );
|
|
8315
|
+
* const App = () => (
|
|
8316
|
+
* <div>
|
|
8317
|
+
* <ResultRowView
|
|
8318
|
+
* queryId="petColors"
|
|
8319
|
+
* rowId="fido"
|
|
8320
|
+
* queries={queries}
|
|
8321
|
+
* separator="/"
|
|
8322
|
+
* />
|
|
8323
|
+
* </div>
|
|
8324
|
+
* );
|
|
8325
|
+
*
|
|
8326
|
+
* const app = document.createElement('div');
|
|
8327
|
+
* ReactDOM.render(<App />, app); // !act
|
|
8328
|
+
* console.log(app.innerHTML);
|
|
8329
|
+
* // -> '<div>dog/brown</div>'
|
|
8330
|
+
*
|
|
8331
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
8332
|
+
* console.log(app.innerHTML);
|
|
8333
|
+
* // -> '<div>dog/walnut</div>'
|
|
8334
|
+
* ```
|
|
8335
|
+
* @example
|
|
8336
|
+
* This example creates a Provider context into which a default Queries object
|
|
8337
|
+
* is provided. The ResultRowView component within it then renders the Row (with
|
|
8338
|
+
* Ids for readability).
|
|
8339
|
+
*
|
|
8340
|
+
* ```jsx
|
|
8341
|
+
* const App = ({queries}) => (
|
|
8342
|
+
* <Provider queries={queries}>
|
|
8343
|
+
* <Pane />
|
|
8344
|
+
* </Provider>
|
|
8345
|
+
* );
|
|
8346
|
+
* const Pane = () => (
|
|
8347
|
+
* <div>
|
|
8348
|
+
* <ResultRowView queryId="petColors" rowId="fido" debugIds={true} />
|
|
8349
|
+
* </div>
|
|
8350
|
+
* );
|
|
8351
|
+
*
|
|
8352
|
+
* const queries = createQueries(
|
|
8353
|
+
* createStore().setTable('pets', {
|
|
8354
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8355
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8356
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
8357
|
+
* }),
|
|
8358
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => {
|
|
8359
|
+
* select('species');
|
|
8360
|
+
* select('color');
|
|
8361
|
+
* });
|
|
8362
|
+
* const app = document.createElement('div');
|
|
8363
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
8364
|
+
* console.log(app.innerHTML);
|
|
8365
|
+
* // -> '<div>fido:{species:{dog}color:{brown}}</div>'
|
|
8366
|
+
* ```
|
|
8367
|
+
* @example
|
|
8368
|
+
* This example creates a Provider context into which a default Queries object
|
|
8369
|
+
* is provided. The ResultRowView component within it then renders the Row with
|
|
8370
|
+
* a custom Cell component and a custom props callback.
|
|
8371
|
+
*
|
|
8372
|
+
* ```jsx
|
|
8373
|
+
* const App = ({queries}) => (
|
|
8374
|
+
* <Provider queries={queries}>
|
|
8375
|
+
* <Pane />
|
|
8376
|
+
* </Provider>
|
|
8377
|
+
* );
|
|
8378
|
+
* const Pane = () => (
|
|
8379
|
+
* <div>
|
|
8380
|
+
* <ResultRowView
|
|
8381
|
+
* queryId="petColors"
|
|
8382
|
+
* rowId="fido"
|
|
8383
|
+
* resultCellComponent={FormattedResultCellView}
|
|
8384
|
+
* getResultCellComponentProps={(cellId) => ({
|
|
8385
|
+
* bold: cellId == 'species',
|
|
8386
|
+
* })}
|
|
8387
|
+
* />
|
|
8388
|
+
* </div>
|
|
8389
|
+
* );
|
|
8390
|
+
* const FormattedResultCellView = ({queryId, rowId, cellId, bold}) => (
|
|
8391
|
+
* <span>
|
|
8392
|
+
* {bold ? <b>{cellId}</b> : cellId}
|
|
8393
|
+
* {': '}
|
|
8394
|
+
* <ResultCellView queryId={queryId} rowId={rowId} cellId={cellId} />
|
|
8395
|
+
* </span>
|
|
8396
|
+
* );
|
|
8397
|
+
*
|
|
8398
|
+
* const queries = createQueries(
|
|
8399
|
+
* createStore().setTable('pets', {
|
|
8400
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8401
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8402
|
+
* cujo: {species: 'dog', color: 'black'},
|
|
8403
|
+
* }),
|
|
8404
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => {
|
|
8405
|
+
* select('species');
|
|
8406
|
+
* select('color');
|
|
8407
|
+
* });
|
|
8408
|
+
* const app = document.createElement('div');
|
|
8409
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
8410
|
+
* console.log(app.innerHTML);
|
|
8411
|
+
* // -> '<div><span><b>species</b>: dog</span><span>color: brown</span></div>'
|
|
8412
|
+
* ```
|
|
8413
|
+
* @category Queries components
|
|
8414
|
+
*/
|
|
8415
|
+
export function ResultRowView(props: ResultRowProps): ComponentReturnType;
|
|
8416
|
+
|
|
8417
|
+
/**
|
|
8418
|
+
* The ResultTableView component renders the contents of a single query's result
|
|
8419
|
+
* Table in a Queries object, and registers a listener so that any changes to
|
|
8420
|
+
* that result will cause a re-render.
|
|
8421
|
+
*
|
|
8422
|
+
* The component's props identify which Table to render based on query Id, and
|
|
8423
|
+
* Queries object (which is either the default context Queries object, a named
|
|
8424
|
+
* context Queries object, or by explicit reference).
|
|
8425
|
+
*
|
|
8426
|
+
* This component renders a result Table by iterating over its Row objects. By
|
|
8427
|
+
* default these are in turn rendered with the ResultRowView component, but you
|
|
8428
|
+
* can override this behavior by providing a `resultRowComponent` prop, a custom
|
|
8429
|
+
* component of your own that will render a Row based on ResultRowProps. You can
|
|
8430
|
+
* also pass additional props to your custom component with the
|
|
8431
|
+
* `getResultRowComponentProps` callback prop.
|
|
8432
|
+
*
|
|
8433
|
+
* This component uses the useResultRowIds hook under the covers, which means
|
|
8434
|
+
* that any changes to the structure of the result Table will cause a re-render.
|
|
8435
|
+
*
|
|
8436
|
+
* @param props The props for this component.
|
|
8437
|
+
* @returns A rendering of the result Table, or nothing, if not present.
|
|
8438
|
+
* @example
|
|
8439
|
+
* This example creates a Queries object outside the application, which is used
|
|
8440
|
+
* in the ResultTableView component by reference. A change to the data in the
|
|
8441
|
+
* Store re-renders the component.
|
|
8442
|
+
*
|
|
8443
|
+
* ```jsx
|
|
8444
|
+
* const store = createStore().setTable('pets', {
|
|
8445
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8446
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8447
|
+
* });
|
|
8448
|
+
* const queries = createQueries(store).setQueryDefinition(
|
|
8449
|
+
* 'petColors',
|
|
8450
|
+
* 'pets',
|
|
8451
|
+
* ({select}) => select('color'),
|
|
8452
|
+
* );
|
|
8453
|
+
* const App = () => (
|
|
8454
|
+
* <div>
|
|
8455
|
+
* <ResultTableView queryId="petColors" queries={queries} separator="/" />
|
|
8456
|
+
* </div>
|
|
8457
|
+
* );
|
|
8458
|
+
*
|
|
8459
|
+
* const app = document.createElement('div');
|
|
8460
|
+
* ReactDOM.render(<App />, app); // !act
|
|
8461
|
+
* console.log(app.innerHTML);
|
|
8462
|
+
* // -> '<div>brown/black</div>'
|
|
8463
|
+
*
|
|
8464
|
+
* store.setRow('pets', 'cujo', {species: 'dog', color: 'black'}); // !act
|
|
8465
|
+
* console.log(app.innerHTML);
|
|
8466
|
+
* // -> '<div>brown/black/black</div>'
|
|
8467
|
+
* ```
|
|
8468
|
+
* @example
|
|
8469
|
+
* This example creates a Provider context into which a default Queries object
|
|
8470
|
+
* is provided. The ResultTableView component within it then renders the Table
|
|
8471
|
+
* (with Ids for readability).
|
|
8472
|
+
*
|
|
8473
|
+
* ```jsx
|
|
8474
|
+
* const App = ({queries}) => (
|
|
8475
|
+
* <Provider queries={queries}>
|
|
8476
|
+
* <Pane />
|
|
8477
|
+
* </Provider>
|
|
8478
|
+
* );
|
|
8479
|
+
* const Pane = () => (
|
|
8480
|
+
* <div>
|
|
8481
|
+
* <ResultTableView queryId="petColors" debugIds={true} />
|
|
8482
|
+
* </div>
|
|
8483
|
+
* );
|
|
8484
|
+
*
|
|
8485
|
+
* const queries = createQueries(
|
|
8486
|
+
* createStore().setTable('pets', {
|
|
8487
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8488
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8489
|
+
* }),
|
|
8490
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
8491
|
+
* const app = document.createElement('div');
|
|
8492
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
8493
|
+
* console.log(app.innerHTML);
|
|
8494
|
+
* // -> '<div>petColors:{fido:{color:{brown}}felix:{color:{black}}}</div>'
|
|
8495
|
+
* ```
|
|
8496
|
+
* @example
|
|
8497
|
+
* This example creates a Provider context into which a default Queries object
|
|
8498
|
+
* is provided. The ResultTableView component within it then renders the Table
|
|
8499
|
+
* with a custom Row component and a custom props callback.
|
|
8500
|
+
*
|
|
8501
|
+
* ```jsx
|
|
8502
|
+
* const App = ({queries}) => (
|
|
8503
|
+
* <Provider queries={queries}>
|
|
8504
|
+
* <Pane />
|
|
8505
|
+
* </Provider>
|
|
8506
|
+
* );
|
|
8507
|
+
* const Pane = () => (
|
|
8508
|
+
* <div>
|
|
8509
|
+
* <ResultTableView
|
|
8510
|
+
* queryId="petColors"
|
|
8511
|
+
* resultRowComponent={FormattedRowView}
|
|
8512
|
+
* getResultRowComponentProps={(rowId) => ({bold: rowId == 'fido'})}
|
|
8513
|
+
* />
|
|
8514
|
+
* </div>
|
|
8515
|
+
* );
|
|
8516
|
+
* const FormattedRowView = ({queryId, rowId, bold}) => (
|
|
8517
|
+
* <span>
|
|
8518
|
+
* {bold ? <b>{rowId}</b> : rowId}
|
|
8519
|
+
* {': '}
|
|
8520
|
+
* <ResultRowView queryId={queryId} rowId={rowId} />
|
|
8521
|
+
* </span>
|
|
8522
|
+
* );
|
|
8523
|
+
*
|
|
8524
|
+
* const queries = createQueries(
|
|
8525
|
+
* createStore().setTable('pets', {
|
|
8526
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
8527
|
+
* felix: {species: 'cat', color: 'black'},
|
|
8528
|
+
* }),
|
|
8529
|
+
* ).setQueryDefinition('petColors', 'pets', ({select}) => select('color'));
|
|
8530
|
+
* const app = document.createElement('div');
|
|
8531
|
+
* ReactDOM.render(<App queries={queries} />, app); // !act
|
|
8532
|
+
* console.log(app.innerHTML);
|
|
8533
|
+
* // -> '<div><span><b>fido</b>: brown</span><span>felix: black</span></div>'
|
|
8534
|
+
* ```
|
|
8535
|
+
* @category Queries components
|
|
8536
|
+
*/
|
|
8537
|
+
export function ResultTableView(props: ResultTableProps): ComponentReturnType;
|
|
8538
|
+
|
|
6730
8539
|
/**
|
|
6731
8540
|
* The CheckpointView component simply renders the label of a checkpoint.
|
|
6732
8541
|
*
|