Skip to content

Commit 6a6a542

Browse files
committed
[docs] v5.1 guides
1 parent 8058715 commit 6a6a542

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

site/guides/05_synchronization/2_using_a_synchronizer.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Of course it is also possible to create custom Synchronizer objects if you have
2424
a transmission medium that allows the synchronization messages to be sent
2525
reliably between clients.
2626

27-
## Synchronizing with WebSockets
27+
## Synchronizing With WebSockets
2828

2929
A common pattern for synchronizing over the web is to use WebSockets. This
3030
allows multiple clients to pass lightweight messages to each other, facilitating
@@ -129,7 +129,35 @@ listeners:
129129
server.destroy();
130130
```
131131

132-
## Synchronizing over the browser BroadcastChannel
132+
### Persisting Data On The Server
133+
134+
New in TinyBase v5.1, the createWsServer function lets you specify a way to
135+
persist data to the server. This makes it possible for all clients to disconnect
136+
from a path, but, when they reconnect, for the data to still be present for them
137+
to sync with.
138+
139+
This is done by passing in a second argument to the function that creates a
140+
Persister instance (for which also need to create or provide a MergeableStore)
141+
for a given path:
142+
143+
```js
144+
import {createFilePersister} from 'tinybase/persisters/persister-file';
145+
146+
const persistingServer = createWsServer(
147+
new WebSocketServer({port: 8050}),
148+
(pathId) => createFilePersister(createMergeableStore(), pathId + '.json'),
149+
);
150+
```
151+
152+
This is a very crude example, but demonstrates a server that will create a file,
153+
based on any path that clients connect to, and persist data to it. In
154+
production, you will certainly want to sanitize the file name! And more likely
155+
you will want to explore using a database-oriented Persister instead of simply
156+
using raw files.
157+
158+
See the createWsServer function documentation for more details.
159+
160+
## Synchronizing Over The Browser BroadcastChannel
133161

134162
There may be situations where you need to synchronize data between different
135163
parts of a browser. For example, you might have a transient in-memory

site/guides/14_releases.md

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

6+
## v5.1
7+
8+
This release lets you persist data on a server using the createWsServer
9+
function. This makes it possible for all clients to disconnect from a path, but,
10+
when they reconnect, for the data to still be present for them to sync with.
11+
12+
This is done by passing in a second argument to the createWsServer function that
13+
creates a Persister instance (for which also need to create or provide a
14+
MergeableStore) for a given path:
15+
16+
```js
17+
import {WebSocketServer} from 'ws';
18+
import {createFilePersister} from 'tinybase/persisters/persister-file';
19+
import {createMergeableStore} from 'tinybase';
20+
import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
21+
22+
const persistingServer = createWsServer(
23+
new WebSocketServer({port: 8051}),
24+
(pathId) => createFilePersister(createMergeableStore(), pathId + '.json'),
25+
);
26+
```
27+
28+
This is a very crude (and not production-safe!) example, but demonstrates a
29+
server that will create a file, based on any path that clients connect to, and
30+
persist data to it. See the createWsServer function documentation for more
31+
details.
32+
33+
This implementation is still experimental so please kick the tires!
34+
635
## v5.0
736

837
We're excited to announce this major release for TinyBase! It includes
@@ -38,8 +67,6 @@ you apply that to (another) store. The merge method is a convenience function to
3867
bidirectionally merge two stores together:
3968

4069
```js
41-
import {createMergeableStore} from 'tinybase';
42-
4370
const localStore1 = createMergeableStore();
4471
const localStore2 = createMergeableStore();
4572

@@ -74,8 +101,7 @@ MergeableStore objects to be merged together. This can be across a network,
74101
using WebSockets, for example:
75102

76103
```js
77-
import {WebSocketServer, WebSocket} from 'ws';
78-
import {createWsServer} from 'tinybase/synchronizers/synchronizer-ws-server';
104+
import {WebSocket} from 'ws';
79105
import {createWsSynchronizer} from 'tinybase/synchronizers/synchronizer-ws-client';
80106

81107
// On a server machine:

site/home/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</section>
88

99
<a href='/guides/releases/#v5-0'><em>NEW!</em> v5.0 release</a> <span
10-
id="one-with">"The One You Can Sync"</span>
10+
id="one-with">"The One You Can Sync (with a server!)"</span>
1111

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

0 commit comments

Comments
 (0)