Skip to content

Commit 5a1abd1

Browse files
isatriomazipan
authored andcommitted
Translate practical-use-of-scoped-slots (vuejs#162)
* Global API * Translated practical-use-of-scoped-slots and update GLOSARIUM * Forgot to change the title
1 parent f4186b5 commit 5a1abd1

File tree

2 files changed

+62
-52
lines changed

2 files changed

+62
-52
lines changed

GLOSARIUM.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
## A
2121

22+
- Analyze: Analisis
2223
- Argument: Argumen
2324
- Attribute: Atribut
2425

@@ -61,6 +62,7 @@
6162
- Element: Elemen
6263
- Error: Galat
6364
- Event: *Event*
65+
- Extracted: Diekstraksi
6466
- Export: Ekspor
6567
- Expression: Ekspresi
6668

@@ -90,9 +92,11 @@
9092

9193
- I.e. (id est / in other words): Dengan kata lain
9294
- Import: Impor
95+
- Inception: Permulaan
9396
- Index: Indeks
9497
- Inheritance: Pewarisan
9598
- Instance: *Instance*
99+
- Instantiate: *Instantiate*
96100
- Interpolation: Interpolasi
97101

98102
[⬆️](#navigasi-berdasarkan-abjad)
@@ -142,6 +146,7 @@
142146
- Parent: Induk
143147
- Passing: Mengoper
144148
- Path: Jalur
149+
- Piece-by-piece: Sepotong-sepotong
145150
- Project: Proyek
146151
- Property: Properti
147152
- Props: Props
@@ -165,6 +170,9 @@
165170

166171
## S
167172

173+
- Section: Bagian/Seksi
174+
- Set: Menetapkan
175+
- Shorthand: Tulisan cepat (tambahkan imbuhan sesuai dengan konteks jika diperlukan)
168176
- String: Untai
169177
- Style: Gaya
170178
- Style Guide: Panduan Gaya

src/v2/cookbook/practical-use-of-scoped-slots.md

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
2-
title: Practical use of scoped slots with GoogleMaps
2+
title: Penggunaan praktis dari slot scoped dengan GoogleMaps
33
type: cookbook
44
order: 14
55
---
66

7-
## Base Example
7+
## Contoh Dasar
88

9-
There are situations when you want the template inside the slot to be able to access data from the child component that is responsible for rendering the slot content. This is particularly useful when you need freedom in creating custom templates that use the child component's data properties. That is a typical use case for scoped slots.
9+
Ada beberapa situasi ketika Anda menginginkan templat dalam slot untuk bisa mengakses data dari _child component_ yang bertanggung jawab untuk menrender slot konten. Sebagian ini berguna ketika Anda membutuhkan kebebasan dalam membuat templat khusus yang menggunakan beberapa properti data _child component_. Kasus penggunaan umum untuk slot _scoped_.
1010

11-
Imagine a component that configures and prepares an external API to be used in another component, but is not tightly coupled with any specific template. Such a component could then be reused in multiple places rendering different templates but using the same base object with specific API.
11+
Bayangkan sebuah komponen yang terkonfigurasi dan menyiapkan API eksternal untuk digunakan di komponen lain, tapi tidak tergabung erat dengan templat spesifik manapun. Seperti sebuah komponen dapat diguna-ulang dalam banyak tempat merender templat berbeda tapi menggunakan obyek dasar yang sama dengan API spesifik.
1212

13-
We'll create a component (`GoogleMapLoader.vue`) that:
14-
1. Initializes the [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference/)
15-
2. Creates `google` and `map` objects
16-
3. Exposes those objects to the parent component in which the `GoogleMapLoader` is used
13+
Kita akan membuat sebuah komponen (`GoogleMapLoader.vue`):
14+
1. Inisialisasi [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference/)
15+
2. Buat obyek `google` dan `map`
16+
3. Buka obyek tersebut untuk _parent component_ yang menggunakan `GoogleMapLoader`
1717

18-
Below is an example of how this can be achieved. We will analyze the code piece-by-piece and see what is actually happening in the next section.
18+
Di bawah adalah contoh bagaimana ini bisa dicapai. Kita akan menganalisis kode sepotong-sepotong dan melihat apa yang sebenarnya terjadi dalam seksi berikutnya.
1919

20-
Let’s first establish our `GoogleMapLoader.vue` template:
20+
Pertama-tama buat `GoogleMapLoader.vue` templat kita
2121

2222
```html
2323
<template>
@@ -33,7 +33,7 @@ Let’s first establish our `GoogleMapLoader.vue` template:
3333
</template>
3434
```
3535

36-
Now, our script needs to pass some props to the component which allows us to set the [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference/) and [Map object](https://developers.google.com/maps/documentation/javascript/reference/map#Map):
36+
Sekarang, kebutuhan skrip kita untuk mengoper beberapa props ke komponen yang mengizinkan kita untuk menetapkan [Google Maps API](https://developers.google.com/maps/documentation/javascript/reference/) dan [Map object](https://developers.google.com/maps/documentation/javascript/reference/map#Map):
3737

3838
```js
3939
import GoogleMapsApiLoader from 'google-maps-api-loader'
@@ -70,17 +70,17 @@ export default {
7070
}
7171
```
7272

73-
This is just part of a working example, you can find the whole example in the Codesandbox below.
73+
Ini hanyalah bagian dari contoh kerja, Anda dapat mencari seluruh contoh di Codesandbox di bawah.
7474

7575
<iframe src="https://codesandbox.io/embed/1o45zvxk0q" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>
7676

77-
## Real-World Example: Creating a Google Map Loader component
77+
## Contoh Nyata: Membuat sebuah komponen Pemuat Google Map
7878

79-
### 1. Create a component that initializes our map
79+
### 1. Buat sebuah komponen yang menginisialisasi map kita
8080

8181
`GoogleMapLoader.vue`
8282

83-
In the template, we create a container for the map which will be used to mount the [Map](https://developers.google.com/maps/documentation/javascript/reference/map#Map) object extracted from the Google Maps API.
83+
Dalam templat, kita membuat sebuah kontainer untuk peta yang akan digunakan untuk memasang [Map](https://developers.google.com/maps/documentation/javascript/reference/map#Map) obyek yang diekstraksi dari API Google Maps.
8484

8585
```html
8686
<template>
@@ -90,10 +90,10 @@ In the template, we create a container for the map which will be used to mount t
9090
</template>
9191
```
9292

93-
Next up, our script needs to receive props from the parent component which will allow us to set the Google Map. Those props consist of:
93+
Berikutnya, skrip kita butuh untuk menerima props dari _parent component_ yang akan mengizinkan kita untuk menetapkan Google Map. Props tersebut terdiri dari:
9494

95-
- [mapConfig](https://developers.google.com/maps/documentation/javascript/reference/3/map#MapOptions): Google Maps config object
96-
- [apiKey](https://developers.google.com/maps/documentation/javascript/get-api-key): Our personal api key required by Google Maps
95+
- [mapConfig](https://developers.google.com/maps/documentation/javascript/reference/3/map#MapOptions): Obyek konfigurasi Google Maps
96+
- [apiKey](https://developers.google.com/maps/documentation/javascript/get-api-key): _Api key_ personal kita dibutuhkan oleh Google Maps
9797

9898
```js
9999
import GoogleMapsApiLoader from 'google-maps-api-loader'
@@ -104,7 +104,7 @@ export default {
104104
apiKey: String,
105105
},
106106
```
107-
Then, we set the initial values of google and map to null:
107+
Lalu, kita menetapkan nilai inisial dari google dan map menjadi null:
108108
109109
```js
110110
data() {
@@ -115,7 +115,7 @@ Then, we set the initial values of google and map to null:
115115
},
116116
```
117117
118-
On `mounted` hook we instantiate a `googleMapApi` and `Map` objects from the `GoogleMapsApi` and we set the values of `google` and `map` to the created instances:
118+
Dalam kait `mounted` kita _instantiate_ sebuah `googleMapApi` dan obyek `Map` dari `GoogleMapsApi` dan kita menetapkan nilai dari `google` dan `map` untuk membuat _instance_:
119119
120120
```js
121121
async mounted() {
@@ -135,17 +135,18 @@ On `mounted` hook we instantiate a `googleMapApi` and `Map` objects from the `Go
135135
}
136136
```
137137

138-
So far, so good. With all that done, we could continue adding the other objects to the map (Markers, Polylines, etc.) and use it as an ordinary map component.
138+
Sejauh ini bagus. Dengan semua yang telah selesai, kita bisa melanjutkan menambahkan ke obyek lain ke dalam peta (Marker, _Polyline_, dll.) dan gunakan sebagai komponen peta biasa.
139139

140-
But, we want to use our `GoogleMapLoader` component only as a loader that prepares the map — we don’t want to render anything on it.
140+
Tapi, kita ingin menggunakan komponen `GoogleMapLoaded` kita saja sebagai pemuat yang menyiapkan peta — kita tidak ingin merender apapun didalamnya.
141141

142-
To achieve that, we need to allow the parent component that will use our `GoogleMapLoader` to access `this.google` and `this.map` that are set inside the `GoogleMapLoader` component. That’s where [scoped slots](https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots) really shine. Scoped slots allow us to expose the properties set in a child component to the parent component. It may sound like Inception, but bear with me one more minute as we break that down further.
142+
Untuk mencapai itu, kita perlu mengizinkan _parent component_ yang akan menggunakan `GoogleMapLoader` kita untuk mengakses `this.google` dan `this.map` yang ditetapkan dalam komponen `GoogleMapLoader`. Itulah dimana _[slot scoped](https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots)_ terlihat bersinar. Slot _scoped_ mengizinkan kita untuk membuka pengaturan properti di sebuah _child component_ ke _parent component_. Ini terdengar seperti permulaan, tapi bertahanlah beberapa menit untuk
143+
kita urai lebih dalam.
143144

144-
### 2. Create component that uses our initializer component.
145+
### 2. Membuat komponen yang menggunakan penginisialisasi komponen kita.
145146

146147
`TravelMap.vue`
147148

148-
In the template, we render the `GoogleMapLoader` component and pass props that are required to initialize the map.
149+
Dalam templat, kita merender komponen `GoogleMapLoader` dan mengoper props yang dibutuhkan untuk menginisialisasi peta.
149150

150151
```html
151152
<template>
@@ -156,7 +157,7 @@ In the template, we render the `GoogleMapLoader` component and pass props that a
156157
</template>
157158
```
158159

159-
Our script tag will look like this:
160+
Tag skrip kita akan terlihat seperti ini:
160161

161162
```js
162163
<script>
@@ -180,11 +181,12 @@ export default {
180181
</script>
181182
```
182183

183-
Still no scoped slots, so let's add one.
184+
Masih tanpa slot _scoped_, jadi mari tambahkan satu.
184185

185-
### 3. Expose `google` and `map` properties to the parent component by adding a scoped slot.
186+
### 3. Membuka properti `google` dan `map` ke _parent component_ dengan menambahkan slot _scoped_.
186187

187-
Finally, we can add a scoped slot that will do the job and allow us to access the child component props in the parent component. We do that by adding the `<slot>` tag in the child component and passing the props that we want to expose (using `v-bind` directive or `:propName` shorthand). It does not differ from passing the props down to the child component, but doing it in the `<slot>` tag will reverse the direction of data flow.
188+
Akhirnya, kita akan menambahkan slot _scoped_ yang akan melakukan pekerjaannya dan mengizinkan kita untuk mengakses props _child component_ di _parent component_. Kita melakukannya dengan menambahkan tag `<slot>` dalam _child component_ dan mengoper props yang kita inginkan untuk dibuka (menggunakan _directive_ `v-bind` atau tulisan cepat `:propName`). Ini tidak berbeda dari mengoper props turuh ke _child component_, tapi dengan melakukan ini dalam tag `<slot>` akan membalikan arah
189+
dari aliran data.
188190

189191
`GoogleMapLoader.vue`
190192

@@ -202,13 +204,13 @@ Finally, we can add a scoped slot that will do the job and allow us to access th
202204
</template>
203205
```
204206

205-
Now, when we have the slot in the child component, we need to receive and consume the exposed props in the parent component.
207+
Sekarang, ketika kita memiliki slot dalam _child component_, kita perlu menerima dan mengkonsumsi props yang dibuka di _parent component_.
206208

207-
### 4. Receive exposed props in the parent component using `slot-scope` attribute.
209+
### 4. Menerima props yang dibuka di _parent component_ menggunakan atribut `slot-scope`.
208210

209-
To receive the props in the parent component, we declare a template element and use the `slot-scope` attribute. This attribute has access to the object carrying all the props exposed from the child component. We can grab the whole object or we can [de-structure that object](https://vuejs.org/v2/guide/components-slots.html#Destructuring-slot-scope) and only what we need.
211+
Untuk menerima props di _parent component_, kita mendeklarasikan sebuauh elemen templat dan menggunakan atribut `slot-scope`. Atribut ini memiliki akses ke obyek yang membawa semua props yang dibuka dari _child component_. Kita bisa mengambil seluruh obyek atau kita bisa [menghancurkan obyek tersebut](https://vuejs.org/v2/guide/components-slots.html#Destructuring-slot-scope) dan hanya apa yang kita butuhkan
210212

211-
Let’s de-structure this thing to get what we need.
213+
Mari hancurkan benda ini untuk mendapatkan apa yang kita butuhkan.
212214

213215
`TravelMap.vue`
214216

@@ -224,15 +226,15 @@ Let’s de-structure this thing to get what we need.
224226
</GoogleMapLoader>
225227
```
226228

227-
Even though the `google` and `map` props do not exist in the `TravelMap` scope, the component has access to them and we can use them in the template.
229+
Meskipun props `google` dan `map` tidak ada di _scope_ `TravelMap`, komponen masih memiliki akses ke props (props dari `google` dan `map`) dan kita dapat menggunakannya dalam templat.
228230

229-
You might wonder why would we do things like that and what is the use of all that?
231+
Anda mungkin takjub mengapa kita mau melakukan hal seperti itu dan apa gunanya semua itu?
230232

231-
Scoped slots allow us to pass a template to the slot instead of a rendered element. It’s called a `scoped` slot because it will have access to certain child component data even though the template is rendered in the parent component scope. This gives us the freedom to fill the template with custom content from the parent component.
233+
Slot _scoped_ mengizinkan kita untuk mengoper templat ke slot sebagai ganti dari elemen yang telah dirender. Itu disebut slot `scoped` karena itu akan memiliki akses ke data _child component_ tertentu meskipun templat telah dirender dalam _scope_ _parent component_. Ini memberikan kita kebebasan untuk mengisi templat dengan konten khusu dari _parent component_.
232234

233-
### 5. Create factory components for Markers and Polylines
235+
### 5. Membuat komponen pabrik dari _Marker_ dan _Polyline_
234236

235-
Now when we have our map ready we will create two factory components that will be used to add elements to the `TravelMap`.
237+
Sekarang ketika kita memiliki peta kita siap kita akan membuat 2 komponen pabrik yang akan digunakan untuk menambah elemen ke `TravelMap`.
236238

237239
`GoogleMapMarker.vue`
238240

@@ -297,21 +299,21 @@ export default {
297299
}
298300
```
299301

300-
Both of these receive `google` that we use to extract the required object (Marker or Polyline) as well as `map` which gives as a reference to the map on which we want to place our element.
302+
Keduanya menerima `google` yang kita gunakan untuk mengekstraksi obyek yang dibutuhkan (_Marker_ atau _Polyline_) sebaik `map` yang diberikan sebagai referensi ke peta di mana kita ingin menempatkan elemen kita.
301303

302-
Each component also expects an extra prop to create a corresponding element. In this case, we have `marker` and `path`, respectively.
304+
Masing-masing komponen juga berekspektasi prop tambahan untuk membuat elemen yang sesuai. Dalam kasus ini, kita memiliki `marker` dan `path`, masing-masing.
303305

304-
On the mounted hook, we create an element (Marker/Polyline) and attach it to our map by passing the `map` property to the object constructor.
306+
Dalam kait yang terpasang, kita membuat sebuah elemen (_Marker_/_Polyline_) dan melampirkannya ke peta kita dengan mengoper properti `map` untuk konstruktor obyek.
305307

306-
There’s still one more step to go...
308+
Masih ada satu langkah lagi...
307309

308-
### 6. Add elements to map
310+
### 6. Menambah elemen ke peta
309311

310-
Let’s use our factory components to add elements to our map. We must render the factory component and pass the `google` and `map` objects so data flows to the right places.
312+
Mari gunakan komponen pabrik kita untuk menambah elemen ke peta kita. Kita harus merender komponen pabrik dan mengoper obyek `google` dan `peta` jadi aliran data menuju ke tempat yang tepat.
311313

312-
We also need to provide the data that’s required by the element itself. In our case, that’s the `marker` object with the position of the marker and the `path` object with Polyline coordinates.
314+
Kita juga perlu menyediakan data yang dibutuhkan oleh elemen itu sendiri. Dalam kasus kita adalah obyek `marker` dengan posisi dari marker dan obyek `path` dengan koordinat _Polyline_/
313315

314-
Here we go, integrating the data points directly into the template:
316+
Kita mulai, mengintegrasi poin data langsung ke templat:
315317

316318
```html
317319
<GoogleMapLoader
@@ -337,7 +339,7 @@ Here we go, integrating the data points directly into the template:
337339
</GoogleMapLoader>
338340
```
339341

340-
We need to import the required factory components in our script and set the data that will be passed to the markers and lines:
342+
Kita perlu mengimpor komponen pabrik yang dibutuhkan di skrip kita dan menetapkan data yang akan dioper ke marker dan garis:
341343

342344
```js
343345
import { mapSettings } from '@/constants/mapSettings'
@@ -378,10 +380,10 @@ export default {
378380
}
379381
```
380382

381-
## When To Avoid This Pattern
382-
It might be tempting to create a very complex solution based on the example, but at some point we can get to the situation where this abstraction becomes an independent part of the code living in our codebase. If we get to that point it might be worth considering extraction to an add-on.
383+
## Kapan Untuk Menghindari Pola Ini
384+
Ini mungkin menggoda untuk membuat solusi yang sangat kompleks berdasarkan contoh, tapi dalam beberapa poin kita dapat sampai pada situasi dimana abstraksi ini menjadi bagian yang mandiri dari kode yang berada dalam basis kode.
383385

384-
## Wrapping Up
385-
That's it. With all those bits and pieces created we can now re-use the `GoogleMapLoader` component as a base for all our maps by passing different templates to each one of them. Imagine that you need to create another map with different Markers or just Markers without Polylines. By using the above pattern it becomes very easy as we just need to pass different content to the `GoogleMapLoader` component.
386+
## Kesimpulan
387+
Jadi itu saja. Dengan semua bit-bit itu dan bagian-bagian yang telah dibuat sekarang kita dapat menguna-ulang komponen `GoogleMapLoader` sebagai dasar untuk semua peta kita dengan mengoper tempat berbeda ke masing-masing templat tersebut. Bayangkan Anda perlu membuat peta lain dengan Marker yang berbeda atau hanya Marker tanpa _Polyline_. Dengan menggunakan pola di atas itu menjadi sangat mudah seperti kita hanya perlu mengoper konten yang berbeda ke komponen `GoogleMapLoader`.
386388

387-
This pattern is not strictly connected to Google Maps; it can be used with any library to set the base component and expose the library's API that might be then used in the component that summoned the base component.
389+
Pola ini tidak ketat terkoneksi ke _Google Maps_; ini dapat digunakan dengan pustaka apapun untuk menetapkan dasar komponen dan membuka pustaka API yang mungkin digunakan dalam komponen yang dipanggil komponen dasar.

0 commit comments

Comments
 (0)