tinybase 3.2.0 → 3.3.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/lib/cjs/store.cjs +1 -1
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/store.cjs +1 -1
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/store.js +53 -13
- package/lib/debug/tinybase.js +53 -13
- package/lib/debug/tools.js +93 -1
- package/lib/debug/ui-react.js +24 -0
- 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.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- 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.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/types/store.d.ts +302 -9
- package/lib/types/tools.d.ts +2 -2
- package/lib/types/ui-react.d.ts +156 -0
- package/lib/types/with-schemas/store.d.ts +405 -16
- package/lib/types/with-schemas/tools.d.ts +2 -2
- package/lib/types/with-schemas/ui-react.d.ts +181 -5
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- 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.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +15 -15
- package/readme.md +2 -2
|
@@ -481,6 +481,29 @@ export type TableCallback<
|
|
|
481
481
|
Params1 extends any[] = Truncate<Params2>,
|
|
482
482
|
> = ((...params: Params2) => void) | ((...params: Params1) => void);
|
|
483
483
|
|
|
484
|
+
/**
|
|
485
|
+
* The TableCellCallback type describes a function that takes a Cell's Id and
|
|
486
|
+
* the count of times it appears across a whole Table.
|
|
487
|
+
*
|
|
488
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
489
|
+
*
|
|
490
|
+
* ```ts override
|
|
491
|
+
* (cellId: Id, count: number) => void;
|
|
492
|
+
* ```
|
|
493
|
+
*
|
|
494
|
+
* A TableCellCallback is provided when using the forEachTableCell method, so
|
|
495
|
+
* that you can do something based on every Cell used across a Table. See that
|
|
496
|
+
* method for specific examples.
|
|
497
|
+
*
|
|
498
|
+
* @param cellId The Id of the Cell that the callback can operate on.
|
|
499
|
+
* @param count The number of times this Cell is used across a whole Table.
|
|
500
|
+
* @category Callback
|
|
501
|
+
*/
|
|
502
|
+
export type TableCellCallback<
|
|
503
|
+
Schema extends OptionalTablesSchema,
|
|
504
|
+
TableId extends TableIdFromSchema<Schema>,
|
|
505
|
+
> = (cellId: CellIdFromSchema<Schema, TableId>, count: number) => void;
|
|
506
|
+
|
|
484
507
|
/**
|
|
485
508
|
* The RowCallback type describes a function that takes a Row's Id and a
|
|
486
509
|
* callback to loop over each Cell within it.
|
|
@@ -779,7 +802,10 @@ export type TablesListener<Schemas extends OptionalSchemas> = (
|
|
|
779
802
|
* This has schema-based typing. The following is a simplified representation:
|
|
780
803
|
*
|
|
781
804
|
* ```ts override
|
|
782
|
-
* (
|
|
805
|
+
* (
|
|
806
|
+
* store: Store,
|
|
807
|
+
* getIdChanges: GetIdChanges | undefined,
|
|
808
|
+
* ) => void;
|
|
783
809
|
* ```
|
|
784
810
|
*
|
|
785
811
|
* A TableIdsListener is provided when using the addTableIdsListener method. See
|
|
@@ -787,11 +813,17 @@ export type TablesListener<Schemas extends OptionalSchemas> = (
|
|
|
787
813
|
*
|
|
788
814
|
* When called, a TableIdsListener is given a reference to the Store.
|
|
789
815
|
*
|
|
816
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
817
|
+
* used to query which Ids changed during the transaction.
|
|
818
|
+
*
|
|
790
819
|
* @param store A reference to the Store that changed.
|
|
820
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
821
|
+
* since v3.3.
|
|
791
822
|
* @category Listener
|
|
792
823
|
*/
|
|
793
824
|
export type TableIdsListener<Schemas extends OptionalSchemas> = (
|
|
794
825
|
store: Store<Schemas>,
|
|
826
|
+
getIdChanges: GetIdChanges<TableIdFromSchema<Schemas[0]>> | undefined,
|
|
795
827
|
) => void;
|
|
796
828
|
|
|
797
829
|
/**
|
|
@@ -836,6 +868,57 @@ export type TableListener<
|
|
|
836
868
|
getCellChange: GetCellChange<Schemas[0]> | undefined,
|
|
837
869
|
) => void;
|
|
838
870
|
|
|
871
|
+
/**
|
|
872
|
+
* The TableCellIdsListener type describes a function that is used to listen to
|
|
873
|
+
* changes to the Cell Ids that appear anywhere in a Table.
|
|
874
|
+
*
|
|
875
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
876
|
+
*
|
|
877
|
+
* ```ts override
|
|
878
|
+
* (
|
|
879
|
+
* store: Store,
|
|
880
|
+
* tableId: Id,
|
|
881
|
+
* getIdChanges: GetIdChanges | undefined,
|
|
882
|
+
* ) => void;
|
|
883
|
+
* ```
|
|
884
|
+
*
|
|
885
|
+
* A TableCellIdsListener is provided when using the addTableCellIdsListener
|
|
886
|
+
* method. See that method for specific examples.
|
|
887
|
+
*
|
|
888
|
+
* When called, a TableCellIdsListener is given a reference to the Store, the Id
|
|
889
|
+
* of the Table whose Cell Ids changed, and a GetIdChanges function that can be
|
|
890
|
+
* used to query which Ids changed during the transaction.
|
|
891
|
+
*
|
|
892
|
+
* @param store A reference to the Store that changed.
|
|
893
|
+
* @param tableId The Id of the Table that changed.
|
|
894
|
+
* @param getIdChanges A function that returns information about the Id changes.
|
|
895
|
+
* @category Listener
|
|
896
|
+
* @since v3.3
|
|
897
|
+
*/
|
|
898
|
+
export type TableCellIdsListener<
|
|
899
|
+
Schemas extends OptionalSchemas,
|
|
900
|
+
TableIdOrNull extends TableIdFromSchema<Schemas[0]> | null,
|
|
901
|
+
Params extends any[] = (
|
|
902
|
+
TableIdOrNull extends null ? TableIdFromSchema<Schemas[0]> : TableIdOrNull
|
|
903
|
+
) extends infer TableId
|
|
904
|
+
? TableId extends TableIdFromSchema<Schemas[0]>
|
|
905
|
+
? [
|
|
906
|
+
store: Store<Schemas>,
|
|
907
|
+
tableId: TableId,
|
|
908
|
+
getIdChanges: GetIdChanges<CellIdFromSchema<Schemas[0], TableId>>,
|
|
909
|
+
]
|
|
910
|
+
: never
|
|
911
|
+
: never,
|
|
912
|
+
Params3 extends any[] =
|
|
913
|
+
| Params
|
|
914
|
+
| [store: never, tableId: never, getIdChanges: never],
|
|
915
|
+
Params2 extends any[] = Truncate<Params3>,
|
|
916
|
+
// Params1 extends any[] = Truncate<Params2>,
|
|
917
|
+
> = Params extends any
|
|
918
|
+
? ((...params: Params3) => void) | ((...params: Params2) => void)
|
|
919
|
+
: // | ((...params: Params1) => void)
|
|
920
|
+
never;
|
|
921
|
+
|
|
839
922
|
/**
|
|
840
923
|
* The RowIdsListener type describes a function that is used to listen to
|
|
841
924
|
* changes to the Row Ids in a Table.
|
|
@@ -843,7 +926,11 @@ export type TableListener<
|
|
|
843
926
|
* This has schema-based typing. The following is a simplified representation:
|
|
844
927
|
*
|
|
845
928
|
* ```ts override
|
|
846
|
-
* (
|
|
929
|
+
* (
|
|
930
|
+
* store: Store,
|
|
931
|
+
* tableId: Id,
|
|
932
|
+
* getIdChanges: GetIdChanges | undefined,
|
|
933
|
+
* ) => void;
|
|
847
934
|
* ```
|
|
848
935
|
*
|
|
849
936
|
* A RowIdsListener is provided when using the addRowIdsListener method. See
|
|
@@ -852,8 +939,13 @@ export type TableListener<
|
|
|
852
939
|
* When called, a RowIdsListener is given a reference to the Store, and the Id
|
|
853
940
|
* of the Table whose Row Ids changed.
|
|
854
941
|
*
|
|
942
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
943
|
+
* used to query which Ids changed during the transaction.
|
|
944
|
+
*
|
|
855
945
|
* @param store A reference to the Store that changed.
|
|
856
946
|
* @param tableId The Id of the Table that changed.
|
|
947
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
948
|
+
* since v3.3.
|
|
857
949
|
* @category Listener
|
|
858
950
|
*/
|
|
859
951
|
export type RowIdsListener<
|
|
@@ -864,6 +956,7 @@ export type RowIdsListener<
|
|
|
864
956
|
tableId: TableIdOrNull extends null
|
|
865
957
|
? TableIdFromSchema<Schemas[0]>
|
|
866
958
|
: TableIdOrNull,
|
|
959
|
+
getIdChanges: GetIdChanges<Id> | undefined,
|
|
867
960
|
) => void;
|
|
868
961
|
|
|
869
962
|
/**
|
|
@@ -975,7 +1068,12 @@ export type RowListener<
|
|
|
975
1068
|
* This has schema-based typing. The following is a simplified representation:
|
|
976
1069
|
*
|
|
977
1070
|
* ```ts override
|
|
978
|
-
* (
|
|
1071
|
+
* (
|
|
1072
|
+
* store: Store,
|
|
1073
|
+
* tableId: Id,
|
|
1074
|
+
* rowId: Id,
|
|
1075
|
+
* getIdChanges: GetIdChanges | undefined,
|
|
1076
|
+
* ) => void;
|
|
979
1077
|
* ```
|
|
980
1078
|
*
|
|
981
1079
|
* A CellIdsListener is provided when using the addCellIdsListener method. See
|
|
@@ -984,22 +1082,43 @@ export type RowListener<
|
|
|
984
1082
|
* When called, a CellIdsListener is given a reference to the Store, the Id of
|
|
985
1083
|
* the Table that changed, and the Id of the Row whose Cell Ids changed.
|
|
986
1084
|
*
|
|
1085
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
1086
|
+
* used to query which Ids changed during the transaction.
|
|
1087
|
+
*
|
|
987
1088
|
* @param store A reference to the Store that changed.
|
|
988
1089
|
* @param tableId The Id of the Table that changed.
|
|
989
1090
|
* @param rowId The Id of the Row that changed.
|
|
1091
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
1092
|
+
* since v3.3.
|
|
990
1093
|
* @category Listener
|
|
991
1094
|
*/
|
|
992
1095
|
export type CellIdsListener<
|
|
993
1096
|
Schemas extends OptionalSchemas,
|
|
994
1097
|
TableIdOrNull extends TableIdFromSchema<Schemas[0]> | null,
|
|
995
1098
|
RowIdOrNull extends IdOrNull,
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
? TableIdFromSchema<Schemas[0]>
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1099
|
+
Params extends any[] = (
|
|
1100
|
+
TableIdOrNull extends null ? TableIdFromSchema<Schemas[0]> : TableIdOrNull
|
|
1101
|
+
) extends infer TableId
|
|
1102
|
+
? TableId extends TableIdFromSchema<Schemas[0]>
|
|
1103
|
+
? [
|
|
1104
|
+
store: Store<Schemas>,
|
|
1105
|
+
tableId: TableId,
|
|
1106
|
+
rowId: RowIdOrNull extends null ? Id : RowIdOrNull,
|
|
1107
|
+
getIdChanges: GetIdChanges<CellIdFromSchema<Schemas[0], TableId>>,
|
|
1108
|
+
]
|
|
1109
|
+
: never
|
|
1110
|
+
: never,
|
|
1111
|
+
Params4 extends any[] =
|
|
1112
|
+
| Params
|
|
1113
|
+
| [store: never, tableId: never, rowId: never, getIdChanges: never],
|
|
1114
|
+
Params3 extends any[] = Truncate<Params4>,
|
|
1115
|
+
// Params2 extends any[] = Truncate<Params3>,
|
|
1116
|
+
// Params1 extends any[] = Truncate<Params2>,
|
|
1117
|
+
> = Params extends any
|
|
1118
|
+
? ((...params: Params4) => void) | ((...params: Params3) => void)
|
|
1119
|
+
: // | ((...params: Params2) => void)
|
|
1120
|
+
// | ((...params: Params1) => void)
|
|
1121
|
+
never;
|
|
1003
1122
|
|
|
1004
1123
|
/**
|
|
1005
1124
|
* The CellListener type describes a function that is used to listen to changes
|
|
@@ -1146,7 +1265,10 @@ export type ValuesListener<Schemas extends OptionalSchemas> = (
|
|
|
1146
1265
|
* This has schema-based typing. The following is a simplified representation:
|
|
1147
1266
|
*
|
|
1148
1267
|
* ```ts override
|
|
1149
|
-
* (
|
|
1268
|
+
* (
|
|
1269
|
+
* store: Store,
|
|
1270
|
+
* getIdChanges: GetIdChanges | undefined,
|
|
1271
|
+
* ) => void;
|
|
1150
1272
|
* ```
|
|
1151
1273
|
*
|
|
1152
1274
|
* A ValueIdsListener is provided when using the addValueIdsListener method. See
|
|
@@ -1154,11 +1276,17 @@ export type ValuesListener<Schemas extends OptionalSchemas> = (
|
|
|
1154
1276
|
*
|
|
1155
1277
|
* When called, a ValueIdsListener is given a reference to the Store.
|
|
1156
1278
|
*
|
|
1279
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
1280
|
+
* used to query which Ids changed during the transaction.
|
|
1281
|
+
*
|
|
1157
1282
|
* @param store A reference to the Store that changed.
|
|
1283
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
1284
|
+
* since v3.3.
|
|
1158
1285
|
* @category Listener
|
|
1159
1286
|
*/
|
|
1160
1287
|
export type ValueIdsListener<Schemas extends OptionalSchemas> = (
|
|
1161
1288
|
store: Store<Schemas>,
|
|
1289
|
+
getIdChanges: GetIdChanges<ValueIdFromSchema<Schemas[1]>> | undefined,
|
|
1162
1290
|
) => void;
|
|
1163
1291
|
|
|
1164
1292
|
/**
|
|
@@ -1315,6 +1443,25 @@ export type InvalidValueListener<Schemas extends OptionalSchemas> = (
|
|
|
1315
1443
|
invalidValues: any[],
|
|
1316
1444
|
) => void;
|
|
1317
1445
|
|
|
1446
|
+
/**
|
|
1447
|
+
* The GetIdChanges type describes a function that returns information about the
|
|
1448
|
+
* changes to a set of Ids during a transaction.
|
|
1449
|
+
*
|
|
1450
|
+
* A GetIdChanges function is provided to every listener when called due Ids in
|
|
1451
|
+
* the Store changing. It returns an object where each key is an Id that
|
|
1452
|
+
* changed. The listener can then easily identify which Ids have been added
|
|
1453
|
+
* (those with the value `1`), and which have been removed (those with the value
|
|
1454
|
+
* `-1`).
|
|
1455
|
+
*
|
|
1456
|
+
* @returns An object keyed by Id with a numerical value. 1 means the Id was
|
|
1457
|
+
* added, and 1 means it was removed.
|
|
1458
|
+
* @category Listener
|
|
1459
|
+
* @since v3.3
|
|
1460
|
+
*/
|
|
1461
|
+
export type GetIdChanges<ValidId extends Id> = () => {
|
|
1462
|
+
[Id in ValidId]?: 1 | -1;
|
|
1463
|
+
};
|
|
1464
|
+
|
|
1318
1465
|
/**
|
|
1319
1466
|
* The GetCellChange type describes a function that returns information about
|
|
1320
1467
|
* any Cell's changes during a transaction.
|
|
@@ -1580,6 +1727,11 @@ export type StoreListenerStats = {
|
|
|
1580
1727
|
* The number of TableListener functions registered with the Store.
|
|
1581
1728
|
*/
|
|
1582
1729
|
table?: number;
|
|
1730
|
+
/**
|
|
1731
|
+
* The number of TableCellIdsListener functions registered with the Store,
|
|
1732
|
+
* since v3.3.
|
|
1733
|
+
*/
|
|
1734
|
+
tableCellIds?: number;
|
|
1583
1735
|
/**
|
|
1584
1736
|
* The number of RowIdsListener functions registered with the Store.
|
|
1585
1737
|
*/
|
|
@@ -1720,6 +1872,7 @@ export type StoreListenerStats = {
|
|
|
1720
1872
|
* |Tables|getTables|setTables|delTables|addTablesListener|
|
|
1721
1873
|
* |Table Ids|getTableIds|-|-|addTableIdsListener|
|
|
1722
1874
|
* |Table|getTable|setTable|delTable|addTableListener|
|
|
1875
|
+
* |Table Cell Ids|getTableCellIds|-|-|addTableCellIdsListener|
|
|
1723
1876
|
* |Row Ids|getRowIds|-|-|addRowIdsListener|
|
|
1724
1877
|
* |Row Ids (sorted)|getSortedRowIds|-|-|addSortedRowIdsListener|
|
|
1725
1878
|
* |Row|getRow|setRow|delRow|addRowListener|
|
|
@@ -1928,6 +2081,51 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
1928
2081
|
tableId: TableId,
|
|
1929
2082
|
): Table<Schemas[0], TableId>;
|
|
1930
2083
|
|
|
2084
|
+
/**
|
|
2085
|
+
* The getTableCellIds method returns the Ids of every Cell used across the
|
|
2086
|
+
* whole Table.
|
|
2087
|
+
*
|
|
2088
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2089
|
+
*
|
|
2090
|
+
* ```ts override
|
|
2091
|
+
* getTableCellIds(tableId: Id): Ids;
|
|
2092
|
+
* ```
|
|
2093
|
+
*
|
|
2094
|
+
* Note that this returns a copy of, rather than a reference, to the list of
|
|
2095
|
+
* Ids, so changes made to the list are not made to the Store itself.
|
|
2096
|
+
*
|
|
2097
|
+
* @param tableId The Id of the Table in the Store.
|
|
2098
|
+
* @returns An array of the Ids of every Cell used across the whole Table.
|
|
2099
|
+
* @example
|
|
2100
|
+
* This example retrieves the Cell Ids used across a whole Table.
|
|
2101
|
+
*
|
|
2102
|
+
* ```js
|
|
2103
|
+
* const store = createStore().setTables({
|
|
2104
|
+
* pets: {
|
|
2105
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
2106
|
+
* felix: {species: 'cat', legs: 4},
|
|
2107
|
+
* cujo: {dangerous: true},
|
|
2108
|
+
* },
|
|
2109
|
+
* });
|
|
2110
|
+
* console.log(store.getTableCellIds('pets'));
|
|
2111
|
+
* // -> ['species', 'color', 'legs', 'dangerous']
|
|
2112
|
+
* ```
|
|
2113
|
+
* @example
|
|
2114
|
+
* This example retrieves the Cell Ids used across a Table that does not
|
|
2115
|
+
* exist, returning an empty array.
|
|
2116
|
+
*
|
|
2117
|
+
* ```js
|
|
2118
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
2119
|
+
* console.log(store.getTableCellIds('species'));
|
|
2120
|
+
* // -> []
|
|
2121
|
+
* ```
|
|
2122
|
+
* @category Getter
|
|
2123
|
+
* @since v3.3
|
|
2124
|
+
*/
|
|
2125
|
+
getTableCellIds<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
2126
|
+
tableId: TableId,
|
|
2127
|
+
): CellIdFromSchema<Schemas[0], TableId>[];
|
|
2128
|
+
|
|
1931
2129
|
/**
|
|
1932
2130
|
* The getRowIds method returns the Ids of every Row in a given Table.
|
|
1933
2131
|
*
|
|
@@ -2134,7 +2332,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2134
2332
|
): Row<Schemas[0], TableId>;
|
|
2135
2333
|
|
|
2136
2334
|
/**
|
|
2137
|
-
* The getCellIds method returns the Ids of every Cell in a given Row
|
|
2335
|
+
* The getCellIds method returns the Ids of every Cell in a given Row in a
|
|
2138
2336
|
* given Table.
|
|
2139
2337
|
*
|
|
2140
2338
|
* This has schema-based typing. The following is a simplified representation:
|
|
@@ -2162,8 +2360,8 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2162
2360
|
* // -> ['species', 'color']
|
|
2163
2361
|
* ```
|
|
2164
2362
|
* @example
|
|
2165
|
-
* This example retrieves the Cell Ids of a
|
|
2166
|
-
*
|
|
2363
|
+
* This example retrieves the Cell Ids of a Row that does not exist, returning
|
|
2364
|
+
* an empty array.
|
|
2167
2365
|
*
|
|
2168
2366
|
* ```js
|
|
2169
2367
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
@@ -2372,6 +2570,41 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2372
2570
|
*/
|
|
2373
2571
|
hasTable(tableId: TableIdFromSchema<Schemas[0]>): boolean;
|
|
2374
2572
|
|
|
2573
|
+
/**
|
|
2574
|
+
* The hasTableCell method returns a boolean indicating whether a given Cell
|
|
2575
|
+
* exists anywhere in a Table, not just in a specific Row.
|
|
2576
|
+
*
|
|
2577
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
2578
|
+
*
|
|
2579
|
+
* ```ts override
|
|
2580
|
+
* hasTableCell(tableId: Id, cellId: Id): boolean;
|
|
2581
|
+
* ```
|
|
2582
|
+
*
|
|
2583
|
+
* @param tableId The Id of a possible Table in the Store.
|
|
2584
|
+
* @param cellId The Id of a possible Cell in the Table.
|
|
2585
|
+
* @returns Whether a Cell with that Id exists anywhere in that Table.
|
|
2586
|
+
* @example
|
|
2587
|
+
* This example shows two simple Cell existence checks.
|
|
2588
|
+
*
|
|
2589
|
+
* ```js
|
|
2590
|
+
* const store = createStore().setTables({
|
|
2591
|
+
* pets: {fido: {species: 'dog'}, felix: {legs: 4}},
|
|
2592
|
+
* });
|
|
2593
|
+
* console.log(store.hasTableCell('pets', 'species'));
|
|
2594
|
+
* // -> true
|
|
2595
|
+
* console.log(store.hasTableCell('pets', 'legs'));
|
|
2596
|
+
* // -> true
|
|
2597
|
+
* console.log(store.hasTableCell('pets', 'color'));
|
|
2598
|
+
* // -> false
|
|
2599
|
+
* ```
|
|
2600
|
+
* @category Getter
|
|
2601
|
+
* @since v3.3
|
|
2602
|
+
*/
|
|
2603
|
+
hasTableCell<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
2604
|
+
tableId: TableId,
|
|
2605
|
+
cellId: CellIdFromSchema<Schemas[0], TableId>,
|
|
2606
|
+
): boolean;
|
|
2607
|
+
|
|
2375
2608
|
/**
|
|
2376
2609
|
* The hasRow method returns a boolean indicating whether a given Row exists
|
|
2377
2610
|
* in the Store.
|
|
@@ -2401,7 +2634,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2401
2634
|
|
|
2402
2635
|
/**
|
|
2403
2636
|
* The hasCell method returns a boolean indicating whether a given Cell exists
|
|
2404
|
-
* in
|
|
2637
|
+
* in a given Row in a given Table.
|
|
2405
2638
|
*
|
|
2406
2639
|
* This has schema-based typing. The following is a simplified representation:
|
|
2407
2640
|
*
|
|
@@ -4220,6 +4453,45 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4220
4453
|
*/
|
|
4221
4454
|
forEachTable(tableCallback: TableCallback<Schemas[0]>): void;
|
|
4222
4455
|
|
|
4456
|
+
/**
|
|
4457
|
+
* The forEachTableCell method takes a function that it will then call for
|
|
4458
|
+
* each Cell used across the whole Table.
|
|
4459
|
+
*
|
|
4460
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
4461
|
+
*
|
|
4462
|
+
* ```ts override
|
|
4463
|
+
* forEachTableCell(tableId: Id, tableCellCallback: TableCellCallback): void;
|
|
4464
|
+
* ```
|
|
4465
|
+
*
|
|
4466
|
+
* This method is useful for iterating over the Cell structure of the Table in
|
|
4467
|
+
* a functional style. The `tableCellCallback` parameter is a
|
|
4468
|
+
* TableCellCallback function that will be called with the Id of each Cell and
|
|
4469
|
+
* the count of Rows in the Table in which it appears.
|
|
4470
|
+
*
|
|
4471
|
+
* @param tableId The Id of the Table containing the Cells to iterate over.
|
|
4472
|
+
* @param tableCellCallback The function that should be called for every Cell
|
|
4473
|
+
* Id used across the whole Table.
|
|
4474
|
+
* @example
|
|
4475
|
+
* This example iterates over each Cell Id used across the whole Table.
|
|
4476
|
+
*
|
|
4477
|
+
* ```js
|
|
4478
|
+
* const store = createStore().setTables({
|
|
4479
|
+
* pets: {fido: {species: 'dog'}, felix: {species: 'cat', legs: 4}},
|
|
4480
|
+
* });
|
|
4481
|
+
* store.forEachTableCell('pets', (cellId, count) => {
|
|
4482
|
+
* console.log(`${cellId}: ${count}`);
|
|
4483
|
+
* });
|
|
4484
|
+
* // -> 'species: 2'
|
|
4485
|
+
* // -> 'legs: 1'
|
|
4486
|
+
* ```
|
|
4487
|
+
* @category Iterator
|
|
4488
|
+
* @since v3.3
|
|
4489
|
+
*/
|
|
4490
|
+
forEachTableCell<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
4491
|
+
tableId: TableId,
|
|
4492
|
+
tableCellCallback: TableCellCallback<Schemas[0], TableId>,
|
|
4493
|
+
): void;
|
|
4494
|
+
|
|
4223
4495
|
/**
|
|
4224
4496
|
* The forEachRow method takes a function that it will then call for each Row
|
|
4225
4497
|
* in a specified Table.
|
|
@@ -4582,6 +4854,123 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4582
4854
|
mutator?: boolean,
|
|
4583
4855
|
): Id;
|
|
4584
4856
|
|
|
4857
|
+
/**
|
|
4858
|
+
* The addTableCellIdsListener method registers a listener function with the
|
|
4859
|
+
* Store that will be called whenever the Cell Ids that appear anywhere in a
|
|
4860
|
+
* Table change.
|
|
4861
|
+
*
|
|
4862
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
4863
|
+
*
|
|
4864
|
+
* ```ts override
|
|
4865
|
+
* addTableCellIdsListener(
|
|
4866
|
+
* tableId: IdOrNull,
|
|
4867
|
+
* listener: TableCellIdsListener,
|
|
4868
|
+
* mutator?: boolean,
|
|
4869
|
+
* ): Id;
|
|
4870
|
+
* ```
|
|
4871
|
+
*
|
|
4872
|
+
* The provided listener is a TableCellIdsListener function, and will be
|
|
4873
|
+
* called with a reference to the Store and the Id of the Table that changed.
|
|
4874
|
+
*
|
|
4875
|
+
* By default, such a listener is only called when a Cell Id is added or
|
|
4876
|
+
* removed from the whole of the Table. To listen to all changes in the Table,
|
|
4877
|
+
* use the addTableListener method.
|
|
4878
|
+
*
|
|
4879
|
+
* You can either listen to a single Table (by specifying its Id as the
|
|
4880
|
+
* method's first parameter) or changes to any Table (by providing a `null`
|
|
4881
|
+
* wildcard).
|
|
4882
|
+
*
|
|
4883
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
4884
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
4885
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
4886
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
4887
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
4888
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
4889
|
+
* though they will fire non-mutator listeners.
|
|
4890
|
+
*
|
|
4891
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
4892
|
+
* @param listener The function that will be called whenever the Cell Ids that
|
|
4893
|
+
* appear anywhere in a Table change.
|
|
4894
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
4895
|
+
* Store data.
|
|
4896
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
4897
|
+
* explicitly, or to remove it.
|
|
4898
|
+
* @example
|
|
4899
|
+
* This example registers a listener that responds to any change to the Cell
|
|
4900
|
+
* Ids that appear anywhere in a Table.
|
|
4901
|
+
*
|
|
4902
|
+
* ```js
|
|
4903
|
+
* const store = createStore().setTables({
|
|
4904
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4905
|
+
* });
|
|
4906
|
+
* const listenerId = store.addTableCellIdsListener('pets', (store) => {
|
|
4907
|
+
* console.log('Cell Ids in pets table changed');
|
|
4908
|
+
* console.log(store.getTableCellIds('pets'));
|
|
4909
|
+
* });
|
|
4910
|
+
*
|
|
4911
|
+
* store.setRow('pets', 'felix', {species: 'cat', legs: 4});
|
|
4912
|
+
* // -> 'Cell Ids in pets table changed'
|
|
4913
|
+
* // -> ['species', 'color', 'legs']
|
|
4914
|
+
*
|
|
4915
|
+
* store.delListener(listenerId);
|
|
4916
|
+
* ```
|
|
4917
|
+
* @example
|
|
4918
|
+
* This example registers a listener that responds to any change to the Cell
|
|
4919
|
+
* Ids that appear anywhere in any Table.
|
|
4920
|
+
*
|
|
4921
|
+
* ```js
|
|
4922
|
+
* const store = createStore().setTables({
|
|
4923
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4924
|
+
* species: {dog: {price: 5}},
|
|
4925
|
+
* });
|
|
4926
|
+
* const listenerId = store.addTableCellIdsListener(
|
|
4927
|
+
* null,
|
|
4928
|
+
* (store, tableId) => {
|
|
4929
|
+
* console.log(`Cell Ids in ${tableId} table changed`);
|
|
4930
|
+
* console.log(store.getTableCellIds(tableId));
|
|
4931
|
+
* },
|
|
4932
|
+
* );
|
|
4933
|
+
*
|
|
4934
|
+
* store.setRow('pets', 'felix', {species: 'cat', legs: 4});
|
|
4935
|
+
* // -> 'Cell Ids in pets table changed'
|
|
4936
|
+
* // -> ['species', 'color', 'legs']
|
|
4937
|
+
*
|
|
4938
|
+
* store.setRow('species', 'cat', {price: 4, friendly: true});
|
|
4939
|
+
* // -> 'Cell Ids in species table changed'
|
|
4940
|
+
* // -> ['price', 'friendly']
|
|
4941
|
+
*
|
|
4942
|
+
* store.delListener(listenerId);
|
|
4943
|
+
* ```
|
|
4944
|
+
* @example
|
|
4945
|
+
* This example registers a listener that responds to the Cell Ids that appear
|
|
4946
|
+
* anywhere in a Table, and which also mutates the Store itself.
|
|
4947
|
+
*
|
|
4948
|
+
* ```js
|
|
4949
|
+
* const store = createStore().setTables({
|
|
4950
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
4951
|
+
* });
|
|
4952
|
+
* const listenerId = store.addTableCellIdsListener(
|
|
4953
|
+
* 'pets',
|
|
4954
|
+
* (store, tableId) => store.setCell('meta', 'update', tableId, true),
|
|
4955
|
+
* true, // mutator
|
|
4956
|
+
* );
|
|
4957
|
+
*
|
|
4958
|
+
* store.setRow('pets', 'felix', {species: 'cat', legs: 4});
|
|
4959
|
+
* console.log(store.getTable('meta'));
|
|
4960
|
+
* // -> {update: {pets: true}}
|
|
4961
|
+
*
|
|
4962
|
+
* store.delListener(listenerId);
|
|
4963
|
+
* ```
|
|
4964
|
+
* @category Listener
|
|
4965
|
+
*/
|
|
4966
|
+
addTableCellIdsListener<
|
|
4967
|
+
TableIdOrNull extends TableIdFromSchema<Schemas[0]> | null,
|
|
4968
|
+
>(
|
|
4969
|
+
tableId: TableIdOrNull,
|
|
4970
|
+
listener: TableCellIdsListener<Schemas, TableIdOrNull>,
|
|
4971
|
+
mutator?: boolean,
|
|
4972
|
+
): Id;
|
|
4973
|
+
|
|
4585
4974
|
/**
|
|
4586
4975
|
* The addRowIdsListener method registers a listener function with the Store
|
|
4587
4976
|
* that will be called whenever the Row Ids in a Table change.
|
|
@@ -4780,7 +5169,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4780
5169
|
* store.delListener(listenerId);
|
|
4781
5170
|
* ```
|
|
4782
5171
|
* @example
|
|
4783
|
-
* This
|
|
5172
|
+
* This example registers a listener that responds to any change to a
|
|
4784
5173
|
* paginated section of the sorted Row Ids of a specific Table.
|
|
4785
5174
|
*
|
|
4786
5175
|
* ```js
|
|
@@ -432,7 +432,7 @@ export interface Tools<in out Schemas extends OptionalSchemas> {
|
|
|
432
432
|
* // -> `export type Tables = {pets?: {[rowId: Id]: {price?: number}}};`
|
|
433
433
|
*
|
|
434
434
|
* const tsLines = ts.split('\n');
|
|
435
|
-
* console.log(tsLines[
|
|
435
|
+
* console.log(tsLines[81]);
|
|
436
436
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
437
437
|
* ```
|
|
438
438
|
* @example
|
|
@@ -453,7 +453,7 @@ export interface Tools<in out Schemas extends OptionalSchemas> {
|
|
|
453
453
|
* // -> 'export type Tables = {pets?: {[rowId: Id]: {price: number}}};'
|
|
454
454
|
*
|
|
455
455
|
* const tsLines = ts.split('\n');
|
|
456
|
-
* console.log(tsLines[
|
|
456
|
+
* console.log(tsLines[83]);
|
|
457
457
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
458
458
|
* ```
|
|
459
459
|
* @category Modelling
|