Skip to content

Commit

Permalink
Merge pull request #10 from llamadeus/documentation-fixes
Browse files Browse the repository at this point in the history
Await watch call
  • Loading branch information
maradotwebp committed May 1, 2023
2 parents 738471d + e328aa0 commit a7569d8
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 dispose = watch(userTable, users => {
const dispose = 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 dispose = watch(userTable, { where: { age: { lt: 3 } } }, babies => {
const dispose = 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 function returned from [`watch()

```ts
dispose();
```
```
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,10 +34,10 @@ watch(userTable, { where: { age: { lt: 3 } } }, (babies) => {
If you want to stop watching for changes, call the function returned by `watch()`.

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

// Stop watching changes
stop();
```
```

0 comments on commit a7569d8

Please sign in to comment.