Skip to content

Commit cb18f1f

Browse files
committed
[docs] Documentation for Id reuse
1 parent 997cb05 commit cb18f1f

File tree

7 files changed

+28
-1
lines changed

7 files changed

+28
-1
lines changed

site/guides/10_releases.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ These are each described in the new TinyBase and TypeScript guide.
4343
Also in v3.1, the ORM-like type definition generation in the tools module has
4444
been extended to emit ui-react definitions.
4545

46+
Finally, v3.0.1 adds a `reuseRowIds` parameter to the addRow method and the
47+
useAddRowCallback hook. It defaults to `true`, for backwards compatibility, but
48+
if set to `false`, new Row Ids will not be reused unless the whole Table is
49+
deleted.
50+
4651
## v3.0
4752

4853
This major new release adds key/value store functionality to TinyBase. Alongside

src/types/docs/store.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,8 +1957,17 @@
19571957
* Row is added to the Table. However it is likely to be a string
19581958
* representation of an increasing integer.
19591959
*
1960+
* The `reuseRowIds` parameter defaults to `true`, which means that if you
1961+
* delete a Row and then add another, the Id will be re-used - unless you
1962+
* delete the entire Table, in which case all Row Ids will reset. Otherwise,
1963+
* if you specify `reuseRowIds` to be `false`, then the Id will be a
1964+
* monotonically increasing string representation of an increasing integer,
1965+
* regardless of any you may have previously deleted.
1966+
*
19601967
* @param tableId The Id of the Table in the Store.
19611968
* @param row The data of a single Row to be added.
1969+
* @param reuseRowIds Whether Ids should be recycled from previously deleted
1970+
* Row objects, defaulting to `true`.
19621971
* @returns A reference to the Store.
19631972
* @example
19641973
* This example adds a single Row.

src/types/docs/ui-react.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,13 @@
14431443
* hook's `storeOrStoreId` parameter) is always automatically used as a hook
14441444
* dependency for the callback.
14451445
*
1446+
* The `reuseRowIds` parameter defaults to `true`, which means that if you
1447+
* delete a Row and then add another, the Id will be re-used - unless you delete
1448+
* the entire Table, in which case all Row Ids will reset. Otherwise, if you
1449+
* specify `reuseRowIds` to be `false`, then the Id will be a monotonically
1450+
* increasing string representation of an increasing integer, regardless of any
1451+
* you may have previously deleted.
1452+
*
14461453
* @param tableId The Id of the Table in the Store.
14471454
* @param getRow A function which returns the Row object that will be used to
14481455
* update the Store, based on the parameter the callback will receive (and which
@@ -1458,6 +1465,9 @@
14581465
* @param thenDeps An optional array of dependencies for the `then` function,
14591466
* which, if any change, result in the regeneration of the callback. This
14601467
* parameter defaults to an empty array.
1468+
* @param reuseRowIds Whether Ids should be recycled from previously deleted Row
1469+
* objects, defaulting to `true`.
1470+
*
14611471
* @returns A parameterized callback for subsequent use.
14621472
* @example
14631473
* This example uses the useAddRowCallback hook to create an event handler which

src/types/store.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export interface Store {
358358
setRow(tableId: Id, rowId: Id, row: Row): Store;
359359

360360
/// Store.addRow
361-
addRow(tableId: Id, row: Row): Id | undefined;
361+
addRow(tableId: Id, row: Row, reuseRowIds?: boolean): Id | undefined;
362362

363363
/// Store.setPartialRow
364364
setPartialRow(tableId: Id, rowId: Id, partialRow: Row): Store;

src/types/ui-react.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export function useAddRowCallback<Parameter>(
174174
storeOrStoreId?: StoreOrStoreId,
175175
then?: (rowId: Id | undefined, store: Store, row: Row) => void,
176176
thenDeps?: React.DependencyList,
177+
reuseRowIds?: boolean,
177178
): ParameterizedCallback<Parameter>;
178179

179180
/// useSetPartialRowCallback

src/types/with-schemas/store.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ export interface Store<in out Schemas extends OptionalSchemas> {
685685
addRow<TableId extends TableIdFromSchema<Schemas[0]>>(
686686
tableId: TableId,
687687
row: Row<Schemas[0], TableId, true>,
688+
reuseRowIds?: boolean,
688689
): Id | undefined;
689690

690691
/// Store.setPartialRow

src/types/with-schemas/ui-react.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export type WithSchemas<Schemas extends OptionalSchemas> = {
256256
storeOrStoreId?: StoreOrStoreId<Schemas>,
257257
then?: (rowId: Id | undefined, store: Store<Schemas>, row: AddRow) => void,
258258
thenDeps?: React.DependencyList,
259+
reuseRowIds?: boolean,
259260
) => ParameterizedCallback<Parameter>;
260261

261262
/// useSetPartialRowCallback

0 commit comments

Comments
 (0)