Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/_docs/General/best-practices.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Best practices"
category: General
order: 4
order: 5
toc: false
---

Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/General/classes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Classes"
category: General
order: 3
order: 4
toc: true
---

Expand Down
88 changes: 88 additions & 0 deletions docs/_docs/General/module-system.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: "Module System"
category: General
order: 1
toc: true
---

The scripts requires its scripts to be written as **modules**.
The idea behind modules is to specify which information inside a script should be made available to other scripts.
In addition the module systems helps making it apparent which information inside a script is taken from other scripts.

A module basically consists of two types of operations: **module includes** and **module exports**.

## Module Includes

A module include is required to use code defined in another module.
There are two types of module includes: the **default include** and the **named include**.

### Default Include

Whenever an included module should be used as a single object, like a `class` object, it should be included using a **default include**.
A default include assigns an included module to a variable:

```javascript
const Module = include("module.id");

// do something with module
```

The assigned variable will contain the value that has been assigned to the **default export** of the included module.

### Named Include

In other cases a single module exports multiple values, which can be used independently from each other.
In such situations the different values can be included using a **named include**.
A named include allows the selection of only a subset of the exported values to be included:

```javascript
const { foo, bar, x, y } = include("module.id");

// do something with foo, bar, x and y
```

The included values can be any kind of object like functions, classes or constants.

## Module Exports

To allow other modules to include values from another module, the module needs to first export it.
An export statement specifies as a form of contract that a value should be _exported_ to other modules and therefore be used by the other modules.
Values are exported by assigning them to the `module` variable which is made available when executing the module script.
A module can contain two types export statements: a single **default export** or multiple **named exports**.

### Named Exports

In some cases a module will need to export multiple values.
In such situations **named exports** can be used.
A named export assigns each exported value to its own variable of the `module` variable:

```javascript
module.foo = function() {
...
};

module.bar = function(input) {
...
};

module.x = // exported value
module.y = // other exported value
```

The previous example module exports four values: `foo`, `bar`, `x` and `y`, which can be included using the code shown in the **Named Include** section.

### Default Export

Often a module will only export a single value.
In such situations a **default export** can be used to make the value accessible by other modules.
A single value can be exported by using:

```javascript
module.default = // value to export
```

The single exported default value needs to be assigned to the `default` value of the `module` variable.
This defines the value as the default export of the module.

A module can either use a single default export **or** multiple named exports.
When a module uses both export types the default export is applied.
2 changes: 1 addition & 1 deletion docs/_docs/General/tools.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Tools"
category: General
order: 1
order: 2
toc: true
---

Expand Down
2 changes: 1 addition & 1 deletion docs/_docs/General/translation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Translation"
category: General
order: 2
order: 3
toc: false
---

Expand Down