Skip to content

Commit 90cb3e6

Browse files
committed
[objarr] Home page
1 parent 670a52a commit 90cb3e6

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"partykit",
150150
"partyserver",
151151
"partysocket",
152+
"parvovirus",
152153
"Pearce",
153154
"Persistable",
154155
"Persistables",

site/guides/17_releases.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,53 @@ highlighted features.
77

88
# v8.0
99

10+
## Object And Array Types
11+
12+
This release also extends the range of types that a Cell or Value can hold.
13+
Previously, TinyBase supported `string`, `number`, `boolean`, and (since v7.0)
14+
`null`. Now you can also store plain JavaScript **objects** and **arrays**
15+
directly in a Store.
16+
17+
```js
18+
const richStore = createStore().setRow('pets', 'fido', {
19+
species: 'dog',
20+
traits: {friendly: true, energetic: true},
21+
vaccinations: ['rabies', 'distemper', 'parvovirus'],
22+
});
23+
24+
console.log(richStore.getCell('pets', 'fido', 'traits'));
25+
// -> {friendly: true, energetic: true}
26+
27+
console.log(richStore.getCell('pets', 'fido', 'vaccinations'));
28+
// -> ['rabies', 'distemper', 'parvovirus']
29+
```
30+
31+
Internally, objects and arrays are stored as JSON-encoded strings with a special
32+
prefix character, so they round-trip transparently through persistence layers.
33+
But in and out of your application code, the Store API always expects or returns
34+
them as native JavaScript values.
35+
36+
Schemas also gain `object` and `array` as valid types:
37+
38+
```js
39+
const richSchemaStore = createStore().setTablesSchema({
40+
pets: {
41+
species: {type: 'string'},
42+
traits: {type: 'object', default: {}},
43+
vaccinations: {type: 'array', default: []},
44+
},
45+
});
46+
47+
richSchemaStore.setRow('pets', 'fido', {species: 'dog'});
48+
console.log(richSchemaStore.getRow('pets', 'fido'));
49+
// -> {species: 'dog', traits: {}, vaccinations: []}
50+
```
51+
52+
Note that TinyBase does not deeply validate the contents of objects or arrays
53+
when a schema is applied - it simply checks that the value is of the right
54+
top-level type. For deeper validation, consider combining with a
55+
[Middleware](/guides/the-basics/using-middleware/) callback. On which note...
56+
1057
## Introducing Middleware
1158

1259
This release introduces a powerful new system for intercepting and transforming

site/home/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<a href='/guides/releases/#v8-0'><em>NEW!</em> v8.0 release</a>
1010

11-
<span id="one-with">"The one with middleware!"</span>
11+
<span id="one-with">"The one with objects, arrays & middleware!"</span>
1212

1313
<a class='start' href='/guides/the-basics/getting-started/'>Get started</a>
1414

0 commit comments

Comments
 (0)