Skip to content

Commit

Permalink
docs(comments): added information about new subscribeToThreads functi…
Browse files Browse the repository at this point in the history
…on (#79)
  • Loading branch information
bdbch authored Dec 20, 2024
1 parent 8a3ef34 commit 9328eba
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/content/comments/core-concepts/manage-threads.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,32 @@ const createThread = () => {

Now the thread and comment will have a user assigned to it.

## Receive and render threads
## Receive and watch threads and comments

To receive the list of threads on your current document, you can simply call `provider.getThreads()`. This will return an array of threads on the document connected to your provider.
Receiving and watching the threads on your current document can easily be done by using the `subscribeToThreads` function. This function will register a watcher, fetch the first initial list of threads and keep the list up to date.

To unsubscribe from the threads, you can call the callback function returned by the `subscribeToThreads` function.

```js
// Subscribe to threads
const unsubscribe = subscribeToThreads({
provider: yourTiptapCollabProvider,
callback: (threads) => {
// do something with threads, store in a state or variable from here
},
// optional options
getThreadsOptions: {
// only threads with the specific type will be fetched/watched, possible values are 'archived' and 'unarchived',
// if not set, only unarchived threads will be handled
// archived and unarchived threads represent soft-deleted threads
types: ['archived', 'unarchived'],
},
})
```

## Receive and render threads manually

To receive the list of threads on your current document manually, you can simply call `provider.getThreads()`. This will return an array of threads on the document connected to your provider.

This is a static array which won't update on its own. If you want to keep the list of threads up to date, you can listen to changes via the `provider.watchThreads` and `provider.unwatchThreads` functions.

Expand Down

0 comments on commit 9328eba

Please sign in to comment.