settings.json
,"[svelte]": {
"editor.defaultFormatter": "svelte.svelte-vscode"
},
<div class="description">
<p>{@html description}</p>
</div>
<div class="{userImage ? 'thumb' : 'thumb thumb-placeholder'}">
<img src="{userImage}" alt={userName}/>
</div>
<div class="thumb" class:thumb-placeholder="{!userImage}">
<img src="{userImage}" alt={userName}/>
</div>
open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp
chrome://version
value
data flow into the inputon:input
data flow out of the input<input type="text" value="{name}" on:input="{nameInput}" >
{#if formState === "done"}
<ContactCard userName={name} jobTitle={title} {description} userImage={image} />
{/if}
{#if formState === "invalid"}
<p>Invalid Input</p>
{/if}
{#if formState === "done"}
<ContactCard userName={name} jobTitle={title} {description} userImage={image} />
{:else if formState === "invalid"}
<p>Invalid Input</p>
{:else}
<p>Some other issue</p>
{/if}
createdContacts
is an arraycreatedContacts
createdContacts = [...createdContacts,
{
name: name,
jobTitle: title,
imageURL: image,
desc: description
}
];
{#each createdContacts as contact}
<ContactCard
userName={contact.name}
jobTitle={contact.jobTitle}
description={contact.description}
userImage={contact.imageURL} />
{/each}
each
{#each createdContacts as contact, index}
<h2># {index + 1}</h2>
<ContactCard
userName={contact.name}
jobTitle={contact.jobTitle}
description={contact.desc}
userImage={contact.imageURL} />
{:else}
<p>Please start adding some contacts, we found none!</p>
{/each}
function deleteFirst() {
createdContacts = createdContacts.slice(1)
}
function deleteLast() {
createdContacts = createdContacts.slice(0, -1)
}
each
{#each createdContacts as contact, index (contact.id)}
Please start adding some contacts, we found none!
{/each} ```on:click="{() => clickHandlerFunc(yourArgument)}"
on:click="{() => clickHandlerFunc.bind(this, yourArgument)}"
<ul>
{#each passwords as pw, i}
<li on:click={removePassword.bind(this, i)}>{pw}</li>
{/each}
</ul>
filter()
method on the existing array to filter out (=remove) an element with a specific index.filter(function(element, index, array))
index
is the index of the current element being processed in the array. function removePassword(index) {
passwords = passwords.filter((pw, idx) => {
return idx !== index;
});
}
each
statement increases the performance.only allow the button to be used once
<button on:click|once={addContact} >Add Contact Card</button>
improves scrolling performance
<button on:click|passive={addContact} >Add Contact Card</button>
stops event propagation
<button on:click|stopPropagation={addContact} >Add Contact Card</button>
<button on:click|preventDefault={addContact} >Add Contact Card</button>
<button on:click="{(event) => {createdContacts = createdContacts.slice()}}">Delete First</button>
Stateful components, containers
Presentational Components