You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One should be careful about using default exports, because they are more difficult to maintain.
280
+
Varsayılan dışa aktarım kullanımlarında dikkat edilmelidir. Çünkü bakımı daha zordur.
281
281
282
-
Named exports are explicit. They exactly name what they import, so we have that information from them, that's a good thing.
282
+
Adlandırılmış açıktır. Aldıkları şeyi tam olarak açıklıyorlar. Bu yüzden onlardan bu bilgilere sahibiz. Bu iyi bir şey.
283
283
284
-
Also, named exports enforce us to use exactly the right name to import:
284
+
Ayrıca, adlandırılmış dışa aktarma işlemleri bizi içe aktarmak için doğru adı kullanmaya zorlar.:
285
285
286
286
```js
287
287
import {User} from './user.js';
288
-
// import {MyUser} won't work, the name must be {User}
288
+
// import {MyUser} çalışmayacak, adı {User} olmalı
289
289
```
290
290
291
-
For default exports, we always choose the name when importing:
291
+
Varsayılan içeriye aktarma için içeriye aktarırken her zaman adı seçeriz:
292
292
293
293
```js
294
-
import User from './user.js'; // works
295
-
import MyUser from './user.js'; // works too
296
-
// could be import Anything..., and it'll be work
294
+
import User from './user.js'; // çalışır
295
+
import MyUser from './user.js'; // çalışır
296
+
// Bir şey içeriye aktarılabilir..., ve çalışacaktır
297
297
```
298
+
Yani, kötüye kullanılabilecek biraz daha fazla özgürlük var. Böylece ekip üyeleri aynı şey için farklı isimler kullanabilirler.
298
299
299
-
So, there's a little bit more freedom that can be abused, so that team members may use different names for the same thing.
300
-
301
-
Usually, to avoid that and keep the code consistent, there's a rule that imported variables should correspond to file names, e.g:
300
+
Genelde, bundan kaçınmak ve kodu tutarlı tutmak için içe aktarılan değişkenlerin dosya adlarına karşılık gelmesi gerektiği bir kural vardır:
302
301
303
302
```js
304
303
import User from './user.js';
@@ -307,24 +306,24 @@ import func from '/path/to/func.js';
307
306
...
308
307
```
309
308
310
-
Another solution would be to use named exportseverywhere. Evenif only a single thing is exported, it's still exported under a name, without `default`.
309
+
Başka bir çözüm, her yerde adlandırılmış içeriye aktarım kullanmak olacaktır. Sadece tek bir şey içeriye aktarılsa bile yine de `default` olmadan bir isim altında içeriye aktarılır.
311
310
312
-
That also makes re-export (see below) a little bit easier.
311
+
Bu da re-export (aşağıda göreceksin) biraz daha kolay hale gelir.
313
312
314
313
## Re-export
315
314
316
-
"Re-export" syntax `export ... from ...` allows to import things and immediately export them (possibly under another name), like this:
315
+
"Re-export" söz dizimi `export ... from ...` şeyleri içeriye aktarmasına ve hemen (başka bir isim altında) içeriye aktarmasına izin verir:
317
316
318
317
```js
319
318
export {sayHi} from './say.js';
320
319
export {default as User} from './user.js';
321
320
```
322
321
323
-
What's the point, why that's needed? Let's see a practical use case.
322
+
Amaç ne? Neden bu gerekli? Pratik bir kullanım örneği görelim.
324
323
325
-
Imagine, we're writing a "package": a folder with a lot of modules, mostly needed internally, with some of the functionality exported outside (tools like NPM allow to publish and distribute packages, but here it doesn't matter).
324
+
Bir "paket" yazdığımızı düşünelim: dışarıda dışa aktarılan fonksiyonelliklerin bir kısmı ile çoğunlukla dahili olarak ihtiyaç duyulan birçok modüle sahip bir klasör (NPM gibi araçlar paketleri yayınlamaya ve dağıtmaya izin verir, ancak burada önemi yoktur).
326
325
327
-
A directory structure could be like this:
326
+
Bir klasör yapısı şöyle olabilir:
328
327
```
329
328
auth/
330
329
index.js
@@ -338,15 +337,16 @@ auth/
338
337
...
339
338
```
340
339
341
-
We'd like to expose the package functionality via a single entry point, the "main file" `auth/index.js`, to be used like this:
340
+
Paket işlevselliğini tek bir giriş noktası üzerinden göstermek istiyoruz, "ana dosya" `auth/index.js` böyle kullanılmalı,
342
341
343
342
```js
344
343
import {login, logout} from 'auth/index.js'
345
344
```
346
345
347
-
The idea is that outsiders, developers who use our package, should not meddle with its internal structure. They should not search for files inside our package folder. We export only what's necessary in `auth/index.js` and keep the rest hidden from prying eyes.
346
+
Buradaki fikir, paketimizi kullanan geliştiricilerin iç yapısıyla karışmaması gerektiğidir. Paket klasörümüzdeki dosyaları aramamalılar. Sadece `auth/index.js`de gerekli olanları dışarıya aktarıyoruz ve gerisini meraklı gözlerden gizleriz.
348
347
349
-
Now, as the actual exported functionality is scattered among the package, we can gather and "re-export" it in `auth/index.js`:
348
+
Şimdi, dışa aktarılan gerçek işlevsellik paketin arasına dağıl olduğundan, paket içinde "re-export" ve toplayabiliriz.
349
+
`auth/index.js`:
350
350
351
351
```js
352
352
// 📁 auth/index.js
@@ -361,12 +361,12 @@ export {Github};
361
361
...
362
362
```
363
363
364
-
"Re-exporting" is just a shorter notation for that:
364
+
"Re-exporting" bunun için sadece kısa bir gösterimidir:
365
365
366
366
```js
367
367
// 📁 auth/index.js
368
368
export {login, logout} from './helpers.js';
369
-
//or, to re-export all helpers, we could use:
369
+
// ya da tüm yardımcıları re-export için kullanabiliriz.
370
370
// export * from './helpers.js';
371
371
372
372
export {default as User} from './user.js';
@@ -376,17 +376,17 @@ export {default as Github} from './providers/github.js';
376
376
```
377
377
378
378
````warn header="Re-exporting default is tricky"
379
-
Please note: `export User from './user.js'` won't work. It's actually a syntax error. To re-export the default export, we must mention it explicitly `{default as ...}`, like in the example above.
379
+
Lütfen unutmayın: `export User from './user.js'` çalışmayacak. Bu aslında sözdizimi hatası. Varsayılan içeriye aktarmayı re-export için açıkça belirtmeliyiz `{default as ...}`. Yukarıdaki örnekte olduğu gibi.
380
380
381
-
Also, there's another oddity: `export * from './user.js'` re-exports only named exports, excluding the default one. Once again, we need to mention it explicitly.
381
+
Ayrıca, başka bir tuhaflık var: `export * from './user.js'` varsayılan olan haric, yalnızca adlandırılmış dışa aktarımlar yeniden dışa aktarılır. Bir kez daha açıkça söylemeliyiz.
382
382
383
-
For instance, to re-export everything, two statements will be necessary:
383
+
Örneğin, her şeyi yeniden dışa aktarmak için iki ifade gerekli olacaktır:
384
384
```js
385
-
export * from './module.js'; // to re-export named exports
386
-
export {default} from './module.js'; // to re-export default
385
+
export * from './module.js'; // adlandırılmış dışarıya aktarımı yeniden dışarıya aktarmak için
386
+
export {default} from './module.js'; // varsayılanı yeniden dışarıya aktarmak için
387
387
```
388
388
389
-
The default should be mentioned explicitly only when re-exporting: `import * as obj` works fine. It imports the default export as `obj.default`. So there's a slight asymmetry between import and export constructs here.
389
+
Varsayılan değer açıkça yalnızca yeniden dışa aktarırken belirtilmelidir `import * as obj` iyi çalışır. Varsayılan dışa aktarımı `obj.default` olarak alır. Yani burada içe aktarım ve dışa aktarım yapıları arasında hafif bir asimetri var.
0 commit comments