diff --git a/site/content/docs/01-component-format.md b/site/content/docs/01-component-format.md index 5ded7b38da..10fd8e5ebc 100644 --- a/site/content/docs/01-component-format.md +++ b/site/content/docs/01-component-format.md @@ -107,6 +107,8 @@ If a statement consists entirely of an assignment to an undeclared variable, Sve Any time you have a reference to a store, you can access its value inside a component by prefixing it with the `$` character. This causes Svelte to declare the prefixed variable, and set up a store subscription that will be unsubscribed when appropriate. +Note that the store must be declared at the top level of the component — not inside an `if` block or a function, for example. + Local variables (that do not represent store values) must *not* have a `$` prefix. ```html diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index 5f40c22822..30d01b406c 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -58,7 +58,7 @@ Or they can *be* JavaScript expressions. --- -An expression might include characters that would cause syntax highlighting to fail in regular HTML, in which case quoting the value is permitted. The quotes do not affect how the value is parsed: +An expression might include characters that would cause syntax highlighting to fail in regular HTML, so quoting the value is permitted. The quotes do not affect how the value is parsed: ```html @@ -180,7 +180,7 @@ An each block can also specify an *index*, equivalent to the second argument in --- -If a *key* expression is provided, Svelte will diff the list when data changes, rather than adding or removing items at the end. +If a *key* expression is provided — which must uniquely identify each list item — Svelte will use it to diff the list when data changes, rather than adding or removing items at the end. ```html {#each items as item, i (item.id)} @@ -236,7 +236,21 @@ Await blocks allow you to branch on the three possible states of a Promise — p --- -The `catch` block can be omitted if no error is possible, and the initial block can be omitted if you don't care about the pending state. +The `catch` block can be omitted if you don't need to render anything when the promise rejects (or no error is possible). + +```html +{#await promise} + +
waiting for the promise to resolve...
+{:then value} + +The value is {value}
+{/await} +``` + +--- + +If you don't care about the pending state, you can also omit the initial block. ```html {#await promise then value} @@ -353,7 +367,7 @@ If the name matches the value, you can use a shorthand. --- -Numeric input values are coerced; even though `input.value` is a string as far as the DOM is concerned, Svelte will treat it as a number. +Numeric input values are coerced; even though `input.value` is a string as far as the DOM is concerned, Svelte will treat it as a number. If the input is empty (in the case of `type="number"`), the value is `undefined`. ```html @@ -492,7 +506,7 @@ You can bind to component props using the same mechanism. Components also support `bind:this`, allowing you to interact with component instances programmatically. -(Note that we can do `{cart.empty}` rather than `{() => cart.empty()}`, since there is no `this` inside a component's `