Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for client deactivation #176

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/js-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ const client = new yorkie.Client('{{API_ADDR}}', {
});
```

##### Deactivate the Client

When the client is no longer needed, you can deactivate it to release resources and disconnect from the server.

```javascript
await client.deactivate();
```

This will detach all documents attached to the client for efficient [garbage collection](https://github.com/yorkie-team/yorkie/blob/main/design/garbage-collection.md).

> When the page is closed, the client should be deactivated for proper cleanup. For this, you can use the `beforeunload` event.
> Using the `keepalive` option in `deactivate` request will remain open, even if the page that initiated the request is closed.
>
> ```javascript
> window.addEventListener('beforeunload', () => {
> client.deactivate({keepalive: true});
> });
> ```
> For more information about `keepalive`, please refer to the https://css-tricks.com/send-an-http-request-on-page-exit/.

hackerwins marked this conversation as resolved.
Show resolved Hide resolved
### Document

`Document` is a primary data type in Yorkie, which provides a JSON-like updating experience that makes it easy to represent your application's model.
Expand Down
Loading