Skip to main content
Create new
Introduction
Reactivity
Props
Logic
Events
Bindings
Lifecycle
Stores
Motion
Transitions
Animations
Easing
SVG
Actions
Classes
Component composition
Context API
Special elements
Module context
Debugging
7GUIs
Miscellaneous
App.svelte
Cheese.svelte
data.js
<script>
// https://www.lemonde.fr/les-decodeurs/article/2018/08/02/manger-du-reblochon-l-ete-du-mont-d-or-l-hiver-quelle-saisonnalite-pour-les-fromages_5338688_4355770.html
import data from './data.js';
import Cheese from './Cheese.svelte';
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
let selectedMonth = months[new Date().getMonth()];
$: selectedMonthIndex = months.findIndex(month => month === selectedMonth);
$: selectedMonthCheeses = data
.filter(({ beginning, end }) => {
if(beginning < end) {
return selectedMonthIndex >= beginning - 1 && selectedMonthIndex <= end - 1;
}
return selectedMonthIndex >= beginning - 1 || selectedMonthIndex <= end - 1 ;
})
.sort(() => 0.5 - Math.random()) // rudimentary shuffle
.slice(0, 10);
let selectedName = data[Math.floor(Math.random() * data.length)].name;
$: selectedCheese = data.find(({name}) => name === selectedName);
</script>

<main>
<p>
The following list highglights some of the cheeses best sampled in
<select bind:value={selectedMonth}>
{#each months as month}
<option>{month}</option>
{/each}
</select>
:
</p>

<ul>
{#each selectedMonthCheeses as {name}}
loading Svelte compiler...
/* Select a component to see its compiled code */
result = svelte.compile(source, {
generate: ,
});
/* Select a component to see its compiled code */