tinybase 3.0.0-beta.0 → 3.0.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/bin/cli.js +1 -1
- package/lib/checkpoints.d.ts +18 -3
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +18 -3
- package/lib/debug/checkpoints.js +97 -49
- package/lib/debug/indexes.js +31 -16
- package/lib/debug/metrics.js +31 -16
- package/lib/debug/persisters.d.ts +33 -23
- package/lib/debug/persisters.js +10 -5
- package/lib/debug/queries.js +2 -2
- package/lib/debug/relationships.js +31 -16
- package/lib/debug/store.d.ts +2053 -381
- package/lib/debug/store.js +444 -106
- package/lib/debug/tinybase.js +512 -138
- package/lib/debug/tools.d.ts +109 -38
- package/lib/debug/tools.js +759 -453
- package/lib/debug/ui-react.d.ts +1218 -138
- package/lib/debug/ui-react.js +163 -12
- package/lib/es6/checkpoints.d.ts +18 -3
- package/lib/es6/checkpoints.js +1 -1
- package/lib/es6/checkpoints.js.gz +0 -0
- package/lib/es6/indexes.js +1 -1
- package/lib/es6/indexes.js.gz +0 -0
- package/lib/es6/metrics.js +1 -1
- package/lib/es6/metrics.js.gz +0 -0
- package/lib/es6/persisters.d.ts +33 -23
- package/lib/es6/persisters.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -0
- package/lib/es6/store.d.ts +2053 -381
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.d.ts +109 -38
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.d.ts +1218 -138
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- 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/persisters.d.ts +33 -23
- package/lib/persisters.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.js.gz +0 -0
- package/lib/store.d.ts +2053 -381
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/tools.d.ts +109 -38
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/ui-react.d.ts +1218 -138
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.d.ts +18 -3
- 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/persisters.d.ts +33 -23
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.d.ts +2053 -381
- 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/tools.d.ts +109 -38
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.d.ts +1218 -138
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/checkpoints.d.ts +18 -3
- package/lib/umd-es6/checkpoints.js +1 -1
- package/lib/umd-es6/checkpoints.js.gz +0 -0
- package/lib/umd-es6/indexes.js +1 -1
- package/lib/umd-es6/indexes.js.gz +0 -0
- package/lib/umd-es6/metrics.js +1 -1
- package/lib/umd-es6/metrics.js.gz +0 -0
- package/lib/umd-es6/persisters.d.ts +33 -23
- package/lib/umd-es6/persisters.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/relationships.js +1 -1
- package/lib/umd-es6/relationships.js.gz +0 -0
- package/lib/umd-es6/store.d.ts +2053 -381
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.d.ts +109 -38
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.d.ts +1218 -138
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +20 -20
- package/readme.md +27 -16
package/lib/debug/ui-react.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ import {
|
|
|
39
39
|
TableListener,
|
|
40
40
|
Tables,
|
|
41
41
|
TablesListener,
|
|
42
|
+
Value,
|
|
43
|
+
ValueIdsListener,
|
|
44
|
+
ValueListener,
|
|
45
|
+
Values,
|
|
46
|
+
ValuesListener,
|
|
42
47
|
} from './store.d';
|
|
43
48
|
import {
|
|
44
49
|
CheckpointIds,
|
|
@@ -339,7 +344,7 @@ export function useCreateStore(
|
|
|
339
344
|
export function useStore(id?: Id): Store | undefined;
|
|
340
345
|
|
|
341
346
|
/**
|
|
342
|
-
* The useTables hook returns a Tables object containing the
|
|
347
|
+
* The useTables hook returns a Tables object containing the tabular data of a
|
|
343
348
|
* Store, and registers a listener so that any changes to that result will cause
|
|
344
349
|
* a re-render.
|
|
345
350
|
*
|
|
@@ -356,7 +361,7 @@ export function useStore(id?: Id): Store | undefined;
|
|
|
356
361
|
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
357
362
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
358
363
|
* reference.
|
|
359
|
-
* @returns A Tables object containing the
|
|
364
|
+
* @returns A Tables object containing the tabular data of the Store.
|
|
360
365
|
* @example
|
|
361
366
|
* This example creates a Store outside the application, which is used in the
|
|
362
367
|
* useTables hook by reference. A change to the data in the Store re-renders the
|
|
@@ -418,7 +423,8 @@ export function useTables(storeOrStoreId?: StoreOrStoreId): Tables;
|
|
|
418
423
|
|
|
419
424
|
/**
|
|
420
425
|
* The useTableIds hook returns the Ids of every Table in a Store, and registers
|
|
421
|
-
* a listener so that any changes to that result will cause a re-render.
|
|
426
|
+
* a listener so that any changes to that result will cause a re-render.
|
|
427
|
+
*
|
|
422
428
|
* A Provider component is used to wrap part of an application in a context, and
|
|
423
429
|
* it can contain a default Store or a set of Store objects named by Id. The
|
|
424
430
|
* useTableIds hook lets you indicate which Store to get data for: omit the
|
|
@@ -492,9 +498,9 @@ export function useTables(storeOrStoreId?: StoreOrStoreId): Tables;
|
|
|
492
498
|
export function useTableIds(storeOrStoreId?: StoreOrStoreId): Ids;
|
|
493
499
|
|
|
494
500
|
/**
|
|
495
|
-
* The useTable hook returns an object containing the
|
|
496
|
-
*
|
|
497
|
-
*
|
|
501
|
+
* The useTable hook returns an object containing the data of a single Table in
|
|
502
|
+
* a Store, and registers a listener so that any changes to that result will
|
|
503
|
+
* cause a re-render.
|
|
498
504
|
*
|
|
499
505
|
* A Provider component is used to wrap part of an application in a context, and
|
|
500
506
|
* it can contain a default Store or a set of Store objects named by Id. The
|
|
@@ -770,9 +776,9 @@ export function useSortedRowIds(
|
|
|
770
776
|
): Ids;
|
|
771
777
|
|
|
772
778
|
/**
|
|
773
|
-
* The useRow hook returns an object containing the
|
|
774
|
-
*
|
|
775
|
-
*
|
|
779
|
+
* The useRow hook returns an object containing the data of a single Row in a
|
|
780
|
+
* given Table, and registers a listener so that any changes to that result will
|
|
781
|
+
* cause a re-render.
|
|
776
782
|
*
|
|
777
783
|
* A Provider component is used to wrap part of an application in a context, and
|
|
778
784
|
* it can contain a default Store or a set of Store objects named by Id. The
|
|
@@ -1032,12 +1038,248 @@ export function useCell(
|
|
|
1032
1038
|
storeOrStoreId?: StoreOrStoreId,
|
|
1033
1039
|
): Cell | undefined;
|
|
1034
1040
|
|
|
1041
|
+
/**
|
|
1042
|
+
* The useValues hook returns a Values object containing the keyed value data of
|
|
1043
|
+
* a Store, and registers a listener so that any changes to that result will
|
|
1044
|
+
* cause a re-render.
|
|
1045
|
+
*
|
|
1046
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
1047
|
+
* it can contain a default Store or a set of Store objects named by Id. The
|
|
1048
|
+
* useValues hook lets you indicate which Store to get data for: omit the
|
|
1049
|
+
* optional parameter for the default context Store, provide an Id for a named
|
|
1050
|
+
* context Store, or provide a Store explicitly by reference.
|
|
1051
|
+
*
|
|
1052
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
1053
|
+
* Values will cause a re-render. When the component containing this hook is
|
|
1054
|
+
* unmounted, the listener will be automatically removed.
|
|
1055
|
+
*
|
|
1056
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
1057
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1058
|
+
* reference.
|
|
1059
|
+
* @returns A Values object containing the keyed value data of the Store.
|
|
1060
|
+
* @example
|
|
1061
|
+
* This example creates a Store outside the application, which is used in the
|
|
1062
|
+
* useValues hook by reference. A change to the data in the Store re-renders the
|
|
1063
|
+
* component.
|
|
1064
|
+
*
|
|
1065
|
+
* ```jsx
|
|
1066
|
+
* const store = createStore().setValue('open', true);
|
|
1067
|
+
* const App = () => <span>{JSON.stringify(useValues(store))}</span>;
|
|
1068
|
+
*
|
|
1069
|
+
* const app = document.createElement('div');
|
|
1070
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
1071
|
+
* console.log(app.innerHTML);
|
|
1072
|
+
* // -> '<span>{"open":true}</span>'
|
|
1073
|
+
*
|
|
1074
|
+
* store.setValue('open', false); // !act
|
|
1075
|
+
* console.log(app.innerHTML);
|
|
1076
|
+
* // -> '<span>{"open":false}</span>'
|
|
1077
|
+
* ```
|
|
1078
|
+
* @example
|
|
1079
|
+
* This example creates a Provider context into which a default Store is
|
|
1080
|
+
* provided. A component within it then uses the useValues hook.
|
|
1081
|
+
*
|
|
1082
|
+
* ```jsx
|
|
1083
|
+
* const App = ({store}) => (
|
|
1084
|
+
* <Provider store={store}>
|
|
1085
|
+
* <Pane />
|
|
1086
|
+
* </Provider>
|
|
1087
|
+
* );
|
|
1088
|
+
* const Pane = () => <span>{JSON.stringify(useValues())}</span>;
|
|
1089
|
+
*
|
|
1090
|
+
* const store = createStore().setValue('open', true);
|
|
1091
|
+
* const app = document.createElement('div');
|
|
1092
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1093
|
+
* console.log(app.innerHTML);
|
|
1094
|
+
* // -> '<span>{"open":true}</span>'
|
|
1095
|
+
* ```
|
|
1096
|
+
* @example
|
|
1097
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
1098
|
+
* by Id. A component within it then uses the useValues hook.
|
|
1099
|
+
*
|
|
1100
|
+
* ```jsx
|
|
1101
|
+
* const App = ({store}) => (
|
|
1102
|
+
* <Provider storesById={{petStore: store}}>
|
|
1103
|
+
* <Pane />
|
|
1104
|
+
* </Provider>
|
|
1105
|
+
* );
|
|
1106
|
+
* const Pane = () => <span>{JSON.stringify(useValues('petStore'))}</span>;
|
|
1107
|
+
*
|
|
1108
|
+
* const store = createStore().setValue('open', true);
|
|
1109
|
+
* const app = document.createElement('div');
|
|
1110
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1111
|
+
* console.log(app.innerHTML);
|
|
1112
|
+
* // -> '<span>{"open":true}</span>'
|
|
1113
|
+
* ```
|
|
1114
|
+
* @category Store hooks
|
|
1115
|
+
* @since v3.0.0
|
|
1116
|
+
*/
|
|
1117
|
+
export function useValues(storeOrStoreId?: StoreOrStoreId): Values;
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* The useValueIds hook returns the Ids of every Value in a Store, and registers
|
|
1121
|
+
* a listener so that any changes to that result will cause a re-render.
|
|
1122
|
+
*
|
|
1123
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
1124
|
+
* it can contain a default Store or a set of Store objects named by Id. The
|
|
1125
|
+
* useValueIds hook lets you indicate which Store to get data for: omit the
|
|
1126
|
+
* optional parameter for the default context Store, provide an Id for a named
|
|
1127
|
+
* context Store, or provide a Store explicitly by reference.
|
|
1128
|
+
*
|
|
1129
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
1130
|
+
* Value Ids will cause a re-render. When the component containing this hook is
|
|
1131
|
+
* unmounted, the listener will be automatically removed.
|
|
1132
|
+
*
|
|
1133
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
1134
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1135
|
+
* reference.
|
|
1136
|
+
* @returns An array of the Ids of every Value in the Store.
|
|
1137
|
+
* @example
|
|
1138
|
+
* This example creates a Store outside the application, which is used in the
|
|
1139
|
+
* useValueIds hook by reference. A change to the data in the Store re-renders
|
|
1140
|
+
* the component.
|
|
1141
|
+
*
|
|
1142
|
+
* ```jsx
|
|
1143
|
+
* const store = createStore().setValue('open', true);
|
|
1144
|
+
* const App = () => <span>{JSON.stringify(useValueIds(store))}</span>;
|
|
1145
|
+
*
|
|
1146
|
+
* const app = document.createElement('div');
|
|
1147
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
1148
|
+
* console.log(app.innerHTML);
|
|
1149
|
+
* // -> '<span>["open"]</span>'
|
|
1150
|
+
*
|
|
1151
|
+
* store.setValue('employees', 3); // !act
|
|
1152
|
+
* console.log(app.innerHTML);
|
|
1153
|
+
* // -> '<span>["open","employees"]</span>'
|
|
1154
|
+
* ```
|
|
1155
|
+
* @example
|
|
1156
|
+
* This example creates a Provider context into which a default Store is
|
|
1157
|
+
* provided. A component within it then uses the useValueIds hook.
|
|
1158
|
+
*
|
|
1159
|
+
* ```jsx
|
|
1160
|
+
* const App = ({store}) => (
|
|
1161
|
+
* <Provider store={store}>
|
|
1162
|
+
* <Pane />
|
|
1163
|
+
* </Provider>
|
|
1164
|
+
* );
|
|
1165
|
+
* const Pane = () => <span>{JSON.stringify(useValueIds())}</span>;
|
|
1166
|
+
*
|
|
1167
|
+
* const store = createStore().setValue('open', true);
|
|
1168
|
+
* const app = document.createElement('div');
|
|
1169
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1170
|
+
* console.log(app.innerHTML);
|
|
1171
|
+
* // -> '<span>["open"]</span>'
|
|
1172
|
+
* ```
|
|
1173
|
+
* @example
|
|
1174
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
1175
|
+
* by Id. A component within it then uses the useValueIds hook.
|
|
1176
|
+
*
|
|
1177
|
+
* ```jsx
|
|
1178
|
+
* const App = ({store}) => (
|
|
1179
|
+
* <Provider storesById={{petStore: store}}>
|
|
1180
|
+
* <Pane />
|
|
1181
|
+
* </Provider>
|
|
1182
|
+
* );
|
|
1183
|
+
* const Pane = () => <span>{JSON.stringify(useValueIds('petStore'))}</span>;
|
|
1184
|
+
*
|
|
1185
|
+
* const store = createStore().setValue('open', true);
|
|
1186
|
+
* const app = document.createElement('div');
|
|
1187
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1188
|
+
* console.log(app.innerHTML);
|
|
1189
|
+
* // -> '<span>["open"]</span>'
|
|
1190
|
+
* ```
|
|
1191
|
+
* @category Store hooks
|
|
1192
|
+
* @since v3.0.0
|
|
1193
|
+
*/
|
|
1194
|
+
export function useValueIds(storeOrStoreId?: StoreOrStoreId): Ids;
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* The useValue hook returns an object containing the data of a single Value in
|
|
1198
|
+
* a Store, and registers a listener so that any changes to that result will
|
|
1199
|
+
* cause a re-render.
|
|
1200
|
+
*
|
|
1201
|
+
* A Provider component is used to wrap part of an application in a context, and
|
|
1202
|
+
* it can contain a default Store or a set of Store objects named by Id. The
|
|
1203
|
+
* useValue hook lets you indicate which Store to get data for: omit the final
|
|
1204
|
+
* optional final parameter for the default context Store, provide an Id for a
|
|
1205
|
+
* named context Store, or provide a Store explicitly by reference.
|
|
1206
|
+
*
|
|
1207
|
+
* When first rendered, this hook will create a listener so that changes to the
|
|
1208
|
+
* Value will cause a re-render. When the component containing this hook is
|
|
1209
|
+
* unmounted, the listener will be automatically removed.
|
|
1210
|
+
*
|
|
1211
|
+
* @param valueId The Id of the Value in the Store.
|
|
1212
|
+
* @param storeOrStoreId The Store to be accessed: omit for the default context
|
|
1213
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1214
|
+
* reference.
|
|
1215
|
+
* @returns An object containing the entire data of the Value.
|
|
1216
|
+
* @example
|
|
1217
|
+
* This example creates a Store outside the application, which is used in the
|
|
1218
|
+
* useValue hook by reference. A change to the data in the Store re-renders the
|
|
1219
|
+
* component.
|
|
1220
|
+
*
|
|
1221
|
+
* ```jsx
|
|
1222
|
+
* const store = createStore().setValue('open', true);
|
|
1223
|
+
* const App = () => <span>{JSON.stringify(useValue('open', store))}</span>;
|
|
1224
|
+
*
|
|
1225
|
+
* const app = document.createElement('div');
|
|
1226
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
1227
|
+
* console.log(app.innerHTML);
|
|
1228
|
+
* // -> '<span>true</span>'
|
|
1229
|
+
*
|
|
1230
|
+
* store.setValue('open', false); // !act
|
|
1231
|
+
* console.log(app.innerHTML);
|
|
1232
|
+
* // -> '<span>false</span>'
|
|
1233
|
+
* ```
|
|
1234
|
+
* @example
|
|
1235
|
+
* This example creates a Provider context into which a default Store is
|
|
1236
|
+
* provided. A component within it then uses the useValue hook.
|
|
1237
|
+
*
|
|
1238
|
+
* ```jsx
|
|
1239
|
+
* const App = ({store}) => (
|
|
1240
|
+
* <Provider store={store}>
|
|
1241
|
+
* <Pane />
|
|
1242
|
+
* </Provider>
|
|
1243
|
+
* );
|
|
1244
|
+
* const Pane = () => <span>{JSON.stringify(useValue('open'))}</span>;
|
|
1245
|
+
*
|
|
1246
|
+
* const store = createStore().setValue('open', true);
|
|
1247
|
+
* const app = document.createElement('div');
|
|
1248
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1249
|
+
* console.log(app.innerHTML);
|
|
1250
|
+
* // -> '<span>true</span>'
|
|
1251
|
+
* ```
|
|
1252
|
+
* @example
|
|
1253
|
+
* This example creates a Provider context into which a Store is provided, named
|
|
1254
|
+
* by Id. A component within it then uses the useValue hook.
|
|
1255
|
+
*
|
|
1256
|
+
* ```jsx
|
|
1257
|
+
* const App = ({store}) => (
|
|
1258
|
+
* <Provider storesById={{petStore: store}}>
|
|
1259
|
+
* <Pane />
|
|
1260
|
+
* </Provider>
|
|
1261
|
+
* );
|
|
1262
|
+
* const Pane = () => (
|
|
1263
|
+
* <span>{JSON.stringify(useValue('open', 'petStore'))}</span>
|
|
1264
|
+
* );
|
|
1265
|
+
*
|
|
1266
|
+
* const store = createStore().setValue('open', true);
|
|
1267
|
+
* const app = document.createElement('div');
|
|
1268
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
1269
|
+
* console.log(app.innerHTML);
|
|
1270
|
+
* // -> '<span>true</span>'
|
|
1271
|
+
* ```
|
|
1272
|
+
* @category Store hooks
|
|
1273
|
+
* @since v3.0.0
|
|
1274
|
+
*/
|
|
1275
|
+
export function useValue(valueId: Id, storeOrStoreId?: StoreOrStoreId): Value;
|
|
1276
|
+
|
|
1035
1277
|
/**
|
|
1036
1278
|
* The useSetTablesCallback hook returns a parameterized callback that can be
|
|
1037
|
-
* used to set the
|
|
1279
|
+
* used to set the tabular data of a Store.
|
|
1038
1280
|
*
|
|
1039
1281
|
* This hook is useful, for example, when creating an event handler that will
|
|
1040
|
-
* mutate the data in Store. In this case, the parameter will likely be the
|
|
1282
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1041
1283
|
* event, so that you can use data from it as part of the mutation.
|
|
1042
1284
|
*
|
|
1043
1285
|
* The first parameter is a function which will produce the Tables object that
|
|
@@ -1117,10 +1359,10 @@ export function useSetTablesCallback<Parameter>(
|
|
|
1117
1359
|
|
|
1118
1360
|
/**
|
|
1119
1361
|
* The useSetTableCallback hook returns a parameterized callback that can be
|
|
1120
|
-
* used to set the
|
|
1362
|
+
* used to set the data of a single Table in a Store.
|
|
1121
1363
|
*
|
|
1122
1364
|
* This hook is useful, for example, when creating an event handler that will
|
|
1123
|
-
* mutate the data in Store. In this case, the parameter will likely be the
|
|
1365
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1124
1366
|
* event, so that you can use data from it as part of the mutation.
|
|
1125
1367
|
*
|
|
1126
1368
|
* The second parameter is a function which will produce the Table object that
|
|
@@ -1203,10 +1445,10 @@ export function useSetTableCallback<Parameter>(
|
|
|
1203
1445
|
|
|
1204
1446
|
/**
|
|
1205
1447
|
* The useSetRowCallback hook returns a parameterized callback that can be used
|
|
1206
|
-
* to set the
|
|
1448
|
+
* to set the data of a single Row in a Store.
|
|
1207
1449
|
*
|
|
1208
1450
|
* This hook is useful, for example, when creating an event handler that will
|
|
1209
|
-
* mutate the data in Store. In this case, the parameter will likely be the
|
|
1451
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1210
1452
|
* event, so that you can use data from it as part of the mutation.
|
|
1211
1453
|
*
|
|
1212
1454
|
* The third parameter is a function which will produce the Row object that will
|
|
@@ -1295,7 +1537,7 @@ export function useSetRowCallback<Parameter>(
|
|
|
1295
1537
|
* to create a new Row in a Store.
|
|
1296
1538
|
*
|
|
1297
1539
|
* This hook is useful, for example, when creating an event handler that will
|
|
1298
|
-
* mutate the data in Store. In this case, the parameter will likely be the
|
|
1540
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1299
1541
|
* event, so that you can use data from it as part of the mutation.
|
|
1300
1542
|
*
|
|
1301
1543
|
* The second parameter is a function which will produce the Row object that
|
|
@@ -1378,7 +1620,7 @@ export function useAddRowCallback<Parameter>(
|
|
|
1378
1620
|
|
|
1379
1621
|
/**
|
|
1380
1622
|
* The useSetPartialRowCallback hook returns a parameterized callback that can
|
|
1381
|
-
* be used to
|
|
1623
|
+
* be used to set partial data of a single Row in the Store, leaving other Cell
|
|
1382
1624
|
* values unaffected.
|
|
1383
1625
|
*
|
|
1384
1626
|
* This hook is useful, for example, when creating an event handler that will
|
|
@@ -1472,7 +1714,7 @@ export function useSetPartialRowCallback<Parameter>(
|
|
|
1472
1714
|
* to set the value of a single Cell in a Store.
|
|
1473
1715
|
*
|
|
1474
1716
|
* This hook is useful, for example, when creating an event handler that will
|
|
1475
|
-
* mutate the data in Store. In this case, the parameter will likely be the
|
|
1717
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1476
1718
|
* event, so that you can use data from it as part of the mutation.
|
|
1477
1719
|
*
|
|
1478
1720
|
* The fourth parameter is a function which will produce the Cell object that
|
|
@@ -1597,43 +1839,61 @@ export function useSetCellCallback<Parameter>(
|
|
|
1597
1839
|
): ParameterizedCallback<Parameter>;
|
|
1598
1840
|
|
|
1599
1841
|
/**
|
|
1600
|
-
* The
|
|
1601
|
-
*
|
|
1842
|
+
* The useSetValuesCallback hook returns a parameterized callback that can be
|
|
1843
|
+
* used to set the keyed value data of a Store.
|
|
1602
1844
|
*
|
|
1603
1845
|
* This hook is useful, for example, when creating an event handler that will
|
|
1604
|
-
*
|
|
1846
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1847
|
+
* event, so that you can use data from it as part of the mutation.
|
|
1848
|
+
*
|
|
1849
|
+
* The first parameter is a function which will produce the Values object that
|
|
1850
|
+
* will then be used to update the Store in the callback.
|
|
1851
|
+
*
|
|
1852
|
+
* If that function has any other dependencies, the changing of which should
|
|
1853
|
+
* also cause the callback to be recreated, you can provide them in an array in
|
|
1854
|
+
* the optional second parameter, just as you would for any React hook with
|
|
1855
|
+
* dependencies.
|
|
1605
1856
|
*
|
|
1606
1857
|
* For convenience, you can optionally provide a `then` function (with its own
|
|
1607
1858
|
* set of dependencies) which will be called just after the Store has been
|
|
1608
1859
|
* updated. This is a useful place to call the addCheckpoint method, for
|
|
1609
|
-
* example, if you wish to add the
|
|
1860
|
+
* example, if you wish to add the mutation to your application's undo stack.
|
|
1610
1861
|
*
|
|
1611
|
-
* The Store to which the callback will make the
|
|
1862
|
+
* The Store to which the callback will make the mutation (indicated by the
|
|
1612
1863
|
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
1613
1864
|
* dependency for the callback.
|
|
1614
1865
|
*
|
|
1866
|
+
* @param getValues A function which returns the Values object that will be used
|
|
1867
|
+
* to update the Store, based on the parameter the callback will receive (and
|
|
1868
|
+
* which is most likely a DOM event).
|
|
1869
|
+
* @param getValuesDeps An optional array of dependencies for the `getValues`
|
|
1870
|
+
* function, which, if any change, result in the regeneration of the callback.
|
|
1871
|
+
* This parameter defaults to an empty array.
|
|
1615
1872
|
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
1616
1873
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1617
1874
|
* reference.
|
|
1618
|
-
* @param then A function which is called after the
|
|
1619
|
-
* to the Store.
|
|
1875
|
+
* @param then A function which is called after the mutation, with a reference
|
|
1876
|
+
* to the Store and the Values used in the update.
|
|
1620
1877
|
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
1621
1878
|
* which, if any change, result in the regeneration of the callback. This
|
|
1622
1879
|
* parameter defaults to an empty array.
|
|
1623
|
-
* @returns A callback for subsequent use.
|
|
1880
|
+
* @returns A parameterized callback for subsequent use.
|
|
1624
1881
|
* @example
|
|
1625
|
-
* This example uses the
|
|
1626
|
-
* which
|
|
1882
|
+
* This example uses the useSetValuesCallback hook to create an event handler
|
|
1883
|
+
* which updates the Store when the `span` element is clicked.
|
|
1627
1884
|
*
|
|
1628
1885
|
* ```jsx
|
|
1629
|
-
* const store = createStore().
|
|
1886
|
+
* const store = createStore().setValues({open: true});
|
|
1630
1887
|
* const App = () => {
|
|
1631
|
-
* const handleClick =
|
|
1632
|
-
*
|
|
1888
|
+
* const handleClick = useSetValuesCallback(
|
|
1889
|
+
* (e) => ({bubbles: e.bubbles}),
|
|
1890
|
+
* [],
|
|
1891
|
+
* store,
|
|
1892
|
+
* (store, values) => console.log(`Updated: ${JSON.stringify(values)}`),
|
|
1633
1893
|
* );
|
|
1634
1894
|
* return (
|
|
1635
1895
|
* <span id="span" onClick={handleClick}>
|
|
1636
|
-
* {JSON.stringify(
|
|
1896
|
+
* {JSON.stringify(useValues(store))}
|
|
1637
1897
|
* </span>
|
|
1638
1898
|
* );
|
|
1639
1899
|
* };
|
|
@@ -1642,62 +1902,301 @@ export function useSetCellCallback<Parameter>(
|
|
|
1642
1902
|
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
1643
1903
|
* const span = app.querySelector('span');
|
|
1644
1904
|
* console.log(span.innerHTML);
|
|
1645
|
-
* // -> '{"
|
|
1905
|
+
* // -> '{"open":true}'
|
|
1646
1906
|
*
|
|
1647
1907
|
* // User clicks the <span> element:
|
|
1648
1908
|
* // -> span MouseEvent('click', {bubbles: true})
|
|
1649
|
-
* // -> '
|
|
1909
|
+
* // -> 'Updated: {"bubbles":true}'
|
|
1650
1910
|
*
|
|
1651
1911
|
* console.log(span.innerHTML);
|
|
1652
|
-
* // -> '{}'
|
|
1912
|
+
* // -> '{"bubbles":true}'
|
|
1653
1913
|
* ```
|
|
1654
1914
|
* @category Store hooks
|
|
1915
|
+
* @since v3.0.0
|
|
1655
1916
|
*/
|
|
1656
|
-
export function
|
|
1917
|
+
export function useSetValuesCallback<Parameter>(
|
|
1918
|
+
getValues: (parameter: Parameter, store: Store) => Values,
|
|
1919
|
+
getValuesDeps?: React.DependencyList,
|
|
1657
1920
|
storeOrStoreId?: StoreOrStoreId,
|
|
1658
|
-
then?: (store: Store) => void,
|
|
1921
|
+
then?: (store: Store, values: Values) => void,
|
|
1659
1922
|
thenDeps?: React.DependencyList,
|
|
1660
|
-
):
|
|
1923
|
+
): ParameterizedCallback<Parameter>;
|
|
1661
1924
|
|
|
1662
1925
|
/**
|
|
1663
|
-
* The
|
|
1664
|
-
*
|
|
1926
|
+
* The useSetPartialValuesCallback hook returns a parameterized callback that
|
|
1927
|
+
* can be used to set partial Values data in the Store, leaving other Values
|
|
1928
|
+
* unaffected.
|
|
1665
1929
|
*
|
|
1666
1930
|
* This hook is useful, for example, when creating an event handler that will
|
|
1667
|
-
*
|
|
1931
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
1932
|
+
* event, so that you can use data from it as part of the mutation.
|
|
1933
|
+
*
|
|
1934
|
+
* The third parameter is a function which will produce the partial Values
|
|
1935
|
+
* object that will then be used to update the Store in the callback.
|
|
1936
|
+
*
|
|
1937
|
+
* If that function has any other dependencies, the changing of which should
|
|
1938
|
+
* also cause the callback to be recreated, you can provide them in an array in
|
|
1939
|
+
* the optional fourth parameter, just as you would for any React hook with
|
|
1940
|
+
* dependencies.
|
|
1668
1941
|
*
|
|
1669
1942
|
* For convenience, you can optionally provide a `then` function (with its own
|
|
1670
1943
|
* set of dependencies) which will be called just after the Store has been
|
|
1671
1944
|
* updated. This is a useful place to call the addCheckpoint method, for
|
|
1672
|
-
* example, if you wish to add the
|
|
1945
|
+
* example, if you wish to add the mutation to your application's undo stack.
|
|
1673
1946
|
*
|
|
1674
|
-
* The Store to which the callback will make the
|
|
1947
|
+
* The Store to which the callback will make the mutation (indicated by the
|
|
1675
1948
|
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
1676
1949
|
* dependency for the callback.
|
|
1677
1950
|
*
|
|
1678
|
-
* @param
|
|
1951
|
+
* @param getPartialValues A function which returns the partial Values object
|
|
1952
|
+
* that will be used to update the Store, based on the parameter the callback
|
|
1953
|
+
* will receive (and which is most likely a DOM event).
|
|
1954
|
+
* @param getPartialValuesDeps An optional array of dependencies for the
|
|
1955
|
+
* `getValues` function, which, if any change, result in the regeneration of the
|
|
1956
|
+
* callback. This parameter defaults to an empty array.
|
|
1679
1957
|
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
1680
1958
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1681
1959
|
* reference.
|
|
1682
|
-
* @param then A function which is called after the
|
|
1683
|
-
* to the Store.
|
|
1960
|
+
* @param then A function which is called after the mutation, with a reference
|
|
1961
|
+
* to the Store and the Values used in the update.
|
|
1684
1962
|
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
1685
1963
|
* which, if any change, result in the regeneration of the callback. This
|
|
1686
1964
|
* parameter defaults to an empty array.
|
|
1687
|
-
* @returns A callback for subsequent use.
|
|
1965
|
+
* @returns A parameterized callback for subsequent use.
|
|
1688
1966
|
* @example
|
|
1689
|
-
* This example uses the
|
|
1690
|
-
* which
|
|
1967
|
+
* This example uses the useSetPartialValuesCallback hook to create an event
|
|
1968
|
+
* handler which updates the Store when the `span` element is clicked.
|
|
1691
1969
|
*
|
|
1692
1970
|
* ```jsx
|
|
1693
|
-
* const store = createStore().
|
|
1971
|
+
* const store = createStore().setValues({open: true});
|
|
1694
1972
|
* const App = () => {
|
|
1695
|
-
* const handleClick =
|
|
1696
|
-
*
|
|
1973
|
+
* const handleClick = useSetPartialValuesCallback(
|
|
1974
|
+
* (e) => ({bubbles: e.bubbles}),
|
|
1975
|
+
* [],
|
|
1976
|
+
* store,
|
|
1977
|
+
* (store, partialValues) =>
|
|
1978
|
+
* console.log(`Updated: ${JSON.stringify(partialValues)}`),
|
|
1697
1979
|
* );
|
|
1698
1980
|
* return (
|
|
1699
1981
|
* <span id="span" onClick={handleClick}>
|
|
1700
|
-
* {JSON.stringify(
|
|
1982
|
+
* {JSON.stringify(useValues(store))}
|
|
1983
|
+
* </span>
|
|
1984
|
+
* );
|
|
1985
|
+
* };
|
|
1986
|
+
*
|
|
1987
|
+
* const app = document.createElement('div');
|
|
1988
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
1989
|
+
* const span = app.querySelector('span');
|
|
1990
|
+
* console.log(span.innerHTML);
|
|
1991
|
+
* // -> '{"open":true}'
|
|
1992
|
+
*
|
|
1993
|
+
* // User clicks the <span> element:
|
|
1994
|
+
* // -> span MouseEvent('click', {bubbles: true})
|
|
1995
|
+
* // -> 'Updated: {"bubbles":true}'
|
|
1996
|
+
*
|
|
1997
|
+
* console.log(span.innerHTML);
|
|
1998
|
+
* // -> '{"open":true,"bubbles":true}'
|
|
1999
|
+
* ```
|
|
2000
|
+
* @category Store hooks
|
|
2001
|
+
* @since v3.0.0
|
|
2002
|
+
*/
|
|
2003
|
+
export function useSetPartialValuesCallback<Parameter>(
|
|
2004
|
+
getPartialValues: (parameter: Parameter, store: Store) => Values,
|
|
2005
|
+
getPartialValuesDeps?: React.DependencyList,
|
|
2006
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2007
|
+
then?: (store: Store, partialValues: Values) => void,
|
|
2008
|
+
thenDeps?: React.DependencyList,
|
|
2009
|
+
): ParameterizedCallback<Parameter>;
|
|
2010
|
+
|
|
2011
|
+
/**
|
|
2012
|
+
* The useSetValueCallback hook returns a parameterized callback that can be
|
|
2013
|
+
* used to set the data of a single Value in a Store.
|
|
2014
|
+
*
|
|
2015
|
+
* This hook is useful, for example, when creating an event handler that will
|
|
2016
|
+
* mutate the data in the Store. In this case, the parameter will likely be the
|
|
2017
|
+
* event, so that you can use data from it as part of the mutation.
|
|
2018
|
+
*
|
|
2019
|
+
* The second parameter is a function which will produce the Value object that
|
|
2020
|
+
* will then be used to update the Store in the callback.
|
|
2021
|
+
*
|
|
2022
|
+
* If that function has any other dependencies, the changing of which should
|
|
2023
|
+
* also cause the callback to be recreated, you can provide them in an array in
|
|
2024
|
+
* the optional third parameter, just as you would for any React hook with
|
|
2025
|
+
* dependencies.
|
|
2026
|
+
*
|
|
2027
|
+
* For convenience, you can optionally provide a `then` function (with its own
|
|
2028
|
+
* set of dependencies) which will be called just after the Store has been
|
|
2029
|
+
* updated. This is a useful place to call the addCheckpoint method, for
|
|
2030
|
+
* example, if you wish to add the mutation to your application's undo stack.
|
|
2031
|
+
*
|
|
2032
|
+
* The Store to which the callback will make the mutation (indicated by the
|
|
2033
|
+
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
2034
|
+
* dependency for the callback.
|
|
2035
|
+
*
|
|
2036
|
+
* @param valueId The Id of the Value in the Store to set.
|
|
2037
|
+
* @param getValue A function which returns the Value object that will be used
|
|
2038
|
+
* to update the Store, based on the parameter the callback will receive (and
|
|
2039
|
+
* which is most likely a DOM event).
|
|
2040
|
+
* @param getValueDeps An optional array of dependencies for the `getValue`
|
|
2041
|
+
* function, which, if any change, result in the regeneration of the callback.
|
|
2042
|
+
* This parameter defaults to an empty array.
|
|
2043
|
+
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
2044
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
2045
|
+
* reference.
|
|
2046
|
+
* @param then A function which is called after the mutation, with a reference
|
|
2047
|
+
* to the Store and the Value used in the update.
|
|
2048
|
+
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
2049
|
+
* which, if any change, result in the regeneration of the callback. This
|
|
2050
|
+
* parameter defaults to an empty array.
|
|
2051
|
+
* @returns A parameterized callback for subsequent use.
|
|
2052
|
+
* @example
|
|
2053
|
+
* This example uses the useSetValueCallback hook to create an event handler
|
|
2054
|
+
* which updates the Store when the `span` element is clicked.
|
|
2055
|
+
*
|
|
2056
|
+
* ```jsx
|
|
2057
|
+
* const store = createStore().setValue('open', true);
|
|
2058
|
+
* const App = () => {
|
|
2059
|
+
* const handleClick = useSetValueCallback(
|
|
2060
|
+
* 'bubbles',
|
|
2061
|
+
* (e) => e.bubbles,
|
|
2062
|
+
* [],
|
|
2063
|
+
* store,
|
|
2064
|
+
* (store, value) => console.log(`Updated: ${JSON.stringify(value)}`),
|
|
2065
|
+
* );
|
|
2066
|
+
* return (
|
|
2067
|
+
* <span id="span" onClick={handleClick}>
|
|
2068
|
+
* {JSON.stringify(useValues(store))}
|
|
2069
|
+
* </span>
|
|
2070
|
+
* );
|
|
2071
|
+
* };
|
|
2072
|
+
*
|
|
2073
|
+
* const app = document.createElement('div');
|
|
2074
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
2075
|
+
* const span = app.querySelector('span');
|
|
2076
|
+
* console.log(span.innerHTML);
|
|
2077
|
+
* // -> '{"open":true}'
|
|
2078
|
+
*
|
|
2079
|
+
* // User clicks the <span> element:
|
|
2080
|
+
* // -> span MouseEvent('click', {bubbles: true})
|
|
2081
|
+
* // -> 'Updated: true'
|
|
2082
|
+
*
|
|
2083
|
+
* console.log(span.innerHTML);
|
|
2084
|
+
* // -> '{"open":true,"bubbles":true}'
|
|
2085
|
+
* ```
|
|
2086
|
+
* @category Store hooks
|
|
2087
|
+
* @since v3.0.0
|
|
2088
|
+
*/
|
|
2089
|
+
export function useSetValueCallback<Parameter>(
|
|
2090
|
+
valueId: Id,
|
|
2091
|
+
getValue: (parameter: Parameter, store: Store) => Value,
|
|
2092
|
+
getValueDeps?: React.DependencyList,
|
|
2093
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2094
|
+
then?: (store: Store, value: Value) => void,
|
|
2095
|
+
thenDeps?: React.DependencyList,
|
|
2096
|
+
): ParameterizedCallback<Parameter>;
|
|
2097
|
+
|
|
2098
|
+
/**
|
|
2099
|
+
* The useDelTablesCallback hook returns a callback that can be used to remove
|
|
2100
|
+
* all of the tabular data in a Store.
|
|
2101
|
+
*
|
|
2102
|
+
* This hook is useful, for example, when creating an event handler that will
|
|
2103
|
+
* delete data in a Store.
|
|
2104
|
+
*
|
|
2105
|
+
* For convenience, you can optionally provide a `then` function (with its own
|
|
2106
|
+
* set of dependencies) which will be called just after the Store has been
|
|
2107
|
+
* updated. This is a useful place to call the addCheckpoint method, for
|
|
2108
|
+
* example, if you wish to add the deletion to your application's undo stack.
|
|
2109
|
+
*
|
|
2110
|
+
* The Store to which the callback will make the deletion (indicated by the
|
|
2111
|
+
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
2112
|
+
* dependency for the callback.
|
|
2113
|
+
*
|
|
2114
|
+
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
2115
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
2116
|
+
* reference.
|
|
2117
|
+
* @param then A function which is called after the deletion, with a reference
|
|
2118
|
+
* to the Store.
|
|
2119
|
+
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
2120
|
+
* which, if any change, result in the regeneration of the callback. This
|
|
2121
|
+
* parameter defaults to an empty array.
|
|
2122
|
+
* @returns A callback for subsequent use.
|
|
2123
|
+
* @example
|
|
2124
|
+
* This example uses the useDelTablesCallback hook to create an event handler
|
|
2125
|
+
* which deletes from the Store when the `span` element is clicked.
|
|
2126
|
+
*
|
|
2127
|
+
* ```jsx
|
|
2128
|
+
* const store = createStore().setTables({pets: {nemo: {species: 'fish'}}});
|
|
2129
|
+
* const App = () => {
|
|
2130
|
+
* const handleClick = useDelTablesCallback(store, () =>
|
|
2131
|
+
* console.log('Deleted'),
|
|
2132
|
+
* );
|
|
2133
|
+
* return (
|
|
2134
|
+
* <span id="span" onClick={handleClick}>
|
|
2135
|
+
* {JSON.stringify(useTables(store))}
|
|
2136
|
+
* </span>
|
|
2137
|
+
* );
|
|
2138
|
+
* };
|
|
2139
|
+
*
|
|
2140
|
+
* const app = document.createElement('div');
|
|
2141
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
2142
|
+
* const span = app.querySelector('span');
|
|
2143
|
+
* console.log(span.innerHTML);
|
|
2144
|
+
* // -> '{"pets":{"nemo":{"species":"fish"}}}'
|
|
2145
|
+
*
|
|
2146
|
+
* // User clicks the <span> element:
|
|
2147
|
+
* // -> span MouseEvent('click', {bubbles: true})
|
|
2148
|
+
* // -> 'Deleted'
|
|
2149
|
+
*
|
|
2150
|
+
* console.log(span.innerHTML);
|
|
2151
|
+
* // -> '{}'
|
|
2152
|
+
* ```
|
|
2153
|
+
* @category Store hooks
|
|
2154
|
+
*/
|
|
2155
|
+
export function useDelTablesCallback(
|
|
2156
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2157
|
+
then?: (store: Store) => void,
|
|
2158
|
+
thenDeps?: React.DependencyList,
|
|
2159
|
+
): Callback;
|
|
2160
|
+
|
|
2161
|
+
/**
|
|
2162
|
+
* The useDelTableCallback hook returns a callback that can be used to remove a
|
|
2163
|
+
* single Table from a Store.
|
|
2164
|
+
*
|
|
2165
|
+
* This hook is useful, for example, when creating an event handler that will
|
|
2166
|
+
* delete data in a Store.
|
|
2167
|
+
*
|
|
2168
|
+
* For convenience, you can optionally provide a `then` function (with its own
|
|
2169
|
+
* set of dependencies) which will be called just after the Store has been
|
|
2170
|
+
* updated. This is a useful place to call the addCheckpoint method, for
|
|
2171
|
+
* example, if you wish to add the deletion to your application's undo stack.
|
|
2172
|
+
*
|
|
2173
|
+
* The Store to which the callback will make the deletion (indicated by the
|
|
2174
|
+
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
2175
|
+
* dependency for the callback.
|
|
2176
|
+
*
|
|
2177
|
+
* @param tableId The Id of the Table in the Store.
|
|
2178
|
+
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
2179
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
2180
|
+
* reference.
|
|
2181
|
+
* @param then A function which is called after the deletion, with a reference
|
|
2182
|
+
* to the Store.
|
|
2183
|
+
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
2184
|
+
* which, if any change, result in the regeneration of the callback. This
|
|
2185
|
+
* parameter defaults to an empty array.
|
|
2186
|
+
* @returns A callback for subsequent use.
|
|
2187
|
+
* @example
|
|
2188
|
+
* This example uses the useDelTableCallback hook to create an event handler
|
|
2189
|
+
* which deletes from the Store when the `span` element is clicked.
|
|
2190
|
+
*
|
|
2191
|
+
* ```jsx
|
|
2192
|
+
* const store = createStore().setTables({pets: {nemo: {species: 'fish'}}});
|
|
2193
|
+
* const App = () => {
|
|
2194
|
+
* const handleClick = useDelTableCallback('pets', store, () =>
|
|
2195
|
+
* console.log('Deleted'),
|
|
2196
|
+
* );
|
|
2197
|
+
* return (
|
|
2198
|
+
* <span id="span" onClick={handleClick}>
|
|
2199
|
+
* {JSON.stringify(useTables(store))}
|
|
1701
2200
|
* </span>
|
|
1702
2201
|
* );
|
|
1703
2202
|
* };
|
|
@@ -1811,8 +2310,8 @@ export function useDelRowCallback(
|
|
|
1811
2310
|
* @param rowId The Id of the Row in the Table.
|
|
1812
2311
|
* @param cellId The Id of the Cell in the Row.
|
|
1813
2312
|
* @param forceDel An optional flag to indicate that the whole Row should be
|
|
1814
|
-
* deleted, even if a
|
|
1815
|
-
* `false`.
|
|
2313
|
+
* deleted, even if a TablesSchema provides a default value for this Cell.
|
|
2314
|
+
* Defaults to `false`.
|
|
1816
2315
|
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
1817
2316
|
* Store, provide an Id for a named context Store, or provide an explicit
|
|
1818
2317
|
* reference.
|
|
@@ -1869,9 +2368,139 @@ export function useDelCellCallback(
|
|
|
1869
2368
|
thenDeps?: React.DependencyList,
|
|
1870
2369
|
): Callback;
|
|
1871
2370
|
|
|
2371
|
+
/**
|
|
2372
|
+
* The useDelValuesCallback hook returns a callback that can be used to remove
|
|
2373
|
+
* all of the keyed value data in a Store.
|
|
2374
|
+
*
|
|
2375
|
+
* This hook is useful, for example, when creating an event handler that will
|
|
2376
|
+
* delete data in a Store.
|
|
2377
|
+
*
|
|
2378
|
+
* For convenience, you can optionally provide a `then` function (with its own
|
|
2379
|
+
* set of dependencies) which will be called just after the Store has been
|
|
2380
|
+
* updated. This is a useful place to call the addCheckpoint method, for
|
|
2381
|
+
* example, if you wish to add the deletion to your application's undo stack.
|
|
2382
|
+
*
|
|
2383
|
+
* The Store to which the callback will make the deletion (indicated by the
|
|
2384
|
+
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
2385
|
+
* dependency for the callback.
|
|
2386
|
+
*
|
|
2387
|
+
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
2388
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
2389
|
+
* reference.
|
|
2390
|
+
* @param then A function which is called after the deletion, with a reference
|
|
2391
|
+
* to the Store.
|
|
2392
|
+
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
2393
|
+
* which, if any change, result in the regeneration of the callback. This
|
|
2394
|
+
* parameter defaults to an empty array.
|
|
2395
|
+
* @returns A callback for subsequent use.
|
|
2396
|
+
* @example
|
|
2397
|
+
* This example uses the useDelValuesCallback hook to create an event handler
|
|
2398
|
+
* which deletes from the Store when the `span` element is clicked.
|
|
2399
|
+
*
|
|
2400
|
+
* ```jsx
|
|
2401
|
+
* const store = createStore().setValues({open: true});
|
|
2402
|
+
* const App = () => {
|
|
2403
|
+
* const handleClick = useDelValuesCallback(store, () =>
|
|
2404
|
+
* console.log('Deleted'),
|
|
2405
|
+
* );
|
|
2406
|
+
* return (
|
|
2407
|
+
* <span id="span" onClick={handleClick}>
|
|
2408
|
+
* {JSON.stringify(useValues(store))}
|
|
2409
|
+
* </span>
|
|
2410
|
+
* );
|
|
2411
|
+
* };
|
|
2412
|
+
*
|
|
2413
|
+
* const app = document.createElement('div');
|
|
2414
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
2415
|
+
* const span = app.querySelector('span');
|
|
2416
|
+
* console.log(span.innerHTML);
|
|
2417
|
+
* // -> '{"open":true}'
|
|
2418
|
+
*
|
|
2419
|
+
* // User clicks the <span> element:
|
|
2420
|
+
* // -> span MouseEvent('click', {bubbles: true})
|
|
2421
|
+
* // -> 'Deleted'
|
|
2422
|
+
*
|
|
2423
|
+
* console.log(span.innerHTML);
|
|
2424
|
+
* // -> '{}'
|
|
2425
|
+
* ```
|
|
2426
|
+
* @category Store hooks
|
|
2427
|
+
* @since v3.0.0
|
|
2428
|
+
*/
|
|
2429
|
+
export function useDelValuesCallback(
|
|
2430
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2431
|
+
then?: (store: Store) => void,
|
|
2432
|
+
thenDeps?: React.DependencyList,
|
|
2433
|
+
): Callback;
|
|
2434
|
+
|
|
2435
|
+
/**
|
|
2436
|
+
* The useDelValueCallback hook returns a callback that can be used to remove a
|
|
2437
|
+
* single Value from a Store.
|
|
2438
|
+
*
|
|
2439
|
+
* This hook is useful, for example, when creating an event handler that will
|
|
2440
|
+
* delete data in a Store.
|
|
2441
|
+
*
|
|
2442
|
+
* For convenience, you can optionally provide a `then` function (with its own
|
|
2443
|
+
* set of dependencies) which will be called just after the Store has been
|
|
2444
|
+
* updated. This is a useful place to call the addCheckpoint method, for
|
|
2445
|
+
* example, if you wish to add the deletion to your application's undo stack.
|
|
2446
|
+
*
|
|
2447
|
+
* The Store to which the callback will make the deletion (indicated by the
|
|
2448
|
+
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
|
|
2449
|
+
* dependency for the callback.
|
|
2450
|
+
*
|
|
2451
|
+
* @param valueId The Id of the Value in the Store.
|
|
2452
|
+
* @param storeOrStoreId The Store to be updated: omit for the default context
|
|
2453
|
+
* Store, provide an Id for a named context Store, or provide an explicit
|
|
2454
|
+
* reference.
|
|
2455
|
+
* @param then A function which is called after the deletion, with a reference
|
|
2456
|
+
* to the Store.
|
|
2457
|
+
* @param thenDeps An optional array of dependencies for the `then` function,
|
|
2458
|
+
* which, if any change, result in the regeneration of the callback. This
|
|
2459
|
+
* parameter defaults to an empty array.
|
|
2460
|
+
* @returns A callback for subsequent use.
|
|
2461
|
+
* @example
|
|
2462
|
+
* This example uses the useDelValueCallback hook to create an event handler
|
|
2463
|
+
* which deletes from the Store when the `span` element is clicked.
|
|
2464
|
+
*
|
|
2465
|
+
* ```jsx
|
|
2466
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
2467
|
+
* const App = () => {
|
|
2468
|
+
* const handleClick = useDelValueCallback('open', store, () =>
|
|
2469
|
+
* console.log('Deleted'),
|
|
2470
|
+
* );
|
|
2471
|
+
* return (
|
|
2472
|
+
* <span id="span" onClick={handleClick}>
|
|
2473
|
+
* {JSON.stringify(useValues(store))}
|
|
2474
|
+
* </span>
|
|
2475
|
+
* );
|
|
2476
|
+
* };
|
|
2477
|
+
*
|
|
2478
|
+
* const app = document.createElement('div');
|
|
2479
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
2480
|
+
* const span = app.querySelector('span');
|
|
2481
|
+
* console.log(span.innerHTML);
|
|
2482
|
+
* // -> '{"open":true,"employees":3}'
|
|
2483
|
+
*
|
|
2484
|
+
* // User clicks the <span> element:
|
|
2485
|
+
* // -> span MouseEvent('click', {bubbles: true})
|
|
2486
|
+
* // -> 'Deleted'
|
|
2487
|
+
*
|
|
2488
|
+
* console.log(span.innerHTML);
|
|
2489
|
+
* // -> '{"employees":3}'
|
|
2490
|
+
* ```
|
|
2491
|
+
* @category Store hooks
|
|
2492
|
+
* @since v3.0.0
|
|
2493
|
+
*/
|
|
2494
|
+
export function useDelValueCallback(
|
|
2495
|
+
valueId: Id,
|
|
2496
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2497
|
+
then?: (store: Store) => void,
|
|
2498
|
+
thenDeps?: React.DependencyList,
|
|
2499
|
+
): Callback;
|
|
2500
|
+
|
|
1872
2501
|
/**
|
|
1873
2502
|
* The useTablesListener hook registers a listener function with a Store that
|
|
1874
|
-
* will be called whenever data in it changes.
|
|
2503
|
+
* will be called whenever tabular data in it changes.
|
|
1875
2504
|
*
|
|
1876
2505
|
* This hook is useful for situations where a component needs to register its
|
|
1877
2506
|
* own specific listener to do more than simply tracking the value (which is
|
|
@@ -1882,8 +2511,8 @@ export function useDelCellCallback(
|
|
|
1882
2511
|
* for you: when the listener changes (per its `listenerDeps` dependencies) or
|
|
1883
2512
|
* the component unmounts, the listener on the underlying Store will be deleted.
|
|
1884
2513
|
*
|
|
1885
|
-
* @param listener The function that will be called whenever data in the
|
|
1886
|
-
* changes.
|
|
2514
|
+
* @param listener The function that will be called whenever tabular data in the
|
|
2515
|
+
* Store changes.
|
|
1887
2516
|
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
1888
2517
|
* function, which, if any change, result in the re-registration of the
|
|
1889
2518
|
* listener. This parameter defaults to an empty array.
|
|
@@ -2257,62 +2886,271 @@ export function useSortedRowIdsListener(
|
|
|
2257
2886
|
* </Provider>
|
|
2258
2887
|
* );
|
|
2259
2888
|
* const Pane = () => {
|
|
2260
|
-
* useRowListener('pets', 'fido', () => console.log('Row changed'));
|
|
2889
|
+
* useRowListener('pets', 'fido', () => console.log('Row changed'));
|
|
2890
|
+
* return <span>App</span>;
|
|
2891
|
+
* };
|
|
2892
|
+
*
|
|
2893
|
+
* const store = createStore().setTables({pets: {fido: {color: 'brown'}}});
|
|
2894
|
+
* const app = document.createElement('div');
|
|
2895
|
+
* const root = ReactDOMClient.createRoot(app);
|
|
2896
|
+
* root.render(<App store={store} />); // !act
|
|
2897
|
+
* console.log(store.getListenerStats().row);
|
|
2898
|
+
* // -> 1
|
|
2899
|
+
*
|
|
2900
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
2901
|
+
* // -> 'Row changed'
|
|
2902
|
+
*
|
|
2903
|
+
* root.unmount(); // !act
|
|
2904
|
+
* console.log(store.getListenerStats().row);
|
|
2905
|
+
* // -> 0
|
|
2906
|
+
* ```
|
|
2907
|
+
* @category Store hooks
|
|
2908
|
+
*/
|
|
2909
|
+
export function useRowListener(
|
|
2910
|
+
tableId: IdOrNull,
|
|
2911
|
+
rowId: IdOrNull,
|
|
2912
|
+
listener: RowListener,
|
|
2913
|
+
listenerDeps?: React.DependencyList,
|
|
2914
|
+
mutator?: boolean,
|
|
2915
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2916
|
+
): void;
|
|
2917
|
+
|
|
2918
|
+
/**
|
|
2919
|
+
* The useCellIdsListener hook registers a listener function with a Store that
|
|
2920
|
+
* will be called whenever the Cell Ids in a Row change.
|
|
2921
|
+
*
|
|
2922
|
+
* This hook is useful for situations where a component needs to register its
|
|
2923
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
2924
|
+
* more easily done with the useCellIds hook).
|
|
2925
|
+
*
|
|
2926
|
+
* You can either listen to a single Row (by specifying the Table Id and Row Id
|
|
2927
|
+
* as the method's first two parameters) or changes to any Row (by providing
|
|
2928
|
+
* `null` wildcards).
|
|
2929
|
+
*
|
|
2930
|
+
* Both, either, or neither of the `tableId` and `rowId` parameters can be
|
|
2931
|
+
* wildcarded with `null`. You can listen to a specific Row in a specific Table,
|
|
2932
|
+
* any Row in a specific Table, a specific Row in any Table, or any Row in any
|
|
2933
|
+
* Table.
|
|
2934
|
+
*
|
|
2935
|
+
* Unlike the addCellIdsListener method, which returns a listener Id and
|
|
2936
|
+
* requires you to remove it manually, the useCellIdsListener hook manages this
|
|
2937
|
+
* lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
2938
|
+
* dependencies) or the component unmounts, the listener on the underlying Store
|
|
2939
|
+
* will be deleted.
|
|
2940
|
+
*
|
|
2941
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
2942
|
+
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
2943
|
+
* @param listener The function that will be called whenever the Cell Ids in the
|
|
2944
|
+
* Row change.
|
|
2945
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
2946
|
+
* function, which, if any change, result in the re-registration of the
|
|
2947
|
+
* listener. This parameter defaults to an empty array.
|
|
2948
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
2949
|
+
* Store data.
|
|
2950
|
+
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
2951
|
+
* default context Store, provide an Id for a named context Store, or provide an
|
|
2952
|
+
* explicit reference.
|
|
2953
|
+
* @example
|
|
2954
|
+
* This example uses the useCellIdsListener hook to create a listener that is
|
|
2955
|
+
* scoped to a single component. When the component is unmounted, the listener
|
|
2956
|
+
* is removed from the Store.
|
|
2957
|
+
*
|
|
2958
|
+
* ```jsx
|
|
2959
|
+
* const App = ({store}) => (
|
|
2960
|
+
* <Provider store={store}>
|
|
2961
|
+
* <Pane />
|
|
2962
|
+
* </Provider>
|
|
2963
|
+
* );
|
|
2964
|
+
* const Pane = () => {
|
|
2965
|
+
* useCellIdsListener('pets', 'fido', () =>
|
|
2966
|
+
* console.log('Cell Ids changed'),
|
|
2967
|
+
* );
|
|
2968
|
+
* return <span>App</span>;
|
|
2969
|
+
* };
|
|
2970
|
+
*
|
|
2971
|
+
* const store = createStore().setTables({pets: {fido: {color: 'brown'}}});
|
|
2972
|
+
* const app = document.createElement('div');
|
|
2973
|
+
* const root = ReactDOMClient.createRoot(app);
|
|
2974
|
+
* root.render(<App store={store} />); // !act
|
|
2975
|
+
* console.log(store.getListenerStats().cellIds);
|
|
2976
|
+
* // -> 1
|
|
2977
|
+
*
|
|
2978
|
+
* store.setCell('pets', 'fido', 'species', 'dog'); // !act
|
|
2979
|
+
* // -> 'Cell Ids changed'
|
|
2980
|
+
*
|
|
2981
|
+
* root.unmount(); // !act
|
|
2982
|
+
* console.log(store.getListenerStats().cellIds);
|
|
2983
|
+
* // -> 0
|
|
2984
|
+
* ```
|
|
2985
|
+
* @category Store hooks
|
|
2986
|
+
*/
|
|
2987
|
+
export function useCellIdsListener(
|
|
2988
|
+
tableId: IdOrNull,
|
|
2989
|
+
rowId: IdOrNull,
|
|
2990
|
+
listener: CellIdsListener,
|
|
2991
|
+
listenerDeps?: React.DependencyList,
|
|
2992
|
+
mutator?: boolean,
|
|
2993
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
2994
|
+
): void;
|
|
2995
|
+
|
|
2996
|
+
/**
|
|
2997
|
+
* The useCellListener hook registers a listener function with a Store that will
|
|
2998
|
+
* be called whenever data in a Cell changes.
|
|
2999
|
+
*
|
|
3000
|
+
* This hook is useful for situations where a component needs to register its
|
|
3001
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
3002
|
+
* more easily done with the useCell hook).
|
|
3003
|
+
*
|
|
3004
|
+
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
3005
|
+
* and Cell Id as the method's first three parameters) or changes to any Cell
|
|
3006
|
+
* (by providing `null` wildcards).
|
|
3007
|
+
*
|
|
3008
|
+
* All, some, or none of the `tableId`, `rowId`, and `cellId` parameters can be
|
|
3009
|
+
* wildcarded with `null`. You can listen to a specific Cell in a specific Row
|
|
3010
|
+
* in a specific Table, any Cell in any Row in any Table, for example - or every
|
|
3011
|
+
* other combination of wildcards.
|
|
3012
|
+
*
|
|
3013
|
+
* Unlike the addCellListener method, which returns a listener Id and requires
|
|
3014
|
+
* you to remove it manually, the useCellListener hook manages this lifecycle
|
|
3015
|
+
* for you: when the listener changes (per its `listenerDeps` dependencies) or
|
|
3016
|
+
* the component unmounts, the listener on the underlying Store will be deleted.
|
|
3017
|
+
*
|
|
3018
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
3019
|
+
* @param rowId The Id of the Row to listen to, or `null` as a wildcard.
|
|
3020
|
+
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
3021
|
+
* @param listener The function that will be called whenever data in the Cell
|
|
3022
|
+
* changes.
|
|
3023
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
3024
|
+
* function, which, if any change, result in the re-registration of the
|
|
3025
|
+
* listener. This parameter defaults to an empty array.
|
|
3026
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
3027
|
+
* Store data.
|
|
3028
|
+
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
3029
|
+
* default context Store, provide an Id for a named context Store, or provide an
|
|
3030
|
+
* explicit reference.
|
|
3031
|
+
* @example
|
|
3032
|
+
* This example uses the useCellListener hook to create a listener that is
|
|
3033
|
+
* scoped to a single component. When the component is unmounted, the listener
|
|
3034
|
+
* is removed from the Store.
|
|
3035
|
+
*
|
|
3036
|
+
* ```jsx
|
|
3037
|
+
* const App = ({store}) => (
|
|
3038
|
+
* <Provider store={store}>
|
|
3039
|
+
* <Pane />
|
|
3040
|
+
* </Provider>
|
|
3041
|
+
* );
|
|
3042
|
+
* const Pane = () => {
|
|
3043
|
+
* useCellListener('pets', 'fido', 'color', () =>
|
|
3044
|
+
* console.log('Cell changed'),
|
|
3045
|
+
* );
|
|
3046
|
+
* return <span>App</span>;
|
|
3047
|
+
* };
|
|
3048
|
+
*
|
|
3049
|
+
* const store = createStore().setTables({pets: {fido: {color: 'brown'}}});
|
|
3050
|
+
* const app = document.createElement('div');
|
|
3051
|
+
* const root = ReactDOMClient.createRoot(app);
|
|
3052
|
+
* root.render(<App store={store} />); // !act
|
|
3053
|
+
* console.log(store.getListenerStats().cell);
|
|
3054
|
+
* // -> 1
|
|
3055
|
+
*
|
|
3056
|
+
* store.setCell('pets', 'fido', 'color', 'walnut'); // !act
|
|
3057
|
+
* // -> 'Cell changed'
|
|
3058
|
+
*
|
|
3059
|
+
* root.unmount(); // !act
|
|
3060
|
+
* console.log(store.getListenerStats().cell);
|
|
3061
|
+
* // -> 0
|
|
3062
|
+
* ```
|
|
3063
|
+
* @category Store hooks
|
|
3064
|
+
*/
|
|
3065
|
+
export function useCellListener(
|
|
3066
|
+
tableId: IdOrNull,
|
|
3067
|
+
rowId: IdOrNull,
|
|
3068
|
+
cellId: IdOrNull,
|
|
3069
|
+
listener: CellListener,
|
|
3070
|
+
listenerDeps?: React.DependencyList,
|
|
3071
|
+
mutator?: boolean,
|
|
3072
|
+
storeOrStoreId?: StoreOrStoreId,
|
|
3073
|
+
): void;
|
|
3074
|
+
|
|
3075
|
+
/**
|
|
3076
|
+
* The useValuesListener hook registers a listener function with a Store that
|
|
3077
|
+
* will be called whenever keyed value data in it changes.
|
|
3078
|
+
*
|
|
3079
|
+
* This hook is useful for situations where a component needs to register its
|
|
3080
|
+
* own specific listener to do more than simply tracking the value (which is
|
|
3081
|
+
* more easily done with the useValues hook).
|
|
3082
|
+
*
|
|
3083
|
+
* Unlike the addValuesListener method, which returns a listener Id and requires
|
|
3084
|
+
* you to remove it manually, the useValuesListener hook manages this lifecycle
|
|
3085
|
+
* for you: when the listener changes (per its `listenerDeps` dependencies) or
|
|
3086
|
+
* the component unmounts, the listener on the underlying Store will be deleted.
|
|
3087
|
+
*
|
|
3088
|
+
* @param listener The function that will be called whenever keyed value data in
|
|
3089
|
+
* the Store changes.
|
|
3090
|
+
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
3091
|
+
* function, which, if any change, result in the re-registration of the
|
|
3092
|
+
* listener. This parameter defaults to an empty array.
|
|
3093
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
3094
|
+
* Store data.
|
|
3095
|
+
* @param storeOrStoreId The Store to register the listener with: omit for the
|
|
3096
|
+
* default context Store, provide an Id for a named context Store, or provide an
|
|
3097
|
+
* explicit reference.
|
|
3098
|
+
* @example
|
|
3099
|
+
* This example uses the useValuesListener hook to create a listener that is
|
|
3100
|
+
* scoped to a single component. When the component is unmounted, the listener
|
|
3101
|
+
* is removed from the Store.
|
|
3102
|
+
*
|
|
3103
|
+
* ```jsx
|
|
3104
|
+
* const App = ({store}) => (
|
|
3105
|
+
* <Provider store={store}>
|
|
3106
|
+
* <Pane />
|
|
3107
|
+
* </Provider>
|
|
3108
|
+
* );
|
|
3109
|
+
* const Pane = () => {
|
|
3110
|
+
* useValuesListener(() => console.log('Values changed'));
|
|
2261
3111
|
* return <span>App</span>;
|
|
2262
3112
|
* };
|
|
2263
3113
|
*
|
|
2264
|
-
* const store = createStore().
|
|
3114
|
+
* const store = createStore().setValues({open: true});
|
|
2265
3115
|
* const app = document.createElement('div');
|
|
2266
3116
|
* const root = ReactDOMClient.createRoot(app);
|
|
2267
3117
|
* root.render(<App store={store} />); // !act
|
|
2268
|
-
* console.log(store.getListenerStats().
|
|
3118
|
+
* console.log(store.getListenerStats().values);
|
|
2269
3119
|
* // -> 1
|
|
2270
3120
|
*
|
|
2271
|
-
* store.
|
|
2272
|
-
* // -> '
|
|
3121
|
+
* store.setValue('open', false); // !act
|
|
3122
|
+
* // -> 'Values changed'
|
|
2273
3123
|
*
|
|
2274
3124
|
* root.unmount(); // !act
|
|
2275
|
-
* console.log(store.getListenerStats().
|
|
3125
|
+
* console.log(store.getListenerStats().values);
|
|
2276
3126
|
* // -> 0
|
|
2277
3127
|
* ```
|
|
2278
3128
|
* @category Store hooks
|
|
3129
|
+
* @since v3.0.0
|
|
2279
3130
|
*/
|
|
2280
|
-
export function
|
|
2281
|
-
|
|
2282
|
-
rowId: IdOrNull,
|
|
2283
|
-
listener: RowListener,
|
|
3131
|
+
export function useValuesListener(
|
|
3132
|
+
listener: ValuesListener,
|
|
2284
3133
|
listenerDeps?: React.DependencyList,
|
|
2285
3134
|
mutator?: boolean,
|
|
2286
3135
|
storeOrStoreId?: StoreOrStoreId,
|
|
2287
3136
|
): void;
|
|
2288
3137
|
|
|
2289
3138
|
/**
|
|
2290
|
-
* The
|
|
2291
|
-
* will be called whenever the
|
|
3139
|
+
* The useValueIdsListener hook registers a listener function with a Store that
|
|
3140
|
+
* will be called whenever the Value Ids in it change.
|
|
2292
3141
|
*
|
|
2293
3142
|
* This hook is useful for situations where a component needs to register its
|
|
2294
3143
|
* own specific listener to do more than simply tracking the value (which is
|
|
2295
|
-
* more easily done with the
|
|
2296
|
-
*
|
|
2297
|
-
* You can either listen to a single Row (by specifying the Table Id and Row Id
|
|
2298
|
-
* as the method's first two parameters) or changes to any Row (by providing
|
|
2299
|
-
* `null` wildcards).
|
|
2300
|
-
*
|
|
2301
|
-
* Both, either, or neither of the `tableId` and `rowId` parameters can be
|
|
2302
|
-
* wildcarded with `null`. You can listen to a specific Row in a specific Table,
|
|
2303
|
-
* any Row in a specific Table, a specific Row in any Table, or any Row in any
|
|
2304
|
-
* Table.
|
|
3144
|
+
* more easily done with the useValueIds hook).
|
|
2305
3145
|
*
|
|
2306
|
-
* Unlike the
|
|
2307
|
-
* requires you to remove it manually, the
|
|
3146
|
+
* Unlike the addValueIdsListener method, which returns a listener Id and
|
|
3147
|
+
* requires you to remove it manually, the useValueIdsListener hook manages this
|
|
2308
3148
|
* lifecycle for you: when the listener changes (per its `listenerDeps`
|
|
2309
3149
|
* dependencies) or the component unmounts, the listener on the underlying Store
|
|
2310
3150
|
* will be deleted.
|
|
2311
3151
|
*
|
|
2312
|
-
* @param
|
|
2313
|
-
*
|
|
2314
|
-
* @param listener The function that will be called whenever the Cell Ids in the
|
|
2315
|
-
* Row change.
|
|
3152
|
+
* @param listener The function that will be called whenever the Value Ids in
|
|
3153
|
+
* the Store change.
|
|
2316
3154
|
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
2317
3155
|
* function, which, if any change, result in the re-registration of the
|
|
2318
3156
|
* listener. This parameter defaults to an empty array.
|
|
@@ -2322,7 +3160,7 @@ export function useRowListener(
|
|
|
2322
3160
|
* default context Store, provide an Id for a named context Store, or provide an
|
|
2323
3161
|
* explicit reference.
|
|
2324
3162
|
* @example
|
|
2325
|
-
* This example uses the
|
|
3163
|
+
* This example uses the useValueIdsListener hook to create a listener that is
|
|
2326
3164
|
* scoped to a single component. When the component is unmounted, the listener
|
|
2327
3165
|
* is removed from the Store.
|
|
2328
3166
|
*
|
|
@@ -2333,63 +3171,52 @@ export function useRowListener(
|
|
|
2333
3171
|
* </Provider>
|
|
2334
3172
|
* );
|
|
2335
3173
|
* const Pane = () => {
|
|
2336
|
-
*
|
|
2337
|
-
* console.log('Cell Ids changed'),
|
|
2338
|
-
* );
|
|
3174
|
+
* useValueIdsListener(() => console.log('Value Ids changed'));
|
|
2339
3175
|
* return <span>App</span>;
|
|
2340
3176
|
* };
|
|
2341
3177
|
*
|
|
2342
|
-
* const store = createStore().
|
|
3178
|
+
* const store = createStore().setValues({open: true});
|
|
2343
3179
|
* const app = document.createElement('div');
|
|
2344
3180
|
* const root = ReactDOMClient.createRoot(app);
|
|
2345
3181
|
* root.render(<App store={store} />); // !act
|
|
2346
|
-
* console.log(store.getListenerStats().
|
|
3182
|
+
* console.log(store.getListenerStats().valueIds);
|
|
2347
3183
|
* // -> 1
|
|
2348
3184
|
*
|
|
2349
|
-
* store.
|
|
2350
|
-
* // -> '
|
|
3185
|
+
* store.setValue('employees', 3); // !act
|
|
3186
|
+
* // -> 'Value Ids changed'
|
|
2351
3187
|
*
|
|
2352
3188
|
* root.unmount(); // !act
|
|
2353
|
-
* console.log(store.getListenerStats().
|
|
3189
|
+
* console.log(store.getListenerStats().valueIds);
|
|
2354
3190
|
* // -> 0
|
|
2355
3191
|
* ```
|
|
2356
3192
|
* @category Store hooks
|
|
3193
|
+
* @since v3.0.0
|
|
2357
3194
|
*/
|
|
2358
|
-
export function
|
|
2359
|
-
|
|
2360
|
-
rowId: IdOrNull,
|
|
2361
|
-
listener: CellIdsListener,
|
|
3195
|
+
export function useValueIdsListener(
|
|
3196
|
+
listener: ValueIdsListener,
|
|
2362
3197
|
listenerDeps?: React.DependencyList,
|
|
2363
3198
|
mutator?: boolean,
|
|
2364
3199
|
storeOrStoreId?: StoreOrStoreId,
|
|
2365
3200
|
): void;
|
|
2366
3201
|
|
|
2367
3202
|
/**
|
|
2368
|
-
* The
|
|
2369
|
-
* be called whenever data in a
|
|
3203
|
+
* The useValueListener hook registers a listener function with a Store that
|
|
3204
|
+
* will be called whenever data in a Value changes.
|
|
2370
3205
|
*
|
|
2371
3206
|
* This hook is useful for situations where a component needs to register its
|
|
2372
3207
|
* own specific listener to do more than simply tracking the value (which is
|
|
2373
|
-
* more easily done with the
|
|
2374
|
-
*
|
|
2375
|
-
* You can either listen to a single Cell (by specifying the Table Id, Row Id,
|
|
2376
|
-
* and Cell Id as the method's first three parameters) or changes to any Cell
|
|
2377
|
-
* (by providing `null` wildcards).
|
|
3208
|
+
* more easily done with the useValue hook).
|
|
2378
3209
|
*
|
|
2379
|
-
*
|
|
2380
|
-
*
|
|
2381
|
-
* in a specific Table, any Cell in any Row in any Table, for example - or every
|
|
2382
|
-
* other combination of wildcards.
|
|
3210
|
+
* You can either listen to a single Value (by specifying its Id as the method's
|
|
3211
|
+
* first parameter) or changes to any Value (by providing a `null` wildcard).
|
|
2383
3212
|
*
|
|
2384
|
-
* Unlike the
|
|
2385
|
-
* you to remove it manually, the
|
|
3213
|
+
* Unlike the addValueListener method, which returns a listener Id and requires
|
|
3214
|
+
* you to remove it manually, the useValueListener hook manages this lifecycle
|
|
2386
3215
|
* for you: when the listener changes (per its `listenerDeps` dependencies) or
|
|
2387
3216
|
* the component unmounts, the listener on the underlying Store will be deleted.
|
|
2388
3217
|
*
|
|
2389
|
-
* @param
|
|
2390
|
-
* @param
|
|
2391
|
-
* @param cellId The Id of the Cell to listen to, or `null` as a wildcard.
|
|
2392
|
-
* @param listener The function that will be called whenever data in the Cell
|
|
3218
|
+
* @param valueId The Id of the Value to listen to, or `null` as a wildcard.
|
|
3219
|
+
* @param listener The function that will be called whenever data in the Value
|
|
2393
3220
|
* changes.
|
|
2394
3221
|
* @param listenerDeps An optional array of dependencies for the `listener`
|
|
2395
3222
|
* function, which, if any change, result in the re-registration of the
|
|
@@ -2400,7 +3227,7 @@ export function useCellIdsListener(
|
|
|
2400
3227
|
* default context Store, provide an Id for a named context Store, or provide an
|
|
2401
3228
|
* explicit reference.
|
|
2402
3229
|
* @example
|
|
2403
|
-
* This example uses the
|
|
3230
|
+
* This example uses the useValueListener hook to create a listener that is
|
|
2404
3231
|
* scoped to a single component. When the component is unmounted, the listener
|
|
2405
3232
|
* is removed from the Store.
|
|
2406
3233
|
*
|
|
@@ -2411,33 +3238,30 @@ export function useCellIdsListener(
|
|
|
2411
3238
|
* </Provider>
|
|
2412
3239
|
* );
|
|
2413
3240
|
* const Pane = () => {
|
|
2414
|
-
*
|
|
2415
|
-
* console.log('Cell changed'),
|
|
2416
|
-
* );
|
|
3241
|
+
* useValueListener('open', () => console.log('Value changed'));
|
|
2417
3242
|
* return <span>App</span>;
|
|
2418
3243
|
* };
|
|
2419
3244
|
*
|
|
2420
|
-
* const store = createStore().
|
|
3245
|
+
* const store = createStore().setValues({open: true});
|
|
2421
3246
|
* const app = document.createElement('div');
|
|
2422
3247
|
* const root = ReactDOMClient.createRoot(app);
|
|
2423
3248
|
* root.render(<App store={store} />); // !act
|
|
2424
|
-
* console.log(store.getListenerStats().
|
|
3249
|
+
* console.log(store.getListenerStats().value);
|
|
2425
3250
|
* // -> 1
|
|
2426
3251
|
*
|
|
2427
|
-
* store.
|
|
2428
|
-
* // -> '
|
|
3252
|
+
* store.setValue('open', false); // !act
|
|
3253
|
+
* // -> 'Value changed'
|
|
2429
3254
|
*
|
|
2430
3255
|
* root.unmount(); // !act
|
|
2431
|
-
* console.log(store.getListenerStats().
|
|
3256
|
+
* console.log(store.getListenerStats().value);
|
|
2432
3257
|
* // -> 0
|
|
2433
3258
|
* ```
|
|
2434
3259
|
* @category Store hooks
|
|
3260
|
+
* @since v3.0.0
|
|
2435
3261
|
*/
|
|
2436
|
-
export function
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
cellId: IdOrNull,
|
|
2440
|
-
listener: CellListener,
|
|
3262
|
+
export function useValueListener(
|
|
3263
|
+
valueId: IdOrNull,
|
|
3264
|
+
listener: ValueListener,
|
|
2441
3265
|
listenerDeps?: React.DependencyList,
|
|
2442
3266
|
mutator?: boolean,
|
|
2443
3267
|
storeOrStoreId?: StoreOrStoreId,
|
|
@@ -4739,7 +5563,7 @@ export function useResultSortedRowIds(
|
|
|
4739
5563
|
): Ids;
|
|
4740
5564
|
|
|
4741
5565
|
/**
|
|
4742
|
-
* The useResultRow hook returns an object containing the
|
|
5566
|
+
* The useResultRow hook returns an object containing the data of a
|
|
4743
5567
|
* single Row in the result Table of the given query, and registers a listener
|
|
4744
5568
|
* so that any changes to that Row will cause a re-render.
|
|
4745
5569
|
*
|
|
@@ -6653,7 +7477,7 @@ export type TablesProps = {
|
|
|
6653
7477
|
*/
|
|
6654
7478
|
readonly separator?: ReactElement | string;
|
|
6655
7479
|
/**
|
|
6656
|
-
* Whether the component should also render the Ids of
|
|
7480
|
+
* Whether the component should also render the Ids of each Table, and its
|
|
6657
7481
|
* descendent objects, to assist with debugging.
|
|
6658
7482
|
*/
|
|
6659
7483
|
readonly debugIds?: boolean;
|
|
@@ -6793,7 +7617,7 @@ export type RowProps = {
|
|
|
6793
7617
|
};
|
|
6794
7618
|
|
|
6795
7619
|
/**
|
|
6796
|
-
*
|
|
7620
|
+
* CellProps props are used for components that refer to a single Cell in a Row,
|
|
6797
7621
|
* such as the CellView component.
|
|
6798
7622
|
*
|
|
6799
7623
|
* @category Props
|
|
@@ -6823,6 +7647,64 @@ export type CellProps = {
|
|
|
6823
7647
|
readonly debugIds?: boolean;
|
|
6824
7648
|
};
|
|
6825
7649
|
|
|
7650
|
+
/**
|
|
7651
|
+
* ValuesProps props are used for components that refer to all the Values in a
|
|
7652
|
+
* Store, such as the ValuesView component.
|
|
7653
|
+
*
|
|
7654
|
+
* @category Props
|
|
7655
|
+
* @since v3.0.0
|
|
7656
|
+
*/
|
|
7657
|
+
export type ValuesProps = {
|
|
7658
|
+
/**
|
|
7659
|
+
* The Store to be accessed: omit for the default context Store, provide an Id
|
|
7660
|
+
* for a named context Store, or provide an explicit reference.
|
|
7661
|
+
*/
|
|
7662
|
+
readonly store?: StoreOrStoreId;
|
|
7663
|
+
/**
|
|
7664
|
+
* A custom component for rendering each Value in the Store (to override the
|
|
7665
|
+
* default ValueView component).
|
|
7666
|
+
*/
|
|
7667
|
+
readonly valueComponent?: ComponentType<ValueProps>;
|
|
7668
|
+
/**
|
|
7669
|
+
* A function for generating extra props for each custom Value component based
|
|
7670
|
+
* on its Id.
|
|
7671
|
+
*/
|
|
7672
|
+
readonly getValueComponentProps?: (valueId: Id) => ExtraProps;
|
|
7673
|
+
/**
|
|
7674
|
+
* A component or string to separate each Value component.
|
|
7675
|
+
*/
|
|
7676
|
+
readonly separator?: ReactElement | string;
|
|
7677
|
+
/**
|
|
7678
|
+
* Whether the component should also render the Ids of each Value to assist
|
|
7679
|
+
* with debugging.
|
|
7680
|
+
*/
|
|
7681
|
+
readonly debugIds?: boolean;
|
|
7682
|
+
};
|
|
7683
|
+
|
|
7684
|
+
/**
|
|
7685
|
+
* ValueProps props are used for components that refer to a single Value in a
|
|
7686
|
+
* Row, such as the ValueView component.
|
|
7687
|
+
*
|
|
7688
|
+
* @category Props
|
|
7689
|
+
* @since v3.0.0
|
|
7690
|
+
*/
|
|
7691
|
+
export type ValueProps = {
|
|
7692
|
+
/**
|
|
7693
|
+
* The Id of the Value in the Row to be rendered.
|
|
7694
|
+
*/
|
|
7695
|
+
readonly valueId: Id;
|
|
7696
|
+
/**
|
|
7697
|
+
* The Store to be accessed: omit for the default context Store, provide an Id
|
|
7698
|
+
* for a named context Store, or provide an explicit reference.
|
|
7699
|
+
*/
|
|
7700
|
+
readonly store?: StoreOrStoreId;
|
|
7701
|
+
/**
|
|
7702
|
+
* Whether the component should also render the Id of the Value to assist with
|
|
7703
|
+
* debugging.
|
|
7704
|
+
*/
|
|
7705
|
+
readonly debugIds?: boolean;
|
|
7706
|
+
};
|
|
7707
|
+
|
|
6826
7708
|
/**
|
|
6827
7709
|
* MetricProps props are used for components that refer to a single Metric in a
|
|
6828
7710
|
* Metrics object, such as the MetricView component.
|
|
@@ -7977,8 +8859,9 @@ export function SortedTableView(props: SortedTableProps): ComponentReturnType;
|
|
|
7977
8859
|
export function TableView(props: TableProps): ComponentReturnType;
|
|
7978
8860
|
|
|
7979
8861
|
/**
|
|
7980
|
-
* The TablesView component renders the contents of a Store, and
|
|
7981
|
-
* listener so that any changes to that result will cause a
|
|
8862
|
+
* The TablesView component renders the tabular contents of a Store, and
|
|
8863
|
+
* registers a listener so that any changes to that result will cause a
|
|
8864
|
+
* re-render.
|
|
7982
8865
|
*
|
|
7983
8866
|
* The component's props can identify which Store to render - either the default
|
|
7984
8867
|
* context Store, a named context Store, or an explicit reference.
|
|
@@ -8004,7 +8887,7 @@ export function TableView(props: TableProps): ComponentReturnType;
|
|
|
8004
8887
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
8005
8888
|
* const App = () => (
|
|
8006
8889
|
* <div>
|
|
8007
|
-
* <TablesView store={store} />
|
|
8890
|
+
* <TablesView store={store} separator="/" />
|
|
8008
8891
|
* </div>
|
|
8009
8892
|
* );
|
|
8010
8893
|
*
|
|
@@ -8015,7 +8898,7 @@ export function TableView(props: TableProps): ComponentReturnType;
|
|
|
8015
8898
|
*
|
|
8016
8899
|
* store.setTable('species', {dog: {price: 5}}); // !act
|
|
8017
8900
|
* console.log(app.innerHTML);
|
|
8018
|
-
* // -> '<div>
|
|
8901
|
+
* // -> '<div>dog/5</div>'
|
|
8019
8902
|
* ```
|
|
8020
8903
|
* @example
|
|
8021
8904
|
* This example creates a Provider context into which a default Store is
|
|
@@ -8030,7 +8913,7 @@ export function TableView(props: TableProps): ComponentReturnType;
|
|
|
8030
8913
|
* );
|
|
8031
8914
|
* const Pane = () => (
|
|
8032
8915
|
* <div>
|
|
8033
|
-
* <TablesView
|
|
8916
|
+
* <TablesView debugIds={true} />
|
|
8034
8917
|
* </div>
|
|
8035
8918
|
* );
|
|
8036
8919
|
*
|
|
@@ -8083,6 +8966,203 @@ export function TableView(props: TableProps): ComponentReturnType;
|
|
|
8083
8966
|
*/
|
|
8084
8967
|
export function TablesView(props: TablesProps): ComponentReturnType;
|
|
8085
8968
|
|
|
8969
|
+
/**
|
|
8970
|
+
* The ValueView component renders the value of a single Value, and registers a
|
|
8971
|
+
* listener so that any changes to that result will cause a re-render.
|
|
8972
|
+
*
|
|
8973
|
+
* The component's props identify which Value to render based on Value Id and
|
|
8974
|
+
* Store (which is either the default context Store, a named context Store, or
|
|
8975
|
+
* an explicit reference).
|
|
8976
|
+
*
|
|
8977
|
+
* A Value contains a string, number, or boolean, so the value is rendered
|
|
8978
|
+
* directly without further decoration. You can create your own ValueView-like
|
|
8979
|
+
* component to customize the way that a Value is rendered: see the ValuesView
|
|
8980
|
+
* component for more details.
|
|
8981
|
+
*
|
|
8982
|
+
* This component uses the useValue hook under the covers, which means that any
|
|
8983
|
+
* changes to the specified Value will cause a re-render.
|
|
8984
|
+
*
|
|
8985
|
+
* @param props The props for this component.
|
|
8986
|
+
* @returns A rendering of the Value, or nothing, if not present.
|
|
8987
|
+
* @example
|
|
8988
|
+
* This example creates a Store outside the application, which is used in the
|
|
8989
|
+
* ValueView component by reference. A change to the data in the Store
|
|
8990
|
+
* re-renders the component.
|
|
8991
|
+
*
|
|
8992
|
+
* ```jsx
|
|
8993
|
+
* const store = createStore().setValue('open', true);
|
|
8994
|
+
* const App = () => (
|
|
8995
|
+
* <span>
|
|
8996
|
+
* <ValueView valueId="open" store={store} />
|
|
8997
|
+
* </span>
|
|
8998
|
+
* );
|
|
8999
|
+
*
|
|
9000
|
+
* const app = document.createElement('div');
|
|
9001
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
9002
|
+
* console.log(app.innerHTML);
|
|
9003
|
+
* // -> '<span>true</span>'
|
|
9004
|
+
*
|
|
9005
|
+
* store.setValue('open', false); // !act
|
|
9006
|
+
* console.log(app.innerHTML);
|
|
9007
|
+
* // -> '<span>false</span>'
|
|
9008
|
+
* ```
|
|
9009
|
+
* @example
|
|
9010
|
+
* This example creates a Provider context into which a default Store is
|
|
9011
|
+
* provided. The ValueView component within it then renders the Value (with its
|
|
9012
|
+
* Id for readability).
|
|
9013
|
+
*
|
|
9014
|
+
* ```jsx
|
|
9015
|
+
* const App = ({store}) => (
|
|
9016
|
+
* <Provider store={store}>
|
|
9017
|
+
* <Pane />
|
|
9018
|
+
* </Provider>
|
|
9019
|
+
* );
|
|
9020
|
+
* const Pane = () => (
|
|
9021
|
+
* <span>
|
|
9022
|
+
* <ValueView valueId="open" debugIds={true} />
|
|
9023
|
+
* </span>
|
|
9024
|
+
* );
|
|
9025
|
+
*
|
|
9026
|
+
* const store = createStore().setValue('open', true);
|
|
9027
|
+
* const app = document.createElement('div');
|
|
9028
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
9029
|
+
* console.log(app.innerHTML);
|
|
9030
|
+
* // -> '<span>open:{true}</span>'
|
|
9031
|
+
* ```
|
|
9032
|
+
* @example
|
|
9033
|
+
* This example creates a Provider context into which a default Store is
|
|
9034
|
+
* provided. The ValueView component within it then attempts to render a
|
|
9035
|
+
* non-existent Value.
|
|
9036
|
+
*
|
|
9037
|
+
* ```jsx
|
|
9038
|
+
* const App = ({store}) => (
|
|
9039
|
+
* <Provider store={store}>
|
|
9040
|
+
* <Pane />
|
|
9041
|
+
* </Provider>
|
|
9042
|
+
* );
|
|
9043
|
+
* const Pane = () => (
|
|
9044
|
+
* <span>
|
|
9045
|
+
* <ValueView valueId="website" />
|
|
9046
|
+
* </span>
|
|
9047
|
+
* );
|
|
9048
|
+
*
|
|
9049
|
+
* const store = createStore().setValue('open', true);
|
|
9050
|
+
* const app = document.createElement('div');
|
|
9051
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
9052
|
+
* console.log(app.innerHTML);
|
|
9053
|
+
* // -> '<span></span>'
|
|
9054
|
+
* ```
|
|
9055
|
+
* @category Store components
|
|
9056
|
+
* @since v3.0.0
|
|
9057
|
+
*/
|
|
9058
|
+
export function ValueView(props: ValueProps): ComponentReturnType;
|
|
9059
|
+
|
|
9060
|
+
/**
|
|
9061
|
+
* The ValuesView component renders the keyed value contents of a Store, and
|
|
9062
|
+
* registers a listener so that any changes to that result will cause a
|
|
9063
|
+
* re-render.
|
|
9064
|
+
*
|
|
9065
|
+
* The component's props can identify which Store to render - either the default
|
|
9066
|
+
* context Store, a named context Store, or an explicit reference.
|
|
9067
|
+
*
|
|
9068
|
+
* This component renders a Store by iterating over its Value objects. By
|
|
9069
|
+
* default these are in turn rendered with the ValueView component, but you can
|
|
9070
|
+
* override this behavior by providing a `valueComponent` prop, a custom
|
|
9071
|
+
* component of your own that will render a Value based on ValueProps. You can
|
|
9072
|
+
* also pass additional props to your custom component with the
|
|
9073
|
+
* `getValueComponentProps` callback prop.
|
|
9074
|
+
*
|
|
9075
|
+
* This component uses the useTableIds hook under the covers, which means that
|
|
9076
|
+
* any changes to the structure of the Store will cause a re-render.
|
|
9077
|
+
*
|
|
9078
|
+
* This component uses the useValueIds hook under the covers, which means that
|
|
9079
|
+
* any changes to the Store's Values will cause a re-render.
|
|
9080
|
+
*
|
|
9081
|
+
* @param props The props for this component.
|
|
9082
|
+
* @returns A rendering of the Values, or nothing, if not present.
|
|
9083
|
+
* @example
|
|
9084
|
+
* This example creates a Store outside the application, which is used in the
|
|
9085
|
+
* ValuesView component by reference. A change to the data in the Store
|
|
9086
|
+
* re-renders the component.
|
|
9087
|
+
*
|
|
9088
|
+
* ```jsx
|
|
9089
|
+
* const store = createStore().setValue('open', true);
|
|
9090
|
+
* const App = () => (
|
|
9091
|
+
* <div>
|
|
9092
|
+
* <ValuesView store={store} separator="/" />
|
|
9093
|
+
* </div>
|
|
9094
|
+
* );
|
|
9095
|
+
*
|
|
9096
|
+
* const app = document.createElement('div');
|
|
9097
|
+
* ReactDOMClient.createRoot(app).render(<App />); // !act
|
|
9098
|
+
* console.log(app.innerHTML);
|
|
9099
|
+
* // -> '<div>true</div>'
|
|
9100
|
+
*
|
|
9101
|
+
* store.setValue('employees', 3); // !act
|
|
9102
|
+
* console.log(app.innerHTML);
|
|
9103
|
+
* // -> '<div>true/3</div>'
|
|
9104
|
+
* ```
|
|
9105
|
+
* @example
|
|
9106
|
+
* This example creates a Provider context into which a default Store is
|
|
9107
|
+
* provided. The ValuesView component within it then renders the Values (with
|
|
9108
|
+
* Ids for readability).
|
|
9109
|
+
*
|
|
9110
|
+
* ```jsx
|
|
9111
|
+
* const App = ({store}) => (
|
|
9112
|
+
* <Provider store={store}>
|
|
9113
|
+
* <Pane />
|
|
9114
|
+
* </Provider>
|
|
9115
|
+
* );
|
|
9116
|
+
* const Pane = () => (
|
|
9117
|
+
* <div>
|
|
9118
|
+
* <ValuesView debugIds={true} />
|
|
9119
|
+
* </div>
|
|
9120
|
+
* );
|
|
9121
|
+
*
|
|
9122
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
9123
|
+
* const app = document.createElement('div');
|
|
9124
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
9125
|
+
* console.log(app.innerHTML);
|
|
9126
|
+
* // -> '<div>open:{true}employees:{3}</div>'
|
|
9127
|
+
* ```
|
|
9128
|
+
* @example
|
|
9129
|
+
* This example creates a Provider context into which a default Store is
|
|
9130
|
+
* provided. The ValuesView component within it then renders the Values with a
|
|
9131
|
+
* custom Value component and a custom props callback.
|
|
9132
|
+
*
|
|
9133
|
+
* ```jsx
|
|
9134
|
+
* const App = ({store}) => (
|
|
9135
|
+
* <Provider store={store}>
|
|
9136
|
+
* <Pane />
|
|
9137
|
+
* </Provider>
|
|
9138
|
+
* );
|
|
9139
|
+
* const Pane = () => (
|
|
9140
|
+
* <div>
|
|
9141
|
+
* <ValuesView
|
|
9142
|
+
* valueComponent={FormattedValueView}
|
|
9143
|
+
* getValueComponentProps={(valueId) => ({bold: valueId == 'open'})}
|
|
9144
|
+
* />
|
|
9145
|
+
* </div>
|
|
9146
|
+
* );
|
|
9147
|
+
* const FormattedValueView = ({valueId, bold}) => (
|
|
9148
|
+
* <span>
|
|
9149
|
+
* {bold ? <b>{valueId}</b> : valueId}
|
|
9150
|
+
* {': '}
|
|
9151
|
+
* <ValueView valueId={valueId} />
|
|
9152
|
+
* </span>
|
|
9153
|
+
* );
|
|
9154
|
+
*
|
|
9155
|
+
* const store = createStore().setValues({open: true, employees: 3});
|
|
9156
|
+
* const app = document.createElement('div');
|
|
9157
|
+
* ReactDOMClient.createRoot(app).render(<App store={store} />); // !act
|
|
9158
|
+
* console.log(app.innerHTML);
|
|
9159
|
+
* // -> '<div><span><b>open</b>: true</span><span>employees: 3</span></div>'
|
|
9160
|
+
* ```
|
|
9161
|
+
* @category Store components
|
|
9162
|
+
* @since v3.0.0
|
|
9163
|
+
*/
|
|
9164
|
+
export function ValuesView(props: ValuesProps): ComponentReturnType;
|
|
9165
|
+
|
|
8086
9166
|
/**
|
|
8087
9167
|
* The MetricView component renders the current value of a Metric, and registers
|
|
8088
9168
|
* a listener so that any changes to that result will cause a re-render.
|