Skip to content

Commit 5c973f7

Browse files
committed
Readme improvements
1 parent 9686c1f commit 5c973f7

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ Svelte to become aware of such changes.
2424
### Reactive computations with `useTracker`
2525

2626
The `useTracker()` function can be used to expose any reactive computation as a
27-
Svelte store. You need only pass a callable, which will be run the first time
28-
it is used and then every time the computed value changes. The changed value is
29-
automatically made available to Svelte.
27+
Svelte store. You need only pass a callable returning a computed value, which
28+
will be run the first time it is used and then every time the computed value
29+
changes. The updated value is automatically made available to Svelte.
3030

31-
For example, this makes the current Meteor user available in a component, and
32-
causes Svelte to update the appropriate element automatically when the current
33-
user changes:
31+
For example, this example makes the current Meteor user available in a
32+
component, and causes Svelte to update the appropriate element automatically
33+
when the current user changes:
3434

3535
```svelte
3636
<script>
37+
import { useTracker } from 'meteor/rdb:svelte-meteor-data';
38+
3739
const currentUser = useTracker(() => Meteor.user());
3840
</script>
3941
@@ -44,9 +46,11 @@ You can even mix Meteor reactivity with Svelte reactivity:
4446

4547
```svelte
4648
<script>
49+
import { useTracker } from 'meteor/rdb:svelte-meteor-data';
50+
4751
let selectedUserId;
4852
49-
$: selectedUser = useTracker(() => selectedUserId);
53+
$: selectedUser = useTracker(() => Meteor.users.findOne(selectedUserId));
5054
</script>
5155
5256
<p>Selected {$selectedUser.username}</p>
@@ -55,8 +59,8 @@ You can even mix Meteor reactivity with Svelte reactivity:
5559
### Cursors
5660

5761
While it's possible to use queries with `useTracker(() => query.fetch())`, this
58-
package supports a more convenient method, directly treating the cursor as a
59-
Svelte store:
62+
package supports a more convenient way to handle reactive queries, by allowing
63+
you to use a MongoDB cursor directly as a Svelte store:
6064

6165
```svelte
6266
<script>
@@ -89,12 +93,12 @@ As an added feature, you can use a subscription handle in an `{#await}` block:
8993
{/if}
9094
```
9195

92-
### `Tracker.autorun`
96+
### Tracker.autorun
9397

94-
It is possible to use `Tracker.autorun()` to have code automatically be re-run
95-
when its Meteor dependencies change. It will stop running when the component is
96-
destroyed. This will work fine for top-level computations that do not depend on
97-
any dynamic Svelte state, such as this example:
98+
It is possible to use `Tracker.autorun()` with a function that is automatically
99+
re-run when its Meteor dependencies change. It will stop being updated when the
100+
component is destroyed. This will work fine for top-level computations that do
101+
not depend on any dynamic Svelte state, such as in this example:
98102

99103
```svelte
100104
<script>

0 commit comments

Comments
 (0)