|
1 | 1 |
|
2 | | -# Dynamic imports |
| 2 | +# Dinamik İçeriye Aktarma |
3 | 3 |
|
4 | | -Export and import statements that we covered in previous chapters are called "static". |
| 4 | +Önceki bölümlerde ele aldığımız ifadelere içeri aktarım ve dışa aktarım ifadelerine "statik" denir. |
5 | 5 |
|
6 | | -That's because they are indeed static. The syntax is very strict. |
| 6 | +Çünkü onlar gerçekten statik. Sözdizimi çok katıdır. |
7 | 7 |
|
8 | | -First, we can't dynamically generate any parameters of `import`. |
| 8 | +Birincisi, dinamik olarak `import` parametresini oluşturamıyoruz. |
9 | 9 |
|
10 | | -The module path must be a primitive string, can't be a function call. This won't work: |
| 10 | +Modül yolu ilkel bir dize olmalı ve işlev çağrısı olamaz. Bu çalışmayacaktır: |
11 | 11 |
|
12 | 12 | ```js |
13 | | -import ... from *!*getModuleName()*/!*; // Error, only from "string" is allowed |
| 13 | +import ... from *!*getModuleName()*/!*; // Hata, sadece "string"den izin verilir. |
14 | 14 | ``` |
15 | 15 |
|
16 | | -Second, we can't import conditionally or at run-time: |
| 16 | +İkincisi, koşullu veya çalışma zamanında içe aktaramıyoruz: |
17 | 17 |
|
18 | 18 | ```js |
19 | 19 | if(...) { |
20 | | - import ...; // Error, not allowed! |
| 20 | + import ...; // Hata, izin verilmiyor! |
21 | 21 | } |
22 | 22 |
|
23 | 23 | { |
24 | | - import ...; // Error, we can't put import in any block |
| 24 | + import ...; // Hata, içe aktarma işlemini herhangi bir bloğa koyamıyoruz. |
25 | 25 | } |
26 | 26 | ``` |
27 | 27 |
|
28 | | -That's because, import/export aim to provide a backbone for the code structure. That's a good thing, as code structure can be analyzed, modules can be gathered and bundled together, unused exports can be removed (tree-shaken). That's possible only because everything is fixed. |
| 28 | +Çünkü import/export kod yapısı için omurga sağlamayı hedefleriyor. Bu iyi bir şey, Kod yapısı analiz edilebildiğinden modüller toplanabilir ve birlikte paketlenebilir, kullanılmayan dışa aktarımlar kaldırılabilir (tree-shaken). Bu mümkün çünkü her şey sabit. |
29 | 29 |
|
30 | | -But how do we import a module dynamically, on-demand? |
31 | 30 |
|
32 | | -## The import() function |
| 31 | +Ancak bir modülü dinamik ve isteğe bağlı olarak nasıl içeriye aktarırız? |
33 | 32 |
|
34 | | -The `import(module)` function can be called from anywhere. It returns a promise that resolves into a module object. |
| 33 | +## import() Fonksiyonu |
35 | 34 |
|
36 | | -The usage pattern looks like this: |
| 35 | +`import(module)` fonksiyonu her yerden çağrılabilir. Bir modül nesnesine çözümlenen bir söz verir. |
37 | 36 |
|
| 37 | +Kullanım şekli şöyle görünür: |
38 | 38 | ```js run |
39 | 39 | let modulePath = prompt("Module path?"); |
40 | 40 |
|
41 | 41 | import(modulePath) |
42 | | - .then(obj => <module object>) |
43 | | - .catch(err => <loading error, no such module?>) |
| 42 | + .then(obj => <modül nesnesi>) |
| 43 | + .catch(err => <yükleme hatası, böyle bir modül yok?>) |
44 | 44 | ``` |
45 | 45 |
|
46 | | -Or, we could use `let module = await import(modulePath)` if inside an async function. |
| 46 | +Veya bir zaman async işlevi içindeyse `let module = await import(modulePath)` kullanabiliriz |
47 | 47 |
|
48 | | -Like this: |
| 48 | +Bunun gibi: |
49 | 49 |
|
50 | 50 | [codetabs src="say" current="index.html"] |
51 | 51 |
|
52 | | -So, dynamic imports are very simple to use. |
| 52 | +Bu nedenle dinamik içe aktarım kullanımı çok basittir. |
53 | 53 |
|
54 | | -Also, dynamic imports work in regular scripts, they don't require `script type="module"`. |
| 54 | +Ayrıca dinamik içeri aktarımlar düzenli komut dosyalarında çalışır, `script type="module"` gerektirmezler. |
0 commit comments