Skip to content

Commit

Permalink
Await watch call
Browse files Browse the repository at this point in the history
  • Loading branch information
llamadeus committed Apr 27, 2023
1 parent c042482 commit 06bc2b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/docs/src/pages/docs/changes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ very fast, there is a better alternative.
(The callback will also be called once with all items in the table right after you register your watcher).

```ts
const watcher = watch(userTable, users => {
const watcher = await watch(userTable, users => {
console.log('All users', users);
});
```
Expand All @@ -23,7 +23,7 @@ Only retrieving certain items from the table is also possible - just provide a [
and your callback will only be called if items matching the filter are inserted/updated/deleted.

```ts
const watcher = watch(userTable, { where: { age: { lt: 3 } } }, babies => {
const watcher = await watch(userTable, { where: { age: { lt: 3 } } }, babies => {
console.log('All babies: ', babies);
});
```
Expand All @@ -32,4 +32,4 @@ If you want to stop receiving updates, call the `.close()` function on the objec

```ts
watcher.close();
```
```
6 changes: 3 additions & 3 deletions packages/docs/src/pages/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ resulting in incredible performance, regardless if you're working with **10.000*
</div>
```ts
// Either watch for changes on the whole table...
watch(userTable, users => {
await watch(userTable, users => {
console.log('All users in the database:', users);
});
// ...or specify a filter
watch(userTable, { where: { age: { lt: 5 } } }, babies => {
await watch(userTable, { where: { age: { lt: 5 } } }, babies => {
console.log('All babies in the database:', babies);
});
```
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions packages/docs/src/pages/docs/reference/watch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ It's perfect for usage inside reactive components like React Hooks.

```ts
// Call `callback` whenever ALL entities change
watch(userTable, (users) => {
await watch(userTable, (users) => {
console.log("All users: ", users);
});
// Call `callback` whenever an item matching the filter changes
watch(userTable, { where: { age: { lt: 3 } } }, (babies) => {
await watch(userTable, { where: { age: { lt: 3 } } }, (babies) => {
console.log("All babies: ", babies);
});
```
Expand All @@ -34,9 +34,9 @@ watch(userTable, { where: { age: { lt: 3 } } }, (babies) => {
If you want to stop watching for changes, call `stop()` on the object returned by `watch()`.

```ts
const watcher = watch(userTable, (users) => {
const watcher = await watch(userTable, (users) => {
console.log("All users: ", users);
});

watcher.stop();
```
```

0 comments on commit 06bc2b1

Please sign in to comment.