Skip to content

Latest commit

 

History

History
executable file
·
23 lines (12 loc) · 1.38 KB

adr-007.md

File metadata and controls

executable file
·
23 lines (12 loc) · 1.38 KB

ADR 7: Export/import full namespace, not individual functions

Context

The many packages in Alfa interact with each other and export/import a lot of code from one package to the other. This often lead to long list of imports when many bits from one package are needed, plus a risk of name collision when things are imported from different packages.

Both these problems can be alleviated by renaming import; using the import * as foo syntax; or bundling everything into a namespace that is exported.

Decision

We will use namespaces to bundle export from each package and never export individual functions. As much as possible, we will keep that separation also at the file level. Functions that are exported from a file will be marked as internal and only the re-export from a namespace in the package will make its way to the API.

For functions closely related to a data structure which is modelled by an existing class, the class and namespace will share the same name in order to merge into a single ES object.

Status

Accepted.

Consequences

Since we cannot import individual functions anymore, bundle size tend to increase. This is not a major problem for our use cases because the time to download Alfa is normally not critical.

Imports from other packages are usually limited to a few namespaces. Dotted notation makes it fairly clear in the code where some function comes from.