|
1 | 1 | use crate::{create_memo, IntoSignalSetter, RwSignal, Scope, Signal, SignalSetter};
|
2 | 2 |
|
3 |
| -/// derives a reactive slice from an [RwSignal](crate::RwSignal) |
| 3 | +/// Derives a reactive slice of an [RwSignal](crate::RwSignal). |
4 | 4 | ///
|
5 |
| -/// Slices have the same guarantees as [Memos](crate::Memo), |
| 5 | +/// Slices have the same guarantees as [Memos](crate::Memo): |
6 | 6 | /// they only emit their value when it has actually been changed.
|
7 | 7 | ///
|
8 |
| -/// slices need a getter and a setter, and you must make sure that |
| 8 | +/// Slices need a getter and a setter, and you must make sure that |
9 | 9 | /// the setter and getter only touch their respective field and nothing else.
|
10 | 10 | /// They optimally should not have any side effects.
|
11 | 11 | ///
|
12 |
| -/// you can use slices whenever you want to react to only parts |
13 |
| -/// of a bigger signal, the prime example would be state management |
14 |
| -/// where you want all state variables grouped up but also need |
| 12 | +/// You can use slices whenever you want to react to only parts |
| 13 | +/// of a bigger signal. The prime example would be state management, |
| 14 | +/// where you want all state variables grouped together, but also need |
15 | 15 | /// fine-grained signals for each or some of these variables.
|
16 | 16 | /// In the example below, setting an auth token will only trigger
|
17 | 17 | /// the token signal, but none of the other derived signals.
|
18 |
| -/// |
19 | 18 | /// ```
|
20 | 19 | /// # use leptos_reactive::*;
|
21 | 20 | /// # let (cx, disposer) = raw_scope_and_disposer(create_runtime());
|
@@ -49,13 +48,14 @@ use crate::{create_memo, IntoSignalSetter, RwSignal, Scope, Signal, SignalSetter
|
49 | 48 | /// );
|
50 | 49 | /// let count_token_updates = create_rw_signal(cx, 0);
|
51 | 50 | /// count_token_updates.with(|counter| assert_eq!(counter, &0));
|
52 |
| -/// create_effect(cx, move |_| { |
53 |
| -/// token.with(|_| {}); |
| 51 | +/// create_isomorphic_effect(cx, move |_| { |
| 52 | +/// _ = token.with(|_| {}); |
54 | 53 | /// count_token_updates.update(|counter| *counter += 1)
|
55 | 54 | /// });
|
56 | 55 | /// count_token_updates.with(|counter| assert_eq!(counter, &1));
|
57 | 56 | /// set_token.set("this is not a token!".into());
|
58 | 57 | /// // token was updated with the new token
|
| 58 | +/// token.with(|token| assert_eq!(token, "this is not a token!")); |
59 | 59 | /// count_token_updates.with(|counter| assert_eq!(counter, &2));
|
60 | 60 | /// set_dark_mode.set(true);
|
61 | 61 | /// // since token didn't change, there was also no update emitted
|
|
0 commit comments