Skip to content

Commit 2832e45

Browse files
committed
[types] createPersisterForPath
1 parent 0c501f6 commit 2832e45

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/@types/synchronizers/synchronizer-ws-server/docs.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,21 @@
482482
*
483483
* This should be run in a server environment, and you must pass in a configured
484484
* WebSocketServer object in order to create it.
485+
*
486+
* If you want your server to persist data itself, you can use the optional
487+
* second parameter of this function, which allows you to create a Persister for
488+
* a new path - whenever a new path is accessed by a client. This Persister will
489+
* only exist when there are active clients on that particular path.
490+
*
491+
* You are responsible for creating a MergeableStore to pass to this Persister,
492+
* but starting and stopping its automatic saving and loading is taken care of
493+
* by the WsServer. As a result, the server MergeableStore will be kept in sync
494+
* with the clients on that path, and in turn with whatever persistence layer
495+
* you have configured. See the example below.
485496
* @param webSocketServer A WebSocketServer object from your server environment.
497+
* @param createPersisterForPath An optional function that will create a
498+
* MergeableStore and a Persister to synchronize with the clients on a given
499+
* path.
486500
* @returns A reference to the new WsServer object.
487501
* @example
488502
* This example creates a WsServer and then destroys it again.

src/@types/synchronizers/synchronizer-ws-server/index.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,5 @@ export function createWsServer<
5555
>,
5656
>(
5757
webSocketServer: WebSocketServer,
58-
createPersisterForPath?: (pathId: Id) => Promise<PathPersister | undefined>,
59-
destroyPersisterForPath?: (pathId: Id, persister: PathPersister) => void,
58+
createPersisterForPath?: (pathId: Id) => PathPersister | undefined,
6059
): WsServer;

src/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,5 @@ export function createWsServer<
6363
>,
6464
>(
6565
webSocketServer: WebSocketServer,
66-
createPersisterForPath?: (pathId: Id) => Promise<PathPersister | undefined>,
67-
destroyPersisterForPath?: (pathId: Id, persister: PathPersister) => void,
66+
createPersisterForPath?: (pathId: Id) => PathPersister | undefined,
6867
): WsServer;

src/synchronizers/synchronizer-ws-server/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ export const createWsServer = (<
5252
>,
5353
>(
5454
webSocketServer: WebSocketServer,
55-
createPersisterForPath?: (pathId: Id) => Promise<PathPersister | undefined>,
56-
destroyPersisterForPath?: (pathId: Id, persister: PathPersister) => void,
55+
createPersisterForPath?: (pathId: Id) => PathPersister | undefined,
5756
) => {
5857
type ServerClient = {
5958
persister: PathPersister;

0 commit comments

Comments
 (0)