Skip to content

Commit

Permalink
Update Yorkie version to 0.4.17 (#123)
Browse files Browse the repository at this point in the history
Co-authored-by: Youngteac Hong <susukang98@gmail.com>
  • Loading branch information
chacha912 and hackerwins authored Apr 23, 2024
1 parent 63f38fe commit e3e9d43
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 41 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Common Environment Variables
NEXT_PUBLIC_YORKIE_VERSION='0.4.13'
NEXT_PUBLIC_YORKIE_JS_VERSION='0.4.13'
NEXT_PUBLIC_YORKIE_IOS_VERSION='0.4.7'
NEXT_PUBLIC_YORKIE_ANDROID_VERSION='0.4.7'
NEXT_PUBLIC_YORKIE_VERSION='0.4.17'
NEXT_PUBLIC_YORKIE_JS_VERSION='0.4.17'
NEXT_PUBLIC_YORKIE_IOS_VERSION='0.4.17'
NEXT_PUBLIC_YORKIE_ANDROID_VERSION='0.4.16'
NEXT_PUBLIC_DASHBOARD_PATH='/dashboard'
NEXT_PUBLIC_JS_SDK_URL='https://cdnjs.cloudflare.com/ajax/libs/yorkie-js-sdk/0.4.13/yorkie-js-sdk.js'

Expand Down
48 changes: 19 additions & 29 deletions docs/js-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ This ensures that any modifications made by one client are instantly propagated

The second argument is options.
- `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.
- `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.
- `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.

```javascript
await client.attach(doc, {
initialPresence: { color: 'blue', cursor: { x: 0, y: 0 } },
isRealtimeSync: true,
syncMode: SyncMode.Manual,
});
```

Expand Down Expand Up @@ -299,43 +299,33 @@ const unsubscribe = doc.subscribe('$.todos', (event) => {
});
```

#### Changing Synchronization Setting
#### Changing Synchronization Mode

To change the synchronization setting for a document, you can use `client.pause(doc)` and `client.resume(doc)`.
To change the synchronization mode for a document, you can use `client.changeSyncMode(doc, syncMode)`.

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.
Yorkie offers four SyncModes:

To resume the realtime synchronization, you can call `client.resume(doc)`.
- `SyncMode.Realtime`: Local changes are automatically pushed to the server, and remote changes are pulled from the server.

```javascript
// 1. Pause real-time sync
await client.pause(doc);
await client.sync(doc); // To perform synchronization, you need to manually call the sync function
- `SyncMode.RealtimePushOnly`: Only local changes are pushed, and remote changes are not pulled.

// 2. Resume real-time sync
await client.resume(doc);
```
- `SyncMode.RealtimeSyncOff`: Changes are not synchronized, but the watch stream remains active.

#### Changing Synchronization Mode
- `SyncMode.Manual`: Synchronization no longer occurs in real-time, and the watch stream is disconneted. Manual handling is required for synchronization.

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.

If you only want to send your changes and not receive remote changes, you can use `push-only` mode.
```javascript
// Enable automatic synchronization of both local and remote changes.
await client.changeSyncMode(doc, SyncMode.Realtime);

For realtime synchronization, you can use `client.pauseRemoteChanges(doc)` and `client.resumeRemoteChanges(doc)`.
// Only push local changes automatically.
await client.changeSyncMode(doc, SyncMode.RealtimePushOnly);

For manual synchronization, you can pass the desired sync mode to `client.sync(doc, syncMode)`.
// Synchronization turned off, but the watch stream remains active.
await client.changeSyncMode(doc, SyncMode.RealtimeSyncOff);

```javascript
// Pause remote changes for realtime sync
client.pauseRemoteChanges(doc);
// Resume remote changes for realtime sync
client.resumeRemoteChanges(doc);

// Manual sync in Push-Only mode
await client.sync(doc, SyncMode.PushOnly);
// Manual sync in Push-Pull mode
await client.sync(doc, SyncMode.PushPull);
// Synchronization turned off, and the watch stream is disconneted.
await client.changeSyncMode(doc, SyncMode.Manual);
await client.sync(doc); // Trigger synchronization manually using the sync function.
```

#### Detaching the Document
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"rehype-slug": "^5.1.0",
"remark-gfm": "^3.0.1",
"unist-util-visit": "^4.1.1",
"yorkie-js-sdk": "^0.4.12"
"yorkie-js-sdk": "^0.4.17"
},
"devDependencies": {
"@mdx-js/loader": "^2.1.5",
Expand Down

0 comments on commit e3e9d43

Please sign in to comment.