A. KULLANIM

Örnek dosyalama yapısı aşağıdaki gibi tasarlanmıştır:

/src/abstractions/an-interface.ts
/src/abstractions/mod.ts
/src/sub-component/a-function.ts
/src/sub-component/a-function.deps.ts
/src/sub-component/mod.ts
/src/another-function.ts
/src/yet-another-function.ts
/src/deps.ts
/src/mod.ts
/src/cli.ts

Dosyalama yapısı oluşturulurken aşağıdaki ilkeler ve kabuller göz önünde bulundurulmuştur:

1. mod.ts modülleri

Bu yapıda tüm kod tabanı, ve kod tabanının alt bileşenleri, kendi kapsamlarındaki tanımlamaları export ettikleri mod.ts modülüne sahiptirler. Bu modül tipleri birden fazla tanımlama (fonksiyon, sınıf, v.b.) export edebilirler.

Bu modüllerde herhangi bir yeni tanımlama yapılmamalı, yine içerisinde yan etki meydana getirebilecek şekilde kodlar çalıştırmamalıdır. Bu tipteki modüller yalnızca import ve export işlemleri için kullanılmalıdır.

Doğru Örnek:

import * as subComponent from "./sub-component/mod.ts";
import anotherFunction from "./another-function.ts";
import yetAnotherFunction from "./yet-another-function.ts";

export * from "./abstractions/mod.ts";
export { anotherFunction, yetAnotherFunction };

Yanlış Örnek:

import * as subComponent from "./sub-component/mod.ts";
import anotherFunction from "./another-function.ts";

function newlyDefinedOne() {  // BAD: shouldn't be defined here
  console.log("there");
}

console.log("I was here");    // BAD: a side-effect

export * from "./abstractions/mod.ts";
export { anotherFunction, newlyDefinedOne };

2. (*.)deps.ts modülleri

Bağımlılık modülleri olarak da isimlendirilebilecek bu modüller belirli dış bağımlılıklara ait tanımlamaları tek modül altında toparlama görevi görürler. deps.ts ait olduğu dizin ve alt dizinlerinde, [modül].deps.ts olarak isimlendirilmiş modüller ise yalnızca [modül].ts modülünde, dış bağımlılıkları toparlamaktadırlar.

Bu modül tipleri varsayılan export tanımlamaz ve birden fazla tanımlama export edebilirler. Yine bu modüllerin içerisinde yan etki meydana getirebilecek şekilde kodlar çalıştırmamalıdır.

Doğru Örnek:

import * as log from "<https://deno.land/std/log/mod.ts>";
import * as logLevels from "<https://deno.land/std/log/levels.ts>";
import * as oak from "<https://deno.land/x/oak/mod.ts>";

export { log, logLevels, oak };

Yanlış Örnek:

import * as log from "<https://deno.land/std/log/mod.ts>";
// BAD: partially imported dependency
import { Application } from "<https://deno.land/x/oak/mod.ts>";

export {
  log as default,  // BAD: use named export instead of default export
  Application,     // BAD: partially exported dependency
};

3. [modül].ts modülleri

Bu modüller yalnızca tanımlamalardan oluşur.

İçerisinde birden fazla tanımlama yer alsa dahi yalnızca tek tanımlama export etmelidir. Bu modüller yan etki meydana getirebilecek şekilde tanımlama dışında kalacak kodlar çalıştırmamalıdır.

Doğru Örnek:

import type AnInterface from "./abstractions/an-interface.ts";

function anImplementation(message: string, error: Error): AnInterface {
  return Promise.resolve({
    payload: message,
    error: error,
  });
}

export { anImplementation as default };