tinybase 3.2.0-beta.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/bin/cli.js +1 -1
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/cjs/checkpoints.cjs +1 -1
- package/lib/cjs/checkpoints.cjs.gz +0 -0
- package/lib/cjs/indexes.cjs +1 -1
- package/lib/cjs/indexes.cjs.gz +0 -0
- package/lib/cjs/metrics.cjs +1 -1
- package/lib/cjs/metrics.cjs.gz +0 -0
- package/lib/cjs/persisters.cjs +1 -1
- package/lib/cjs/persisters.cjs.gz +0 -0
- package/lib/cjs/queries.cjs +1 -1
- package/lib/cjs/queries.cjs.gz +0 -0
- package/lib/cjs/relationships.cjs +1 -1
- package/lib/cjs/relationships.cjs.gz +0 -0
- 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/checkpoints.cjs +1 -1
- package/lib/cjs-es6/checkpoints.cjs.gz +0 -0
- package/lib/cjs-es6/indexes.cjs +1 -1
- package/lib/cjs-es6/indexes.cjs.gz +0 -0
- package/lib/cjs-es6/metrics.cjs +1 -1
- package/lib/cjs-es6/metrics.cjs.gz +0 -0
- package/lib/cjs-es6/persisters.cjs +1 -1
- package/lib/cjs-es6/persisters.cjs.gz +0 -0
- package/lib/cjs-es6/queries.cjs +1 -1
- package/lib/cjs-es6/queries.cjs.gz +0 -0
- package/lib/cjs-es6/relationships.cjs +1 -1
- package/lib/cjs-es6/relationships.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/checkpoints.js +2 -2
- package/lib/debug/indexes.js +2 -2
- package/lib/debug/metrics.js +2 -2
- package/lib/debug/persisters.js +2 -2
- package/lib/debug/queries.js +1 -1
- package/lib/debug/relationships.js +2 -2
- package/lib/debug/store.js +89 -48
- package/lib/debug/tinybase.js +92 -51
- package/lib/debug/tools.js +106 -5
- package/lib/debug/ui-react.js +27 -2
- 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.js +1 -1
- package/lib/es6/persisters.js.gz +0 -0
- package/lib/es6/queries.js +1 -1
- package/lib/es6/queries.js.gz +0 -0
- package/lib/es6/relationships.js +1 -1
- package/lib/es6/relationships.js.gz +0 -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/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.js +1 -1
- package/lib/persisters.js.gz +0 -0
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.js +1 -1
- package/lib/relationships.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 +386 -30
- package/lib/types/tools.d.ts +2 -2
- package/lib/types/ui-react.d.ts +167 -0
- package/lib/types/with-schemas/store.d.ts +496 -37
- package/lib/types/with-schemas/tools.d.ts +2 -2
- package/lib/types/with-schemas/ui-react.d.ts +193 -5
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/persisters.js +1 -1
- package/lib/umd/persisters.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/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/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.js +1 -1
- package/lib/umd-es6/persisters.js.gz +0 -0
- package/lib/umd-es6/queries.js +1 -1
- package/lib/umd-es6/queries.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.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 +52 -28
- package/readme.md +14 -14
|
@@ -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
|
/**
|
|
@@ -1253,10 +1381,10 @@ export type ValueListener<
|
|
|
1253
1381
|
* ) => void;
|
|
1254
1382
|
* ```
|
|
1255
1383
|
*
|
|
1256
|
-
*
|
|
1384
|
+
* An InvalidCellListener is provided when using the addInvalidCellListener
|
|
1257
1385
|
* method. See that method for specific examples.
|
|
1258
1386
|
*
|
|
1259
|
-
* When called,
|
|
1387
|
+
* When called, an InvalidCellListener is given a reference to the Store, the Id
|
|
1260
1388
|
* of the Table, the Id of the Row, and the Id of Cell that was being attempted
|
|
1261
1389
|
* to be changed. It is also given the invalid value of the Cell, which could
|
|
1262
1390
|
* have been of absolutely any type. Since there could have been multiple failed
|
|
@@ -1293,11 +1421,11 @@ export type InvalidCellListener<Schemas extends OptionalSchemas> = (
|
|
|
1293
1421
|
* ) => void;
|
|
1294
1422
|
* ```
|
|
1295
1423
|
*
|
|
1296
|
-
*
|
|
1424
|
+
* An InvalidValueListener is provided when using the addInvalidValueListener
|
|
1297
1425
|
* method. See that method for specific examples.
|
|
1298
1426
|
*
|
|
1299
|
-
* When called,
|
|
1300
|
-
* Id of Value that was being attempted to be changed. It is also given the
|
|
1427
|
+
* When called, an InvalidValueListener is given a reference to the Store and
|
|
1428
|
+
* the Id of Value that was being attempted to be changed. It is also given the
|
|
1301
1429
|
* invalid value of the Value, which could have been of absolutely any type.
|
|
1302
1430
|
* Since there could have been multiple failed attempts to set the Value within
|
|
1303
1431
|
* a single transaction, this is an array containing each attempt,
|
|
@@ -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|
|
|
@@ -1811,8 +1964,8 @@ export type StoreListenerStats = {
|
|
|
1811
1964
|
*/
|
|
1812
1965
|
export interface Store<in out Schemas extends OptionalSchemas> {
|
|
1813
1966
|
/**
|
|
1814
|
-
* The getTables method returns a Tables object containing the entire
|
|
1815
|
-
* the Store.
|
|
1967
|
+
* The getTables method returns a Tables object containing the entire tabular
|
|
1968
|
+
* data of the Store.
|
|
1816
1969
|
*
|
|
1817
1970
|
* This has schema-based typing. The following is a simplified representation:
|
|
1818
1971
|
*
|
|
@@ -1824,9 +1977,9 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
1824
1977
|
* data, so changes made to the returned object are not made to the Store
|
|
1825
1978
|
* itself.
|
|
1826
1979
|
*
|
|
1827
|
-
* @returns A Tables object containing the
|
|
1980
|
+
* @returns A Tables object containing the tabular data of the Store.
|
|
1828
1981
|
* @example
|
|
1829
|
-
* This example retrieves the data in a Store.
|
|
1982
|
+
* This example retrieves the tabular data in a Store.
|
|
1830
1983
|
*
|
|
1831
1984
|
* ```js
|
|
1832
1985
|
* const store = createStore().setTables({
|
|
@@ -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
|
*
|
|
@@ -1999,7 +2197,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
1999
2197
|
*
|
|
2000
2198
|
* @param tableId The Id of the Table in the Store.
|
|
2001
2199
|
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
2002
|
-
* `undefined` to by
|
|
2200
|
+
* `undefined` to sort by the Row Id itself.
|
|
2003
2201
|
* @param descending Whether the sorting should be in descending order.
|
|
2004
2202
|
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
2005
2203
|
* any.
|
|
@@ -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'}}});
|
|
@@ -2234,9 +2432,9 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2234
2432
|
* data, so changes made to the returned object are not made to the Store
|
|
2235
2433
|
* itself.
|
|
2236
2434
|
*
|
|
2237
|
-
* @returns An object containing the
|
|
2435
|
+
* @returns An object containing the set of keyed Values in the Store.
|
|
2238
2436
|
* @example
|
|
2239
|
-
* This example retrieves the keyed Values
|
|
2437
|
+
* This example retrieves the set of keyed Values in the Store.
|
|
2240
2438
|
*
|
|
2241
2439
|
* ```js
|
|
2242
2440
|
* const store = createStore().setValues({open: true, employees: 3});
|
|
@@ -2244,7 +2442,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2244
2442
|
* // -> {open: true, employees: 3}
|
|
2245
2443
|
* ```
|
|
2246
2444
|
* @example
|
|
2247
|
-
* This example retrieves
|
|
2445
|
+
* This example retrieves Values from a Store that has none, returning an
|
|
2248
2446
|
* empty object.
|
|
2249
2447
|
*
|
|
2250
2448
|
* ```js
|
|
@@ -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
|
*
|
|
@@ -2671,7 +2904,8 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2671
2904
|
getSchemaJson(): Json;
|
|
2672
2905
|
|
|
2673
2906
|
/**
|
|
2674
|
-
* The setTables method takes an object and sets the entire data of
|
|
2907
|
+
* The setTables method takes an object and sets the entire tabular data of
|
|
2908
|
+
* the Store.
|
|
2675
2909
|
*
|
|
2676
2910
|
* This has schema-based typing. The following is a simplified representation:
|
|
2677
2911
|
*
|
|
@@ -2695,7 +2929,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2695
2929
|
*
|
|
2696
2930
|
* @param tables The data of the Store to be set.
|
|
2697
2931
|
* @example
|
|
2698
|
-
* This example sets the data of a Store.
|
|
2932
|
+
* This example sets the tabular data of a Store.
|
|
2699
2933
|
*
|
|
2700
2934
|
* ```js
|
|
2701
2935
|
* const store = createStore().setTables({
|
|
@@ -2706,8 +2940,8 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2706
2940
|
* // -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}
|
|
2707
2941
|
* ```
|
|
2708
2942
|
* @example
|
|
2709
|
-
* This example attempts to set the data of an existing Store with
|
|
2710
|
-
* invalid, and then completely invalid, Tables objects.
|
|
2943
|
+
* This example attempts to set the tabular data of an existing Store with
|
|
2944
|
+
* partly invalid, and then completely invalid, Tables objects.
|
|
2711
2945
|
*
|
|
2712
2946
|
* ```js
|
|
2713
2947
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
@@ -2851,7 +3085,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2851
3085
|
* This has schema-based typing. The following is a simplified representation:
|
|
2852
3086
|
*
|
|
2853
3087
|
* ```ts override
|
|
2854
|
-
* addRow(tableId: Id, row: Row): Id | undefined;
|
|
3088
|
+
* addRow(tableId: Id, row: Row, reuseRowIds?: boolean): Id | undefined;
|
|
2855
3089
|
* ```
|
|
2856
3090
|
*
|
|
2857
3091
|
* This method will cause listeners to be called for any Table, Row, Cell, or
|
|
@@ -2869,8 +3103,17 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2869
3103
|
* Row is added to the Table. However it is likely to be a string
|
|
2870
3104
|
* representation of an increasing integer.
|
|
2871
3105
|
*
|
|
3106
|
+
* The `reuseRowIds` parameter defaults to `true`, which means that if you
|
|
3107
|
+
* delete a Row and then add another, the Id will be re-used - unless you
|
|
3108
|
+
* delete the entire Table, in which case all Row Ids will reset. Otherwise,
|
|
3109
|
+
* if you specify `reuseRowIds` to be `false`, then the Id will be a
|
|
3110
|
+
* monotonically increasing string representation of an increasing integer,
|
|
3111
|
+
* regardless of any you may have previously deleted.
|
|
3112
|
+
*
|
|
2872
3113
|
* @param tableId The Id of the Table in the Store.
|
|
2873
3114
|
* @param row The data of a single Row to be added.
|
|
3115
|
+
* @param reuseRowIds Whether Ids should be recycled from previously deleted
|
|
3116
|
+
* Row objects, defaulting to `true`.
|
|
2874
3117
|
* @returns A reference to the Store.
|
|
2875
3118
|
* @example
|
|
2876
3119
|
* This example adds a single Row.
|
|
@@ -2904,6 +3147,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
2904
3147
|
addRow<TableId extends TableIdFromSchema<Schemas[0]>>(
|
|
2905
3148
|
tableId: TableId,
|
|
2906
3149
|
row: Row<Schemas[0], TableId, true>,
|
|
3150
|
+
reuseRowIds?: boolean,
|
|
2907
3151
|
): Id | undefined;
|
|
2908
3152
|
|
|
2909
3153
|
/**
|
|
@@ -3347,7 +3591,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
3347
3591
|
* // -> {}
|
|
3348
3592
|
* ```
|
|
3349
3593
|
* @example
|
|
3350
|
-
* This example attempts to set
|
|
3594
|
+
* This example attempts to set both the tabular and keyed value contents of a
|
|
3351
3595
|
* Store from an invalid serialization.
|
|
3352
3596
|
*
|
|
3353
3597
|
* ```js
|
|
@@ -4209,6 +4453,45 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4209
4453
|
*/
|
|
4210
4454
|
forEachTable(tableCallback: TableCallback<Schemas[0]>): void;
|
|
4211
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
|
+
|
|
4212
4495
|
/**
|
|
4213
4496
|
* The forEachRow method takes a function that it will then call for each Row
|
|
4214
4497
|
* in a specified Table.
|
|
@@ -4571,6 +4854,123 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4571
4854
|
mutator?: boolean,
|
|
4572
4855
|
): Id;
|
|
4573
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
|
+
|
|
4574
4974
|
/**
|
|
4575
4975
|
* The addRowIdsListener method registers a listener function with the Store
|
|
4576
4976
|
* that will be called whenever the Row Ids in a Table change.
|
|
@@ -4723,7 +5123,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4723
5123
|
*
|
|
4724
5124
|
* @param tableId The Id of the Table to listen to.
|
|
4725
5125
|
* @param cellId The Id of the Cell whose values are used for the sorting, or
|
|
4726
|
-
* `undefined` to by
|
|
5126
|
+
* `undefined` to sort by the Row Id itself.
|
|
4727
5127
|
* @param descending Whether the sorting should be in descending order.
|
|
4728
5128
|
* @param offset The number of Row Ids to skip for pagination purposes, if
|
|
4729
5129
|
* any.
|
|
@@ -4769,7 +5169,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
4769
5169
|
* store.delListener(listenerId);
|
|
4770
5170
|
* ```
|
|
4771
5171
|
* @example
|
|
4772
|
-
* This
|
|
5172
|
+
* This example registers a listener that responds to any change to a
|
|
4773
5173
|
* paginated section of the sorted Row Ids of a specific Table.
|
|
4774
5174
|
*
|
|
4775
5175
|
* ```js
|
|
@@ -5982,6 +6382,57 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
5982
6382
|
mutator?: boolean,
|
|
5983
6383
|
): Id;
|
|
5984
6384
|
|
|
6385
|
+
/**
|
|
6386
|
+
* The addStartTransactionListener method registers a listener function with
|
|
6387
|
+
* the Store that will be called at the start of a transaction.
|
|
6388
|
+
*
|
|
6389
|
+
* This has schema-based typing. The following is a simplified representation:
|
|
6390
|
+
*
|
|
6391
|
+
* ```ts override
|
|
6392
|
+
* addStartTransactionListener(listener: TransactionListener): Id;
|
|
6393
|
+
* ```
|
|
6394
|
+
*
|
|
6395
|
+
* The provided TransactionListener will receive a reference to the Store and
|
|
6396
|
+
* two booleans to indicate whether Cell or Value data has been touched during
|
|
6397
|
+
* the transaction. Since this is called at the start, they will both be
|
|
6398
|
+
* `false`!
|
|
6399
|
+
*
|
|
6400
|
+
* Note that a TransactionListener added to the Store with this method can
|
|
6401
|
+
* mutate the Store, and its changes will be treated as part of the
|
|
6402
|
+
* transaction that is starting.
|
|
6403
|
+
*
|
|
6404
|
+
* @returns A unique Id for the listener that can later be used to remove it.
|
|
6405
|
+
* @example
|
|
6406
|
+
* This example registers a listener that is called at start end of the
|
|
6407
|
+
* transaction, just before its listeners will be called.
|
|
6408
|
+
*
|
|
6409
|
+
* ```js
|
|
6410
|
+
* const store = createStore()
|
|
6411
|
+
* .setTables({
|
|
6412
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
6413
|
+
* })
|
|
6414
|
+
* .setValues({open: true, employees: 3});
|
|
6415
|
+
* const listenerId = store.addStartTransactionListener(
|
|
6416
|
+
* (store, cellsTouched, valuesTouched) => {
|
|
6417
|
+
* console.log('Transaction started');
|
|
6418
|
+
* },
|
|
6419
|
+
* );
|
|
6420
|
+
*
|
|
6421
|
+
* store.transaction(() =>
|
|
6422
|
+
* store.setCell('pets', 'fido', 'color', 'brown').setValue('employees', 3),
|
|
6423
|
+
* );
|
|
6424
|
+
* // -> 'Transaction started'
|
|
6425
|
+
*
|
|
6426
|
+
* store.callListener(listenerId);
|
|
6427
|
+
* // -> 'Transaction started'
|
|
6428
|
+
*
|
|
6429
|
+
* store.delListener(listenerId);
|
|
6430
|
+
* ```
|
|
6431
|
+
* @category Listener
|
|
6432
|
+
* @since v3.2.0
|
|
6433
|
+
*/
|
|
6434
|
+
addStartTransactionListener(listener: TransactionListener<Schemas>): Id;
|
|
6435
|
+
|
|
5985
6436
|
/**
|
|
5986
6437
|
* The addWillFinishTransactionListener method registers a listener function
|
|
5987
6438
|
* with the Store that will be called just before other non-mutating listeners
|
|
@@ -6008,6 +6459,11 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
6008
6459
|
* value of `cellsTouched` and `valuesTouched` in the listener will be `false`
|
|
6009
6460
|
* because all changes have been reverted.
|
|
6010
6461
|
*
|
|
6462
|
+
* Note that a TransactionListener added to the Store with this method can
|
|
6463
|
+
* mutate the Store itself, and its changes will be treated as part of the
|
|
6464
|
+
* transaction that is starting (and may fire non-mutating listeners after
|
|
6465
|
+
* this).
|
|
6466
|
+
*
|
|
6011
6467
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
6012
6468
|
* @example
|
|
6013
6469
|
* This example registers a listener that is called at the end of the
|
|
@@ -6107,6 +6563,9 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
6107
6563
|
* value of `cellsTouched` and `valuesTouched` in the listener will be `false`
|
|
6108
6564
|
* because all changes have been reverted.
|
|
6109
6565
|
*
|
|
6566
|
+
* Note that a TransactionListener added to the Store with this method
|
|
6567
|
+
* _cannot_ mutate the Store itself, and attempts to do so will fail silently.
|
|
6568
|
+
*
|
|
6110
6569
|
* @returns A unique Id for the listener that can later be used to remove it.
|
|
6111
6570
|
* @example
|
|
6112
6571
|
* This example registers a listener that is called at the end of the
|
|
@@ -6271,7 +6730,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
|
|
|
6271
6730
|
* ```
|
|
6272
6731
|
* @example
|
|
6273
6732
|
* This example registers listeners for the end of transactions, and for
|
|
6274
|
-
* invalid Cells.
|
|
6733
|
+
* invalid Cells. They are explicitly called, meaninglessly. The former
|
|
6275
6734
|
* receives empty arguments. The latter is not called at all.
|
|
6276
6735
|
*
|
|
6277
6736
|
* ```js
|