File tree Expand file tree Collapse file tree 4 files changed +17
-6
lines changed
@types/synchronizers/synchronizer-ws-server
synchronizers/synchronizer-ws-server Expand file tree Collapse file tree 4 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments