mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
710 B
40 lines
710 B
6 years ago
|
<script>
|
||
2 years ago
|
import { onDestroy } from 'svelte';
|
||
|
|
||
3 years ago
|
const emojis = {
|
||
1 year ago
|
apple: '🍎',
|
||
|
banana: '🍌',
|
||
|
carrot: '🥕',
|
||
|
doughnut: '🍩',
|
||
|
egg: '🥚'
|
||
|
};
|
||
3 years ago
|
|
||
|
// the name is updated whenever the prop value changes...
|
||
|
export let name;
|
||
6 years ago
|
|
||
3 years ago
|
// ...but the "emoji" variable is fixed upon initialisation of the component
|
||
|
const emoji = emojis[name];
|
||
2 years ago
|
|
||
|
// observe in the console which entry is removed
|
||
|
onDestroy(() => {
|
||
1 year ago
|
console.log('thing destroyed: ' + name);
|
||
2 years ago
|
});
|
||
6 years ago
|
</script>
|
||
|
|
||
5 years ago
|
<p>
|
||
1 year ago
|
<span>The emoji for {name} is {emoji}</span>
|
||
5 years ago
|
</p>
|
||
|
|
||
|
<style>
|
||
3 years ago
|
p {
|
||
|
margin: 0.8em 0;
|
||
|
}
|
||
5 years ago
|
span {
|
||
|
display: inline-block;
|
||
3 years ago
|
padding: 0.2em 1em 0.3em;
|
||
5 years ago
|
text-align: center;
|
||
|
border-radius: 0.2em;
|
||
1 year ago
|
background-color: #ffdfd3;
|
||
5 years ago
|
}
|
||
3 years ago
|
</style>
|