tinybase 7.2.0-beta.2 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/queries/index.d.ts +333 -4
- package/@types/queries/with-schemas/index.d.ts +359 -4
- package/@types/ui-react/index.d.ts +477 -8
- package/@types/ui-react/with-schemas/index.d.ts +519 -8
- package/agents.md +34 -0
- package/index.js +100 -18
- package/min/index.js +1 -1
- package/min/index.js.gz +0 -0
- package/min/omni/index.js +1 -1
- package/min/omni/index.js.gz +0 -0
- package/min/omni/with-schemas/index.js +1 -1
- package/min/omni/with-schemas/index.js.gz +0 -0
- package/min/queries/index.js +1 -1
- package/min/queries/index.js.gz +0 -0
- package/min/queries/with-schemas/index.js +1 -1
- package/min/queries/with-schemas/index.js.gz +0 -0
- package/min/ui-react/index.js +1 -1
- package/min/ui-react/index.js.gz +0 -0
- package/min/ui-react/with-schemas/index.js +1 -1
- package/min/ui-react/with-schemas/index.js.gz +0 -0
- package/min/ui-react-dom/index.js +1 -1
- package/min/ui-react-dom/index.js.gz +0 -0
- package/min/ui-react-dom/with-schemas/index.js +1 -1
- package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
- package/min/ui-react-inspector/index.js +1 -1
- package/min/ui-react-inspector/index.js.gz +0 -0
- package/min/ui-react-inspector/with-schemas/index.js +1 -1
- package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
- package/min/with-schemas/index.js +1 -1
- package/min/with-schemas/index.js.gz +0 -0
- package/omni/index.js +173 -48
- package/omni/with-schemas/index.js +173 -48
- package/package.json +3 -3
- package/queries/index.js +120 -18
- package/queries/with-schemas/index.js +120 -18
- package/readme.md +13 -13
- package/releases.md +40 -40
- package/ui-react/index.js +98 -30
- package/ui-react/with-schemas/index.js +98 -30
- package/ui-react-dom/index.js +38 -15
- package/ui-react-dom/with-schemas/index.js +38 -15
- package/ui-react-inspector/index.js +40 -17
- package/ui-react-inspector/with-schemas/index.js +40 -17
- package/with-schemas/index.js +100 -18
|
@@ -100,7 +100,9 @@ import type {
|
|
|
100
100
|
} from '../../persisters/with-schemas/index.d.ts';
|
|
101
101
|
import type {
|
|
102
102
|
ParamValue,
|
|
103
|
+
ParamValueListener,
|
|
103
104
|
ParamValues,
|
|
105
|
+
ParamValuesListener,
|
|
104
106
|
Queries,
|
|
105
107
|
ResultCell,
|
|
106
108
|
ResultCellIdsListener,
|
|
@@ -11777,8 +11779,520 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
11777
11779
|
) => void;
|
|
11778
11780
|
|
|
11779
11781
|
/**
|
|
11780
|
-
* The
|
|
11781
|
-
*
|
|
11782
|
+
* The useParamValues hook returns an object containing all the parameter values
|
|
11783
|
+
* currently set for a query.
|
|
11784
|
+
*
|
|
11785
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
11786
|
+
*
|
|
11787
|
+
* ```ts override
|
|
11788
|
+
* useParamValues(
|
|
11789
|
+
* queryId: Id,
|
|
11790
|
+
* queriesOrQueriesId?: QueriesOrQueriesId,
|
|
11791
|
+
* ): ParamValues | undefined;
|
|
11792
|
+
* ```
|
|
11793
|
+
*
|
|
11794
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
11795
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
11796
|
+
* Id. The useParamValues hook lets you indicate which Queries object to get
|
|
11797
|
+
* data for: omit the optional final parameter for the default context Queries
|
|
11798
|
+
* object, provide an Id for a named context Queries object, or provide a
|
|
11799
|
+
* Queries object explicitly by reference.
|
|
11800
|
+
*
|
|
11801
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
11802
|
+
* parameter values will cause a re-render. When the component containing this
|
|
11803
|
+
* hook is unmounted, the listener will be automatically removed.
|
|
11804
|
+
* @param queryId The Id of the query to get parameter values for.
|
|
11805
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
11806
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
11807
|
+
* object, or provide an explicit reference.
|
|
11808
|
+
* @returns An object containing all parameter values for the query, or
|
|
11809
|
+
* undefined if the query doesn't exist.
|
|
11810
|
+
* @example
|
|
11811
|
+
* This example creates a Queries object outside the application, which is used
|
|
11812
|
+
* in the useParamValues hook by reference. A change to the parameter values
|
|
11813
|
+
* re-renders the component.
|
|
11814
|
+
*
|
|
11815
|
+
* ```jsx
|
|
11816
|
+
* import React from 'react';
|
|
11817
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
11818
|
+
* import {createRoot} from 'react-dom/client';
|
|
11819
|
+
* import {useParamValues} from 'tinybase/ui-react';
|
|
11820
|
+
*
|
|
11821
|
+
* const store = createStore().setTable('pets', {
|
|
11822
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
11823
|
+
* felix: {species: 'cat', color: 'black'},
|
|
11824
|
+
* });
|
|
11825
|
+
* const queries = createQueries(store);
|
|
11826
|
+
* queries.setQueryDefinition(
|
|
11827
|
+
* 'petsBySpecies',
|
|
11828
|
+
* 'pets',
|
|
11829
|
+
* ({select, where, param}) => {
|
|
11830
|
+
* select('species');
|
|
11831
|
+
* where('species', param('species'));
|
|
11832
|
+
* },
|
|
11833
|
+
* {species: 'dog'},
|
|
11834
|
+
* );
|
|
11835
|
+
*
|
|
11836
|
+
* const App = () => (
|
|
11837
|
+
* <span>{JSON.stringify(useParamValues('petsBySpecies', queries))}</span>
|
|
11838
|
+
* );
|
|
11839
|
+
*
|
|
11840
|
+
* const app = document.createElement('div');
|
|
11841
|
+
* createRoot(app).render(<App />); // !act
|
|
11842
|
+
* console.log(app.innerHTML);
|
|
11843
|
+
* // -> '<span>{"species":"dog"}</span>'
|
|
11844
|
+
*
|
|
11845
|
+
* queries.setParamValue('petsBySpecies', 'species', 'cat'); // !act
|
|
11846
|
+
* console.log(app.innerHTML);
|
|
11847
|
+
* // -> '<span>{"species":"cat"}</span>'
|
|
11848
|
+
* ```
|
|
11849
|
+
* @example
|
|
11850
|
+
* This example creates a Provider context into which a default Queries object
|
|
11851
|
+
* is provided. A component within it then uses the useParamValues hook.
|
|
11852
|
+
*
|
|
11853
|
+
* ```jsx
|
|
11854
|
+
* import {Provider, useParamValues} from 'tinybase/ui-react';
|
|
11855
|
+
* import React from 'react';
|
|
11856
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
11857
|
+
* import {createRoot} from 'react-dom/client';
|
|
11858
|
+
*
|
|
11859
|
+
* const App = ({queries}) => (
|
|
11860
|
+
* <Provider queries={queries}>
|
|
11861
|
+
* <Pane />
|
|
11862
|
+
* </Provider>
|
|
11863
|
+
* );
|
|
11864
|
+
* const Pane = () => (
|
|
11865
|
+
* <span>{JSON.stringify(useParamValues('petsBySpecies'))}</span>
|
|
11866
|
+
* );
|
|
11867
|
+
*
|
|
11868
|
+
* const store = createStore().setTable('pets', {
|
|
11869
|
+
* fido: {species: 'dog'},
|
|
11870
|
+
* felix: {species: 'cat'},
|
|
11871
|
+
* });
|
|
11872
|
+
* const queries = createQueries(store);
|
|
11873
|
+
* queries.setQueryDefinition(
|
|
11874
|
+
* 'petsBySpecies',
|
|
11875
|
+
* 'pets',
|
|
11876
|
+
* ({select, where, param}) => {
|
|
11877
|
+
* select('species');
|
|
11878
|
+
* where('species', param('species'));
|
|
11879
|
+
* },
|
|
11880
|
+
* {species: 'dog'},
|
|
11881
|
+
* );
|
|
11882
|
+
*
|
|
11883
|
+
* const app = document.createElement('div');
|
|
11884
|
+
* createRoot(app).render(<App queries={queries} />); // !act
|
|
11885
|
+
* console.log(app.innerHTML);
|
|
11886
|
+
* // -> '<span>{"species":"dog"}</span>'
|
|
11887
|
+
* ```
|
|
11888
|
+
* @example
|
|
11889
|
+
* This example creates a Provider context into which a Queries object is
|
|
11890
|
+
* provided, named by Id. A component within it then uses the useParamValues
|
|
11891
|
+
* hook.
|
|
11892
|
+
*
|
|
11893
|
+
* ```jsx
|
|
11894
|
+
* import {Provider, useParamValues} from 'tinybase/ui-react';
|
|
11895
|
+
* import React from 'react';
|
|
11896
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
11897
|
+
* import {createRoot} from 'react-dom/client';
|
|
11898
|
+
*
|
|
11899
|
+
* const App = ({queries}) => (
|
|
11900
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
11901
|
+
* <Pane />
|
|
11902
|
+
* </Provider>
|
|
11903
|
+
* );
|
|
11904
|
+
* const Pane = () => (
|
|
11905
|
+
* <span>
|
|
11906
|
+
* {JSON.stringify(useParamValues('petsBySpecies', 'petQueries'))}
|
|
11907
|
+
* </span>
|
|
11908
|
+
* );
|
|
11909
|
+
*
|
|
11910
|
+
* const store = createStore().setTable('pets', {
|
|
11911
|
+
* fido: {species: 'dog'},
|
|
11912
|
+
* felix: {species: 'cat'},
|
|
11913
|
+
* });
|
|
11914
|
+
* const queries = createQueries(store);
|
|
11915
|
+
* queries.setQueryDefinition(
|
|
11916
|
+
* 'petsBySpecies',
|
|
11917
|
+
* 'pets',
|
|
11918
|
+
* ({select, where, param}) => {
|
|
11919
|
+
* select('species');
|
|
11920
|
+
* where('species', param('species'));
|
|
11921
|
+
* },
|
|
11922
|
+
* {species: 'dog'},
|
|
11923
|
+
* );
|
|
11924
|
+
*
|
|
11925
|
+
* const app = document.createElement('div');
|
|
11926
|
+
* createRoot(app).render(<App queries={queries} />); // !act
|
|
11927
|
+
* console.log(app.innerHTML);
|
|
11928
|
+
* // -> '<span>{"species":"dog"}</span>'
|
|
11929
|
+
* ```
|
|
11930
|
+
* @category Queries hooks
|
|
11931
|
+
* @since v7.2.0
|
|
11932
|
+
*/
|
|
11933
|
+
useParamValues: (
|
|
11934
|
+
queryId: Id,
|
|
11935
|
+
queriesOrQueriesId?: QueriesOrQueriesId<Schemas>,
|
|
11936
|
+
) => ParamValues | undefined;
|
|
11937
|
+
|
|
11938
|
+
/**
|
|
11939
|
+
* The useParamValue hook returns the current value of a single parameter in a
|
|
11940
|
+
* query.
|
|
11941
|
+
*
|
|
11942
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
11943
|
+
*
|
|
11944
|
+
* ```ts override
|
|
11945
|
+
* useParamValue(
|
|
11946
|
+
* queryId: Id,
|
|
11947
|
+
* paramId: Id,
|
|
11948
|
+
* queriesOrQueriesId?: QueriesOrQueriesId,
|
|
11949
|
+
* ): ParamValue | undefined;
|
|
11950
|
+
* ```
|
|
11951
|
+
*
|
|
11952
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
11953
|
+
* it can contain a default Queries object or a set of Queries objects named by
|
|
11954
|
+
* Id. The useParamValue hook lets you indicate which Queries object to get data
|
|
11955
|
+
* for: omit the optional final parameter for the default context Queries
|
|
11956
|
+
* object, provide an Id for a named context Queries object, or provide a
|
|
11957
|
+
* Queries object explicitly by reference.
|
|
11958
|
+
*
|
|
11959
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
11960
|
+
* parameter value will cause a re-render. When the component containing this
|
|
11961
|
+
* hook is unmounted, the listener will be automatically removed.
|
|
11962
|
+
* @param queryId The Id of the query to get the parameter value from.
|
|
11963
|
+
* @param paramId The Id of the parameter to get the value of.
|
|
11964
|
+
* @param queriesOrQueriesId The Queries object to be accessed: omit for the
|
|
11965
|
+
* default context Queries object, provide an Id for a named context Queries
|
|
11966
|
+
* object, or provide an explicit reference.
|
|
11967
|
+
* @returns The value of the parameter, or undefined if it doesn't exist.
|
|
11968
|
+
* @example
|
|
11969
|
+
* This example creates a Queries object outside the application, which is used
|
|
11970
|
+
* in the useParamValue hook by reference. A change to the parameter value
|
|
11971
|
+
* re-renders the component.
|
|
11972
|
+
*
|
|
11973
|
+
* ```jsx
|
|
11974
|
+
* import React from 'react';
|
|
11975
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
11976
|
+
* import {createRoot} from 'react-dom/client';
|
|
11977
|
+
* import {useParamValue} from 'tinybase/ui-react';
|
|
11978
|
+
*
|
|
11979
|
+
* const store = createStore().setTable('pets', {
|
|
11980
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
11981
|
+
* felix: {species: 'cat', color: 'black'},
|
|
11982
|
+
* });
|
|
11983
|
+
* const queries = createQueries(store);
|
|
11984
|
+
* queries.setQueryDefinition(
|
|
11985
|
+
* 'petsBySpecies',
|
|
11986
|
+
* 'pets',
|
|
11987
|
+
* ({select, where, param}) => {
|
|
11988
|
+
* select('species');
|
|
11989
|
+
* where('species', param('species'));
|
|
11990
|
+
* },
|
|
11991
|
+
* {species: 'dog'},
|
|
11992
|
+
* );
|
|
11993
|
+
*
|
|
11994
|
+
* const App = () => (
|
|
11995
|
+
* <span>{useParamValue('petsBySpecies', 'species', queries)}</span>
|
|
11996
|
+
* );
|
|
11997
|
+
*
|
|
11998
|
+
* const app = document.createElement('div');
|
|
11999
|
+
* createRoot(app).render(<App />); // !act
|
|
12000
|
+
* console.log(app.innerHTML);
|
|
12001
|
+
* // -> '<span>dog</span>'
|
|
12002
|
+
*
|
|
12003
|
+
* queries.setParamValue('petsBySpecies', 'species', 'cat'); // !act
|
|
12004
|
+
* console.log(app.innerHTML);
|
|
12005
|
+
* // -> '<span>cat</span>'
|
|
12006
|
+
* ```
|
|
12007
|
+
* @example
|
|
12008
|
+
* This example creates a Provider context into which a default Queries object
|
|
12009
|
+
* is provided. A component within it then uses the useParamValue hook.
|
|
12010
|
+
*
|
|
12011
|
+
* ```jsx
|
|
12012
|
+
* import {Provider, useParamValue} from 'tinybase/ui-react';
|
|
12013
|
+
* import React from 'react';
|
|
12014
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
12015
|
+
* import {createRoot} from 'react-dom/client';
|
|
12016
|
+
*
|
|
12017
|
+
* const App = ({queries}) => (
|
|
12018
|
+
* <Provider queries={queries}>
|
|
12019
|
+
* <Pane />
|
|
12020
|
+
* </Provider>
|
|
12021
|
+
* );
|
|
12022
|
+
* const Pane = () => (
|
|
12023
|
+
* <span>{useParamValue('petsBySpecies', 'species')}</span>
|
|
12024
|
+
* );
|
|
12025
|
+
*
|
|
12026
|
+
* const store = createStore().setTable('pets', {
|
|
12027
|
+
* fido: {species: 'dog'},
|
|
12028
|
+
* felix: {species: 'cat'},
|
|
12029
|
+
* });
|
|
12030
|
+
* const queries = createQueries(store);
|
|
12031
|
+
* queries.setQueryDefinition(
|
|
12032
|
+
* 'petsBySpecies',
|
|
12033
|
+
* 'pets',
|
|
12034
|
+
* ({select, where, param}) => {
|
|
12035
|
+
* select('species');
|
|
12036
|
+
* where('species', param('species'));
|
|
12037
|
+
* },
|
|
12038
|
+
* {species: 'dog'},
|
|
12039
|
+
* );
|
|
12040
|
+
*
|
|
12041
|
+
* const app = document.createElement('div');
|
|
12042
|
+
* createRoot(app).render(<App queries={queries} />); // !act
|
|
12043
|
+
* console.log(app.innerHTML);
|
|
12044
|
+
* // -> '<span>dog</span>'
|
|
12045
|
+
* ```
|
|
12046
|
+
* @example
|
|
12047
|
+
* This example creates a Provider context into which a Queries object is
|
|
12048
|
+
* provided, named by Id. A component within it then uses the useParamValue
|
|
12049
|
+
* hook.
|
|
12050
|
+
*
|
|
12051
|
+
* ```jsx
|
|
12052
|
+
* import {Provider, useParamValue} from 'tinybase/ui-react';
|
|
12053
|
+
* import React from 'react';
|
|
12054
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
12055
|
+
* import {createRoot} from 'react-dom/client';
|
|
12056
|
+
*
|
|
12057
|
+
* const App = ({queries}) => (
|
|
12058
|
+
* <Provider queriesById={{petQueries: queries}}>
|
|
12059
|
+
* <Pane />
|
|
12060
|
+
* </Provider>
|
|
12061
|
+
* );
|
|
12062
|
+
* const Pane = () => (
|
|
12063
|
+
* <span>{useParamValue('petsBySpecies', 'species', 'petQueries')}</span>
|
|
12064
|
+
* );
|
|
12065
|
+
*
|
|
12066
|
+
* const store = createStore().setTable('pets', {
|
|
12067
|
+
* fido: {species: 'dog'},
|
|
12068
|
+
* felix: {species: 'cat'},
|
|
12069
|
+
* });
|
|
12070
|
+
* const queries = createQueries(store);
|
|
12071
|
+
* queries.setQueryDefinition(
|
|
12072
|
+
* 'petsBySpecies',
|
|
12073
|
+
* 'pets',
|
|
12074
|
+
* ({select, where, param}) => {
|
|
12075
|
+
* select('species');
|
|
12076
|
+
* where('species', param('species'));
|
|
12077
|
+
* },
|
|
12078
|
+
* {species: 'dog'},
|
|
12079
|
+
* );
|
|
12080
|
+
*
|
|
12081
|
+
* const app = document.createElement('div');
|
|
12082
|
+
* createRoot(app).render(<App queries={queries} />); // !act
|
|
12083
|
+
* console.log(app.innerHTML);
|
|
12084
|
+
* // -> '<span>dog</span>'
|
|
12085
|
+
* ```
|
|
12086
|
+
* @category Queries hooks
|
|
12087
|
+
* @since v7.2.0
|
|
12088
|
+
*/
|
|
12089
|
+
useParamValue: (
|
|
12090
|
+
queryId: Id,
|
|
12091
|
+
paramId: Id,
|
|
12092
|
+
queriesOrQueriesId?: QueriesOrQueriesId<Schemas>,
|
|
12093
|
+
) => ParamValue | undefined;
|
|
12094
|
+
|
|
12095
|
+
/**
|
|
12096
|
+
* The useParamValuesListener hook registers a listener function with a Queries
|
|
12097
|
+
* object that will be called whenever the parameter values for a query change.
|
|
12098
|
+
*
|
|
12099
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
12100
|
+
*
|
|
12101
|
+
* ```ts override
|
|
12102
|
+
* useParamValuesListener(
|
|
12103
|
+
* queryId: IdOrNull,
|
|
12104
|
+
* listener: ParamValuesListener,
|
|
12105
|
+
* listenerDeps?: React.DependencyList,
|
|
12106
|
+
* queriesOrQueriesId?: QueriesOrQueriesId,
|
|
12107
|
+
* ): void;
|
|
12108
|
+
* ```
|
|
12109
|
+
*
|
|
12110
|
+
* This hook is useful for situations where a component needs to register its
|
|
12111
|
+
* own specific listener to do more than simply tracking the values (which is
|
|
12112
|
+
* more easily done with the useParamValues hook).
|
|
12113
|
+
*
|
|
12114
|
+
* Unlike the addParamValuesListener method, which returns a listener Id and
|
|
12115
|
+
* requires you to remove it manually, the useParamValuesListener hook manages
|
|
12116
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
12117
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
12118
|
+
* Queries object will be deleted.
|
|
12119
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
12120
|
+
* @param listener The function that will be called whenever the parameter
|
|
12121
|
+
* values for the query change.
|
|
12122
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
12123
|
+
* function, which, if any change, result in the re-registration of the
|
|
12124
|
+
* listener. This parameter defaults to an empty array.
|
|
12125
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
12126
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
12127
|
+
* context Queries object, or provide an explicit reference.
|
|
12128
|
+
* @example
|
|
12129
|
+
* This example uses the useParamValuesListener hook to create a listener that
|
|
12130
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
12131
|
+
* listener is removed from the Queries object.
|
|
12132
|
+
*
|
|
12133
|
+
* ```jsx
|
|
12134
|
+
* import React from 'react';
|
|
12135
|
+
* import {createRoot} from 'react-dom/client';
|
|
12136
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
12137
|
+
* import {Provider, useParamValuesListener} from 'tinybase/ui-react';
|
|
12138
|
+
*
|
|
12139
|
+
* const App = ({queries}) => (
|
|
12140
|
+
* <Provider queries={queries}>
|
|
12141
|
+
* <Pane />
|
|
12142
|
+
* </Provider>
|
|
12143
|
+
* );
|
|
12144
|
+
* const Pane = () => {
|
|
12145
|
+
* useParamValuesListener('petsBySpecies', () =>
|
|
12146
|
+
* console.log('Param values changed'),
|
|
12147
|
+
* );
|
|
12148
|
+
* return <span>App</span>;
|
|
12149
|
+
* };
|
|
12150
|
+
*
|
|
12151
|
+
* const store = createStore().setTable('pets', {
|
|
12152
|
+
* fido: {species: 'dog'},
|
|
12153
|
+
* felix: {species: 'cat'},
|
|
12154
|
+
* });
|
|
12155
|
+
* const queries = createQueries(store);
|
|
12156
|
+
* queries.setQueryDefinition(
|
|
12157
|
+
* 'petsBySpecies',
|
|
12158
|
+
* 'pets',
|
|
12159
|
+
* ({select, where, param}) => {
|
|
12160
|
+
* select('species');
|
|
12161
|
+
* where('species', param('species'));
|
|
12162
|
+
* },
|
|
12163
|
+
* {species: 'dog'},
|
|
12164
|
+
* );
|
|
12165
|
+
* const app = document.createElement('div');
|
|
12166
|
+
* const root = createRoot(app);
|
|
12167
|
+
* root.render(<App queries={queries} />); // !act
|
|
12168
|
+
* console.log(queries.getListenerStats().paramValues);
|
|
12169
|
+
* // -> 1
|
|
12170
|
+
*
|
|
12171
|
+
* queries.setParamValue('petsBySpecies', 'species', 'cat'); // !act
|
|
12172
|
+
* // -> 'Param values changed'
|
|
12173
|
+
*
|
|
12174
|
+
* root.unmount(); // !act
|
|
12175
|
+
* console.log(queries.getListenerStats().paramValues);
|
|
12176
|
+
* // -> 0
|
|
12177
|
+
* ```
|
|
12178
|
+
* @category Queries hooks
|
|
12179
|
+
* @since v7.2.0
|
|
12180
|
+
*/
|
|
12181
|
+
useParamValuesListener: (
|
|
12182
|
+
queryId: IdOrNull,
|
|
12183
|
+
listener: ParamValuesListener<Schemas>,
|
|
12184
|
+
listenerDeps?: React.DependencyList,
|
|
12185
|
+
queriesOrQueriesId?: QueriesOrQueriesId<Schemas>,
|
|
12186
|
+
) => void;
|
|
12187
|
+
|
|
12188
|
+
/**
|
|
12189
|
+
* The useParamValueListener hook registers a listener function with a Queries
|
|
12190
|
+
* object that will be called whenever a single parameter value for a query
|
|
12191
|
+
* changes.
|
|
12192
|
+
*
|
|
12193
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
12194
|
+
*
|
|
12195
|
+
* ```ts override
|
|
12196
|
+
* useParamValueListener(
|
|
12197
|
+
* queryId: IdOrNull,
|
|
12198
|
+
* paramId: IdOrNull,
|
|
12199
|
+
* listener: ParamValueListener,
|
|
12200
|
+
* listenerDeps?: React.DependencyList,
|
|
12201
|
+
* queriesOrQueriesId?: QueriesOrQueriesId,
|
|
12202
|
+
* ): void;
|
|
12203
|
+
* ```
|
|
12204
|
+
*
|
|
12205
|
+
* This hook is useful for situations where a component needs to register its
|
|
12206
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
12207
|
+
* more easily done with the useParamValue hook).
|
|
12208
|
+
*
|
|
12209
|
+
* You can either listen to a single parameter (by specifying the query Id and
|
|
12210
|
+
* parameter Id as the method's first two parameters) or changes to any
|
|
12211
|
+
* parameter (by providing `null` wildcards).
|
|
12212
|
+
*
|
|
12213
|
+
* Both the `queryId` and `paramId` parameters can be wildcarded with `null`.
|
|
12214
|
+
* You can listen to a specific parameter in a specific query, any parameter in
|
|
12215
|
+
* any query, for example - or every other combination of wildcards.
|
|
12216
|
+
*
|
|
12217
|
+
* Unlike the addParamValueListener method, which returns a listener Id and
|
|
12218
|
+
* requires you to remove it manually, the useParamValueListener hook manages
|
|
12219
|
+
* this lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
12220
|
+
* dependencies) or the component unmounts, the listener on the underlying
|
|
12221
|
+
* Queries object will be deleted.
|
|
12222
|
+
* @param queryId The Id of the query to listen to, or `null` as a wildcard.
|
|
12223
|
+
* @param paramId The Id of the parameter to listen to, or `null` as a wildcard.
|
|
12224
|
+
* @param listener The function that will be called whenever the parameter value
|
|
12225
|
+
* changes.
|
|
12226
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
12227
|
+
* function, which, if any change, result in the re-registration of the
|
|
12228
|
+
* listener. This parameter defaults to an empty array.
|
|
12229
|
+
* @param queriesOrQueriesId The Queries object to register the listener with:
|
|
12230
|
+
* omit for the default context Queries object, provide an Id for a named
|
|
12231
|
+
* context Queries object, or provide an explicit reference.
|
|
12232
|
+
* @example
|
|
12233
|
+
* This example uses the useParamValueListener hook to create a listener that
|
|
12234
|
+
* is scoped to a single component. When the component is unmounted, the
|
|
12235
|
+
* listener is removed from the Queries object.
|
|
12236
|
+
*
|
|
12237
|
+
* ```jsx
|
|
12238
|
+
* import React from 'react';
|
|
12239
|
+
* import {createRoot} from 'react-dom/client';
|
|
12240
|
+
* import {createQueries, createStore} from 'tinybase';
|
|
12241
|
+
* import {Provider, useParamValueListener} from 'tinybase/ui-react';
|
|
12242
|
+
*
|
|
12243
|
+
* const App = ({queries}) => (
|
|
12244
|
+
* <Provider queries={queries}>
|
|
12245
|
+
* <Pane />
|
|
12246
|
+
* </Provider>
|
|
12247
|
+
* );
|
|
12248
|
+
* const Pane = () => {
|
|
12249
|
+
* useParamValueListener('petsBySpecies', 'species', () =>
|
|
12250
|
+
* console.log('Param value changed'),
|
|
12251
|
+
* );
|
|
12252
|
+
* return <span>App</span>;
|
|
12253
|
+
* };
|
|
12254
|
+
*
|
|
12255
|
+
* const store = createStore().setTable('pets', {
|
|
12256
|
+
* fido: {species: 'dog'},
|
|
12257
|
+
* felix: {species: 'cat'},
|
|
12258
|
+
* });
|
|
12259
|
+
* const queries = createQueries(store);
|
|
12260
|
+
* queries.setQueryDefinition(
|
|
12261
|
+
* 'petsBySpecies',
|
|
12262
|
+
* 'pets',
|
|
12263
|
+
* ({select, where, param}) => {
|
|
12264
|
+
* select('species');
|
|
12265
|
+
* where('species', param('species'));
|
|
12266
|
+
* },
|
|
12267
|
+
* {species: 'dog'},
|
|
12268
|
+
* );
|
|
12269
|
+
* const app = document.createElement('div');
|
|
12270
|
+
* const root = createRoot(app);
|
|
12271
|
+
* root.render(<App queries={queries} />); // !act
|
|
12272
|
+
* console.log(queries.getListenerStats().paramValue);
|
|
12273
|
+
* // -> 1
|
|
12274
|
+
*
|
|
12275
|
+
* queries.setParamValue('petsBySpecies', 'species', 'cat'); // !act
|
|
12276
|
+
* // -> 'Param value changed'
|
|
12277
|
+
*
|
|
12278
|
+
* root.unmount(); // !act
|
|
12279
|
+
* console.log(queries.getListenerStats().paramValue);
|
|
12280
|
+
* // -> 0
|
|
12281
|
+
* ```
|
|
12282
|
+
* @category Queries hooks
|
|
12283
|
+
* @since v7.2.0
|
|
12284
|
+
*/
|
|
12285
|
+
useParamValueListener: (
|
|
12286
|
+
queryId: IdOrNull,
|
|
12287
|
+
paramId: IdOrNull,
|
|
12288
|
+
listener: ParamValueListener<Schemas>,
|
|
12289
|
+
listenerDeps?: React.DependencyList,
|
|
12290
|
+
queriesOrQueriesId?: QueriesOrQueriesId<Schemas>,
|
|
12291
|
+
) => void;
|
|
12292
|
+
|
|
12293
|
+
/**
|
|
12294
|
+
* The useSetParamValueCallback hook returns a parameterized callback that can
|
|
12295
|
+
* be used to set a single parameter value for a query.
|
|
11782
12296
|
*
|
|
11783
12297
|
* This has schema-based typing. The following is a simplified representation:
|
|
11784
12298
|
*
|
|
@@ -11843,10 +12357,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
11843
12357
|
* import React from 'react';
|
|
11844
12358
|
* import {createRoot} from 'react-dom/client';
|
|
11845
12359
|
* import {createQueries, createStore} from 'tinybase';
|
|
11846
|
-
* import {
|
|
11847
|
-
* useResultTable,
|
|
11848
|
-
* useSetParamValueCallback,
|
|
11849
|
-
* } from 'tinybase/ui-react';
|
|
12360
|
+
* import {useResultTable, useSetParamValueCallback} from 'tinybase/ui-react';
|
|
11850
12361
|
*
|
|
11851
12362
|
* const store = createStore().setTable('pets', {
|
|
11852
12363
|
* fido: {species: 'dog', color: 'brown'},
|
|
@@ -11924,8 +12435,8 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
|
|
|
11924
12435
|
) => ParameterizedCallback<Parameter>;
|
|
11925
12436
|
|
|
11926
12437
|
/**
|
|
11927
|
-
* The useSetParamValuesCallback hook returns a parameterized callback that
|
|
11928
|
-
*
|
|
12438
|
+
* The useSetParamValuesCallback hook returns a parameterized callback that can
|
|
12439
|
+
* be used to set multiple parameter values for a query at once.
|
|
11929
12440
|
*
|
|
11930
12441
|
* This has schema-based typing. The following is a simplified representation:
|
|
11931
12442
|
*
|
package/agents.md
CHANGED
|
@@ -485,3 +485,37 @@ When adding a new feature:
|
|
|
485
485
|
`<span id="one-with">"The one with Schematizers!"</span>`
|
|
486
486
|
|
|
487
487
|
3. **Generated files update automatically** during build process
|
|
488
|
+
|
|
489
|
+
## Demo Development Workflow
|
|
490
|
+
|
|
491
|
+
Demos are located in `/site/demos/` as markdown files containing embedded code
|
|
492
|
+
blocks that are assembled into working applications.
|
|
493
|
+
|
|
494
|
+
### Demo Structure
|
|
495
|
+
|
|
496
|
+
- **Demo files**: `/site/demos/*.md` or `/site/demos/*/`
|
|
497
|
+
- **E2E tests**: `/test/e2e/demos/*.test.ts`
|
|
498
|
+
- Code blocks in markdown are extracted and combined into complete applications
|
|
499
|
+
- All code fragments in a demo share scope (variables declared in one block are
|
|
500
|
+
available in subsequent blocks)
|
|
501
|
+
|
|
502
|
+
### Iteration Workflow
|
|
503
|
+
|
|
504
|
+
When modifying demos:
|
|
505
|
+
|
|
506
|
+
```bash
|
|
507
|
+
# One-time setup (only if TinyBase source code has changed)
|
|
508
|
+
npm run compileForProd
|
|
509
|
+
|
|
510
|
+
# Fast iteration loop
|
|
511
|
+
npm run compileDocsPagesOnly # Rebuild just the demo pages
|
|
512
|
+
npm run testE2e # Run E2E tests to verify demos
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
**Key points**:
|
|
516
|
+
|
|
517
|
+
- `compileForProd` builds the TinyBase libraries themselves
|
|
518
|
+
- `compileDocsPagesOnly` is much faster - only rebuilds demo pages from markdown
|
|
519
|
+
- You only need `compileForProd` once, unless you've changed TinyBase source
|
|
520
|
+
- E2E tests use Playwright to verify demos work in a real browser
|
|
521
|
+
- Individual E2E tests can be run for faster verification during iteration
|