Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate page tutorial/logic #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: If blocks
title: Blok if
---

HTML doesn't have a way of expressing *logic*, like conditionals and loops. Svelte does.
HTML tidak mempunyai cara untuk mengekspresikan *logika*, seperti kondisi dan perulangan. Svelte punya.

To conditionally render some markup, we wrap it in an `if` block:
Untuk mengkondisikan *render* markup, kita membungkusnya dengan `if` blok:

```html
{#if user.loggedIn}
Expand All @@ -20,4 +20,4 @@ To conditionally render some markup, we wrap it in an `if` block:
{/if}
```

Try it — update the component, and click on the buttons.
Cobalah - perbarui komponen, dan klik tombolnya.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Else blocks
title: Blok else
---

Since the two conditions — `if user.loggedIn` and `if !user.loggedIn` — are mutually exclusive, we can simplify this component slightly by using an `else` block:
Adanya dua kondisi - `if user.loggedIn` dan `if !user.loggedIn` - dimana itu eksklusif, kita bisa menyederhanakan komponen dengan menggunakan `else` blok:

```html
{#if user.loggedIn}
Expand All @@ -16,4 +16,4 @@ Since the two conditions — `if user.loggedIn` and `if !user.loggedIn` — are
{/if}
```

> A `#` character always indicates a *block opening* tag. A `/` character always indicates a *block closing* tag. A `:` character, as in `{:else}`, indicates a *block continuation* tag. Don't worry — you've already learned almost all the syntax Svelte adds to HTML.
> Karakter `#` selalu menunjukkan sebuah tag *pembukaan blok*. Karakter `/` selalu menunjukan sebuah tag *penutup blok*. Karakter `:`, dalam `{:else}`, menunjukkan sebuah tag *lanjutan blok*. Jangan khawatir - kamu sudah mempelajari hampir semua sintak yang Svelte tambahkan ke HTML.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Else-if blocks
title: Blok else-if
---

Multiple conditions can be 'chained' together with `else if`:
Banyak kondisi dapat 'dirangkai' secara bersamaan dengan `else if`:

```html
{#if x > 10}
Expand All @@ -12,4 +12,4 @@ Multiple conditions can be 'chained' together with `else if`:
{:else}
<p>{x} is between 5 and 10</p>
{/if}
```
```
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Each blocks
title: Blok each
---

If you need to loop over lists of data, use an `each` block:
Jika kamu perlu melakukan perulangan dari sebuah *list* data, gunakanlah `each` blok:

```html
<ul>
Expand All @@ -14,9 +14,10 @@ If you need to loop over lists of data, use an `each` block:
</ul>
```

> The expression (`cats`, in this case) can be any array or array-like object (i.e. it has a `length` property). You can loop over generic iterables with `each [...iterable]`.
> Ekspresi (`cats`, dalam hal ini) bisa berbentuk sebuah *array* atau *array-like object* (i.e. memiliki properti `length`). Kamu bisa mengulang *generic iterable* dengan `each [...iterable]`.

You can get the current *index* as a second argument, like so:
Kamu bisa mendapatkan *index* saat ini sebagai argumen, seperti:

```html
{#each cats as cat, i}
Expand All @@ -26,4 +27,4 @@ You can get the current *index* as a second argument, like so:
{/each}
```

If you prefer, you can use destructuring `each cats as { id, name }` — and replace `cat.id` and `cat.name` with `id` and `name`.
Jika kamu lebih suka, kamu bisa menggunakan *destructuring* - `each cats as { id, name }` - dan mengganti `cat.id` dan `cat.name` dengan `id` dan `name` saja.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
title: Keyed each blocks
title: Mengunci blok each
---

By default, when you modify the value of an `each` block, it will add and remove items at the *end* of the block, and update any values that have changed. That might not be what you want.
Secara default, saat kamu mengubah value dari blok `each`, itu akan menambah dan menghapus item di *akhir* blok, dan memperbarui nilai apapun yg berubah. Itu mungkin bukan apa yang kamu inginkan.

It's easier to show why than to explain. Click the 'Remove first thing' button a few times, and notice that it's removing `<Thing>` components from the end and updating the `color` for those that remain. Instead, we'd like to remove the first `<Thing>` component and leave the rest unaffected.
Ini akan lebih mudah untuk ditunjukkan ketimbang dijelaskan. Klik tombol 'Remove first thing' beberapa kali, dan perhatikan itu menghapus komponen `<Thing>` dari bawah dan memperbarui `warna` dari sisanya. Sedangkan, kita ingin menghapus komponen `<Thing>` pertama dan membiarkan sisanya tidak terdampak.

To do that, we specify a unique identifier for the `each` block:
Untuk melakukan itu, kita spesifikasikan sebuah identitas unik untuk blok `each`:

```html
{#each things as thing (thing.id)}
<Thing current={thing.color}/>
{/each}
```

The `(thing.id)` tells Svelte how to figure out what changed.
`(thing.id)` memberi tau Svelte bagaimana mencari apa yang berubah.

> You can use any object as the key, as Svelte uses a `Map` internally — in other words you could do `(thing)` instead of `(thing.id)`. Using a string or number is generally safer, however, since it means identity persists without referential equality, for example when updating with fresh data from an API server.
> Kamu bisa mengunakan objek sebagai sebuah kunci, karena Svelte menggunakan `Map` secara internal - dengan kata lain kamu bisa menggunakan `(thing)` dari pada `(thing.id)`. Mengunakan sebuah string atau angka lebih aman, namun, karena itu merupakan sebuah identitas yang bertahan tanpa persamaan referensial, misalnya saat kita memperbarui dengan data baru dari API *server*.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: Await blocks
title: Blok await
---

Most web applications have to deal with asynchronous data at some point. Svelte makes it easy to *await* the value of [promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) directly in your markup:
Kebanyakan aplikasi web harus berurusan dengan `asynchronous` data secara bersamaan. Svelte mempermudah untuk melakukan *await* nilai dari sebuah [*promise*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) secara langsung di markupmu:

```html
{#await promise}
Expand All @@ -14,12 +14,12 @@ Most web applications have to deal with asynchronous data at some point. Svelte
{/await}
```

> Only the most recent `promise` is considered, meaning you don't need to worry about race conditions.
> Hanya `promise` terbaru yang dipertimbangkan, artinya kamu tidak perlu khawatir dengan *race conditions*.

If you know that your promise can't reject, you can omit the `catch` block. You can also omit the first block if you don't want to show anything until the promise resolves:
Jika kamu tau *promise* mu tidak bisa di *reject*, kamu bisa menghilangan blok `catch`. Kamu juga bisa menghilangan blok pertama jika kamu tidak ingin menampilkan apapun sampai *promise* nya terselesaikan:

```html
{#await promise then value}
<p>the value is {value}</p>
{/await}
```
```