Skip to content

Commit c2e2f8d

Browse files
committed
[docs] v3.3 Guides
1 parent ceb143e commit c2e2f8d

File tree

6 files changed

+71
-5
lines changed

6 files changed

+71
-5
lines changed

site/guides/10_releases.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,70 @@
33
This is a reverse chronological list of the major TinyBase releases, with
44
highlighted features.
55

6+
## v3.3
7+
8+
This release allows you to track the Cell Ids used across a whole Table,
9+
regardless of which Row they are in.
10+
11+
In a Table (particularly in a Store without a TablesSchema), different Rows can
12+
use different Cells. Consider this Store, where each pet has a different set of
13+
Cell Ids:
14+
15+
```js
16+
const store = createStore();
17+
18+
store.setTable('pets', {
19+
fido: {species: 'dog'},
20+
felix: {species: 'cat', friendly: true},
21+
cujo: {legs: 4},
22+
});
23+
```
24+
25+
Prior to v3.3, you could only get the Cell Ids used in each Row at a time (with
26+
the getCellIds method). But you can now use the getTableCellIds method to get
27+
the union of all the Cell Ids used across the Table:
28+
29+
```js
30+
console.log(store.getCellIds('pets', 'fido')); // previously available
31+
// -> ['species']
32+
33+
console.log(store.getTableCellIds('pets')); // new in v3.3
34+
// -> ['species', 'friendly', 'legs']
35+
```
36+
37+
You can register a listener to track the Cell Ids used across a Table with the
38+
new addTableCellIdsListener method. Use cases for this might include knowing
39+
which headers to render when displaying a sparse Table in a user interface, or
40+
synchronizing data with relational or column-oriented database system.
41+
42+
There is also a corresponding useTableCellIds hook in the optional ui-react
43+
module for accessing these Ids reactively, and a useTableCellIdsListener hook
44+
for more advanced purposes.
45+
46+
Note that the bookkeeping behind these new accessors and listeners is efficient
47+
and should not be slowed by the number of Rows in the Table.
48+
49+
This release also passes a getIdChanges function to every Id-related listener
50+
that, when called, returns information about the Id changes, both additions and
51+
removals, during a transaction. See the TableIdsListener type, for example.
52+
53+
```js
54+
let listenerId = store.addRowIdsListener(
55+
'pets',
56+
(store, tableId, getIdChanges) => {
57+
console.log(getIdChanges());
58+
},
59+
);
60+
61+
store.setRow('pets', 'lowly', {species: 'worm'});
62+
// -> {lowly: 1}
63+
64+
store.delRow('pets', 'felix');
65+
// -> {felix: -1}
66+
67+
store.delListener(listenerId).delTables();
68+
```
69+
670
## v3.2
771

872
This release lets you add a listener to the start of a transaction, and detect
@@ -17,8 +81,6 @@ Transactions added with the existing addDidFinishTransactionListener method
1781
_cannot_ mutate data.
1882

1983
```js
20-
const store = createStore();
21-
2284
const startListenerId = store.addStartTransactionListener(() => {
2385
console.log('Start transaction');
2486
console.log(store.getTables());
@@ -112,7 +174,7 @@ store.setValues({employees: 3, open: true});
112174
console.log(store.getValues());
113175
// -> {employees: 3, open: true}
114176

115-
const listenerId = store.addValueListener(
177+
listenerId = store.addValueListener(
116178
null,
117179
(store, valueId, newValue, oldValue) => {
118180
console.log(`Value '${valueId}' changed from ${oldValue} to ${newValue}`);

site/guides/1_the_basics/4_reading_from_stores.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ console.log(store.getCellIds('pets', 'fido'));
113113
```
114114

115115
There is also the getSortedRowIds method that lets you get the Ids sorted by a
116-
specific Cell Id.
116+
specific Cell Id, and the getTableCellIds method that lets you get all the Ids
117+
used across a whole Table.
117118

118119
Again, the return types of these methods are by value, not by reference. So if
119120
you manipulate the returned array, the Store is not updated:

site/guides/1_the_basics/5_listening_to_stores.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ And for tabular data:
1515
- Listen to Tables with the addTablesListener method.
1616
- Listen to Table Ids with the addTableIdsListener method.
1717
- Listen to a Table with the addTableListener method.
18+
- Listen to Cells Ids across a Table with the addTableCellIdsListener method.
1819
- Listen to Row Ids with the addRowIdsListener method.
1920
- Listen to sorted Row Ids with the addSortedRowIdsListener method.
2021
- Listen to a Row with the addRowListener method.

site/guides/2_building_uis/2_using_react_hooks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ And for tabular data:
3939
- The useTables hook is the reactive equivalent of the getTables method.
4040
- The useTableIds hook is the reactive equivalent of the getTableIds method.
4141
- The useTable hook is the reactive equivalent of the getTable method.
42+
- The useTableCellIds hook is the reactive equivalent of the getTableCellIds method.
4243
- The useRowIds hook is the reactive equivalent of the getRowIds method.
4344
- The useSortedRowIds hook is the reactive equivalent of the getSortedRowIds method.
4445
- The useRow hook is the reactive equivalent of the getRow method.

site/home/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</p>
5757
</section>
5858

59-
<a id='new' href='/guides/releases/#v3-2'><em>NEW!</em> v3.2 release</a>
59+
<a id='new' href='/guides/releases/#v3-3'><em>NEW!</em> v3.3 release</a>
6060

6161
---
6262

src/types/docs/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,7 @@
10591059
* |Tables|getTables|setTables|delTables|addTablesListener|
10601060
* |Table Ids|getTableIds|-|-|addTableIdsListener|
10611061
* |Table|getTable|setTable|delTable|addTableListener|
1062+
* |Table Cell Ids|getTableCellIds|-|-|addTableCellIdsListener|
10621063
* |Row Ids|getRowIds|-|-|addRowIdsListener|
10631064
* |Row Ids (sorted)|getSortedRowIds|-|-|addSortedRowIdsListener|
10641065
* |Row|getRow|setRow|delRow|addRowListener|

0 commit comments

Comments
 (0)