You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0003-reactive-declarations.md
+3-13Lines changed: 3 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -57,7 +57,7 @@ As an indirect consequence of that change, we're able to get rid of all the boil
57
57
58
58
The useful thing about computed properties is that they are only recalculated when their inputs change, side-stepping a common performance problem that affects some frameworks in which derived values must be recalculated on every render. Unlike some other frameworks that implement computed properties, the compiler is able to build a dependency graph of computed properties at *compile time*, enabling it to sort them topologically and generate highly efficient code that doesn't depend on expensive *run time* dependency tracking.
59
59
60
-
RFC 1 glosses over the loss of computed properties, suggesting that we could simply replace them with functions:
60
+
RFC 1 initially glossed over the loss of computed properties, suggesting that we could simply replace them with functions:
61
61
62
62
```html
63
63
<script>
@@ -172,15 +172,7 @@ Another consequence is that it's straightforward to include side-effects (`$: co
172
172
173
173
### Timing
174
174
175
-
Since reactive declarations are likely to depend on props passed into the component from outside, we probably don't want them to run immediately upon instantiation (when props aren't yet available).
176
-
177
-
> 🐃 There has been some discussion about whether we *should* make props available immediately, rather than waiting until the first update cycle. In other words,
178
-
>
179
-
> export let foo = 'fallback value';
180
-
>
181
-
> would be transformed by the compiler to something like
182
-
>
183
-
> let { foo = 'fallback value' } = $$props;
175
+
Since reactive declarations are ordered topologically, we probably don't want them to run immediately in source order upon instantiation.
184
176
185
177
We also don't want to run them immediately upon every change. Recalculating `foo` after `bar` is updated...
186
178
@@ -207,7 +199,7 @@ In Svelte 2, computed properties are read-only — attempting to write to them t
207
199
208
200
### Reactive stores
209
201
210
-
[RFC 2](https://github.com/sveltejs/rfcs/blob/svelte-observables/text/0002-observables.md) introduced a proposal for reactive stores (the naming is TBD; the title of that RFC is 'Svelte observables', but at one point the favoured name was 'sources'. For now I'll refer to them as reactive stores, for alignment with reactive assignments and declarations).
202
+
[RFC 2](https://github.com/sveltejs/rfcs/blob/svelte-observables/text/0002-observables.md) introduced a proposal for reactive stores.
211
203
212
204
Briefly, the idea is that a reactive store exposes a `subscribe` method that can be used to track a value over time; *writable* stores would also expose methods like `set` and `update`. This allows application state to be stored outside the component tree, where appropriate. Inside templates, stores can be referenced with a `$` prefix that exposes their value:
213
205
@@ -308,8 +300,6 @@ This shouldn't be the first thing that people encounter when learning Svelte —
308
300
309
301
When discussing reactive programming, it's useful to refer to existing implementations of the idea, including spreadsheets.
310
302
311
-
The naming and terminology are still TBD. 'Reactive declarations' makes sense to me as one leg of the reactive assignments/declarations/stores trinity, but better alternatives may exist. As for the label itself, I don't have a clear favourite, though I'm warming to `reactive:`.
0 commit comments