File tree Expand file tree Collapse file tree 3 files changed +18
-22
lines changed
sites/svelte-5-preview/src/routes/docs/content/01-api Expand file tree Collapse file tree 3 files changed +18
-22
lines changed Original file line number Diff line number Diff line change @@ -64,19 +64,18 @@ declare namespace $state {
64
64
export function snapshot < T > ( state : T ) : T ;
65
65
66
66
/**
67
- * To take a check if two reactive from `$state()` are the same, use `$state.is`:
67
+ * Compare two values, one or both of which is a reactive `$state(...)` proxy.
68
68
*
69
69
* Example:
70
70
* ```ts
71
71
* <script>
72
- * let state = $state({});
73
- * let object = {};
72
+ * let foo = $state({});
73
+ * let bar = {};
74
74
*
75
- * state.object = object ;
75
+ * foo.bar = bar ;
76
76
*
77
- * console.log(state.object === object); // false because of the $state proxy
78
- *
79
- * console.log($state.is(state.object, object)); // true
77
+ * console.log(foo.bar === bar); // false — `foo.bar` is a reactive proxy
78
+ * console.log($state.is(foo.bar, bar)); // true
80
79
* </script>
81
80
* ```
82
81
*
Original file line number Diff line number Diff line change @@ -2625,19 +2625,18 @@ declare namespace $state {
2625
2625
export function snapshot < T > ( state : T ) : T ;
2626
2626
2627
2627
/**
2628
- * To take a check if two reactive from `$state()` are the same, use `$state.is`:
2628
+ * Compare two values, one or both of which is a reactive `$state(...)` proxy.
2629
2629
*
2630
2630
* Example:
2631
2631
* ```ts
2632
2632
* <script>
2633
- * let state = $state({});
2634
- * let object = {};
2633
+ * let foo = $state({});
2634
+ * let bar = {};
2635
2635
*
2636
- * state.object = object ;
2636
+ * foo.bar = bar ;
2637
2637
*
2638
- * console.log(state.object === object); // false because of the $state proxy
2639
- *
2640
- * console.log($state.is(state.object, object)); // true
2638
+ * console.log(foo.bar === bar); // false — `foo.bar` is a reactive proxy
2639
+ * console.log($state.is(foo.bar, bar)); // true
2641
2640
* </script>
2642
2641
* ```
2643
2642
*
Original file line number Diff line number Diff line change @@ -114,19 +114,17 @@ This is handy when you want to pass some state to an external library or API tha
114
114
115
115
## ` $state.is `
116
116
117
- Sometimes you might need to deal with the equality of two values, where one of the objects might have been wrapped in a with a ` $state ` proxy,
118
- you can use ` $state.is ` to check if the two values are the same.
117
+ Sometimes you might need to compare two values, one of which is a reactive ` $state(...) ` proxy. For this you can use ` $state.is(a, b) ` :
119
118
120
119
``` svelte
121
120
<script>
122
- let state = $state({});
123
- let object = {};
121
+ let foo = $state({});
122
+ let bar = {};
124
123
125
- state.object = object ;
124
+ foo.bar = bar ;
126
125
127
- console.log(state.object === object); // false because of the $state proxy
128
-
129
- console.log($state.is(state.object, object)); // true
126
+ console.log(foo.bar === bar); // false — `foo.bar` is a reactive proxy
127
+ console.log($state.is(foo.bar, bar)); // true
130
128
</script>
131
129
```
132
130
You can’t perform that action at this time.
0 commit comments