Skip to content

Commit 31143ba

Browse files
authored
Merge pull request #79 from Salah856/master
Dynamic imports
2 parents f55afac + fe18ea2 commit 31143ba

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

  • 1-js/13-modules/03-modules-dynamic-imports

1-js/13-modules/03-modules-dynamic-imports/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Dynamic imports
22

3-
Export and import statements that we covered in previous chapters are called "static". The syntax is very simple and strict.
3+
بيانات التصدير والاستيراد التي تناولناها في الفصول السابقة تسمى "ثابتة". النحو بسيط للغاية وصارم.
44

5-
First, we can't dynamically generate any parameters of `import`.
5+
أولاً ، لا يمكننا إنشاء أي لـ "استيراد" ديناميكيًا.
66

7-
The module path must be a primitive string, can't be a function call. This won't work:
7+
يجب أن يكون مسار الوحدة النمطية سلسلة أولية ، ولا يمكن أن يكون استدعاء دالة. هذا لن يعمل:
88

99
```js
1010
import ... from *!*getModuleName()*/!*; // Error, only from "string" is allowed
@@ -22,15 +22,15 @@ if(...) {
2222
}
2323
```
2424

25-
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 into one file by special tools, unused exports can be removed ("tree-shaken"). That's possible only because the structure of imports/exports is simple and fixed.
25+
وذلك لأن `الاستيراد` /` التصدير` يهدف إلى توفير العمود الفقري لبنية الكود. هذا شيء جيد ، حيث يمكن تحليل بنية الكود ، ويمكن تجميع الوحدات وتجميعها في ملف واحد بواسطة أدوات خاصة ، ويمكن إزالة عمليات التصدير غير المستخدمة ("اهتزاز الشجرة"). هذا ممكن فقط لأن هيكل الواردات / الصادرات بسيط وثابت.
2626

27-
But how can we import a module dynamically, on-demand?
27+
ولكن كيف يمكننا استيراد وحدة نمطية ديناميكيًا حسب الطلب؟
2828

2929
## The import() expression
3030

31-
The `import(module)` expression loads the module and returns a promise that resolves into a module object that contains all its exports. It can be called from any place in the code.
31+
يقوم التعبير "import (module)" بتحميل الوحدة النمطية وإرجاع الوعد الذي يتم حله في كائن الوحدة النمطية الذي يحتوي على كافة عمليات التصدير الخاصة به. يمكن استدعاؤها من أي مكان في التعليمات البرمجية.
3232

33-
We can use it dynamically in any place of the code, for instance:
33+
يمكننا استخدامه ديناميكيًا في أي مكان من الرمز ، على سبيل المثال:
3434

3535
```js
3636
let modulePath = prompt("Which module to load?");
@@ -40,9 +40,9 @@ import(modulePath)
4040
.catch(err => <loading error, e.g. if no such module>)
4141
```
4242

43-
Or, we could use `let module = await import(modulePath)` if inside an async function.
43+
أو يمكننا استخدام `let module = انتظار الاستيراد (modulePath)` إذا كان داخل دالة غير متزامنة.
4444

45-
For instance, if we have the following module `say.js`:
45+
على سبيل المثال ، إذا كان لدينا الوحدة التالية `say.js`:
4646

4747
```js
4848
// 📁 say.js
@@ -55,7 +55,7 @@ export function bye() {
5555
}
5656
```
5757

58-
...Then dynamic import can be like this:
58+
... ثم يمكن أن يكون الاستيراد الديناميكي مثل هذا:
5959

6060
```js
6161
let {hi, bye} = await import('./say.js');
@@ -64,7 +64,7 @@ hi();
6464
bye();
6565
```
6666

67-
Or, if `say.js` has the default export:
67+
أو ، إذا كان `say.js` يحتوي على التصدير الافتراضي:
6868

6969
```js
7070
// 📁 say.js
@@ -73,7 +73,7 @@ export default function() {
7373
}
7474
```
7575

76-
...Then, in order to access it, we can use `default` property of the module object:
76+
... ثم ، للوصول إليه ، يمكننا استخدام خاصية "افتراضي" لكائن الوحدة:
7777

7878
```js
7979
let obj = await import('./say.js');
@@ -83,16 +83,16 @@ let say = obj.default;
8383
say();
8484
```
8585

86-
Here's the full example:
86+
هنا المثال كاملا:
8787

8888
[codetabs src="say" current="index.html"]
8989

9090
```smart
91-
Dynamic imports work in regular scripts, they don't require `script type="module"`.
91+
تعمل عمليات الاستيراد الديناميكية في النصوص العادية ، ولا تتطلب ذلك `script type="module"`.
9292
```
9393

9494
```smart
95-
Although `import()` looks like a function call, it's a special syntax that just happens to use parentheses (similar to `super()`).
95+
على الرغم من أن `` import () `يشبه استدعاء دالة ، إلا أنها بناء جملة خاص يحدث فقط لاستخدام الأقواس (على غرار` super () `).
9696
97-
So we can't copy `import` to a variable or use `call/apply` with it. It's not a function.
97+
لذلك لا يمكننا نسخ "استيراد" إلى متغير أو استخدام "استدعاء / تطبيق" معه. إنها ليست وظيفة.
9898
```

0 commit comments

Comments
 (0)