Skip to content

Commit

Permalink
Add documentation for client deactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
hackerwins committed Nov 22, 2024
1 parent d957a40 commit 73e7104
Showing 1 changed file with 20 additions and 0 deletions.
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/.
### 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

0 comments on commit 73e7104

Please sign in to comment.