site: clearer examples for <slot let:name>

In the first example, "item" is used to describe three logically
distinct objects: (1) the name of the slot's property; (2) the JS
variable used within FancyList.svelte's {#each} block; and (3) the JS
variable used within App.svelte. To make it clearer that these are
three different objects, give them different names.

The second example can continue reusing the same name for all of the
objects to demonstrate there's no collision between them. But we can
also simplify the example to take further advantage of shorthand
rules.
pull/4125/head
Matthew Dempsky 6 years ago
parent a9065d4120
commit 4c630e4ffc

@ -1245,15 +1245,15 @@ The usual shorthand rules apply — `let:item` is equivalent to `let:item={item}
```html ```html
<!-- App.svelte --> <!-- App.svelte -->
<FancyList {items} let:item={item}> <FancyList {items} let:prop={thing}>
<div>{item.text}</div> <div>{thing.text}</div>
</FancyList> </FancyList>
<!-- FancyList.svelte --> <!-- FancyList.svelte -->
<ul> <ul>
{#each items as item} {#each items as item}
<li class="fancy"> <li class="fancy">
<slot item={item}></slot> <slot prop={item}></slot>
</li> </li>
{/each} {/each}
</ul> </ul>
@ -1266,7 +1266,7 @@ Named slots can also expose values. The `let:` directive goes on the element wit
```html ```html
<!-- App.svelte --> <!-- App.svelte -->
<FancyList {items}> <FancyList {items}>
<div slot="item" let:item={item}>{item.text}</div> <div slot="item" let:item>{item.text}</div>
<p slot="footer">Copyright (c) 2019 Svelte Industries</p> <p slot="footer">Copyright (c) 2019 Svelte Industries</p>
</FancyList> </FancyList>
@ -1274,7 +1274,7 @@ Named slots can also expose values. The `let:` directive goes on the element wit
<ul> <ul>
{#each items as item} {#each items as item}
<li class="fancy"> <li class="fancy">
<slot name="item" item={item}></slot> <slot name="item" {item}></slot>
</li> </li>
{/each} {/each}
</ul> </ul>

Loading…
Cancel
Save