@@ -24,16 +24,18 @@ Svelte to become aware of such changes.
24
24
### Reactive computations with ` useTracker `
25
25
26
26
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.
30
30
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:
34
34
35
35
``` svelte
36
36
<script>
37
+ import { useTracker } from 'meteor/rdb:svelte-meteor-data';
38
+
37
39
const currentUser = useTracker(() => Meteor.user());
38
40
</script>
39
41
@@ -44,9 +46,11 @@ You can even mix Meteor reactivity with Svelte reactivity:
44
46
45
47
``` svelte
46
48
<script>
49
+ import { useTracker } from 'meteor/rdb:svelte-meteor-data';
50
+
47
51
let selectedUserId;
48
52
49
- $: selectedUser = useTracker(() => selectedUserId);
53
+ $: selectedUser = useTracker(() => Meteor.users.findOne( selectedUserId) );
50
54
</script>
51
55
52
56
<p>Selected {$selectedUser.username}</p>
@@ -55,8 +59,8 @@ You can even mix Meteor reactivity with Svelte reactivity:
55
59
### Cursors
56
60
57
61
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:
60
64
61
65
``` svelte
62
66
<script>
@@ -89,12 +93,12 @@ As an added feature, you can use a subscription handle in an `{#await}` block:
89
93
{/if}
90
94
```
91
95
92
- ### ` Tracker.autorun `
96
+ ### Tracker.autorun
93
97
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:
98
102
99
103
``` svelte
100
104
<script>
0 commit comments