0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-29 08:32:05 +01:00

Merge pull request #2090 from sveltejs/gh-2078

fix two examples
This commit is contained in:
Rich Harris 2019-02-17 13:51:34 -04:00 committed by GitHub
commit 5c70456123
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 23 deletions

View File

@ -3,13 +3,22 @@
<script>
export let people = [];
let filteredPeople;
let selected;
let prefix = '';
let first = '';
let last = '';
let i = 0;
$: filteredPeople = prefix
? people.filter(person => {
const name = `${person.last}, ${person.first}`;
return name.toLowerCase().startsWith(prefix.toLowerCase());
})
: people;
$: selected = filteredPeople[i];
$: reset_inputs(selected);
function create() {
people = people.concat({ first, last });
i = people.length - 1;
@ -27,18 +36,8 @@
i = Math.min(i, people.length - 1);
}
$: filteredPeople = prefix
? people.filter(person => {
const name = `${person.last}, ${person.first}`;
return name.toLowerCase().startsWith(prefix.toLowerCase());
})
: people;
$: selected = filteredPeople[i];
$: if (selected) {
first = selected.first;
last = selected.last;
function reset_inputs(person) {
({ first, last } = person);
}
</script>

View File

@ -1,26 +1,24 @@
<script>
const tomorrow = new Date(Date.now() + 86400000);
const tomorrowAsString = [
let start = [
tomorrow.getFullYear(),
pad(tomorrow.getMonth() + 1, 2),
pad(tomorrow.getDate(), 2)
].join('-');
let start = tomorrowAsString;
let end = tomorrowAsString;
let end = start;
let isReturn = false;
const startDate = () => convertToDate(start);
const endDate = () => convertToDate(end);
$: startDate = convertToDate(start);
$: endDate = convertToDate(end);
function bookFlight() {
const type = isReturn ? 'return' : 'one-way';
let message = `You have booked a ${type} flight, leaving ${startDate().toDateString()}`;
let message = `You have booked a ${type} flight, leaving ${startDate.toDateString()}`;
if (type === 'return') {
message += ` and returning ${endDate().toDateString()}`;
message += ` and returning ${endDate.toDateString()}`;
}
alert(message);
@ -57,5 +55,5 @@
<button
on:click={bookFlight}
disabled="{isReturn && (startDate() >= endDate())}"
disabled="{isReturn && (startDate >= endDate)}"
>book</button>