You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/js-sdk.mdx
+19-29Lines changed: 19 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,12 +72,12 @@ This ensures that any modifications made by one client are instantly propagated
72
72
73
73
The second argument is options.
74
74
-`initialPresence`: Sets the initial presence of the client that attaches the document. The presence is shared with other users participating in the document. It must be serializable to JSON.
75
-
-`isRealtimeSync`(Optional): Specifies whether to enable real-time synchronization. The default value is `true`, which means synchronization occurs automatically. If set to `false`, you should manually control the synchronization.
75
+
-`syncMode`(Optional): Specifies synchronization modes. The default value is `SyncMode.Realtime`, which automatically pushes and pulls changes. If you set it to `SyncMode.Manual`, you'll need to manually handle synchronization.
To change the synchronization setting for a document, you can use `client.pause(doc)` and `client.resume(doc)`.
304
+
To change the synchronization mode for a document, you can use `client.changeSyncMode(doc, syncMode)`.
305
305
306
-
When you pause a document, the synchronization process will no longer occur in realtime, and you will need to manually execute the synchronization to ensure that the changes are propagated to other clients.
306
+
Yorkie offers four SyncModes:
307
307
308
-
To resume the realtime synchronization, you can call `client.resume(doc)`.
308
+
-`SyncMode.Realtime`: Local changes are automatically pushed to the server, and remote changes are pulled from the server.
309
309
310
-
```javascript
311
-
// 1. Pause real-time sync
312
-
awaitclient.pause(doc);
313
-
awaitclient.sync(doc); // To perform synchronization, you need to manually call the sync function
310
+
-`SyncMode.RealtimePushOnly`: Only local changes are pushed, and remote changes are not pulled.
314
311
315
-
// 2. Resume real-time sync
316
-
awaitclient.resume(doc);
317
-
```
312
+
-`SyncMode.RealtimeSyncOff`: Changes are not synchronized, but the watch stream remains active.
318
313
319
-
#### Changing Synchronization Mode
314
+
-`SyncMode.Manual`: Synchronization no longer occurs in real-time, and the watch stream is disconneted. Manual handling is required for synchronization.
320
315
321
-
By default, Yorkie synchronizes a document in `push-pull` mode, where local changes are pushed to the server, and remote changes are pulled from the server.
322
-
323
-
If you only want to send your changes and not receive remote changes, you can use `push-only` mode.
316
+
```javascript
317
+
// Enable automatic synchronization of both local and remote changes.
0 commit comments