| OLD | NEW |
| (Empty) | |
| 1 Sky module system |
| 2 ================= |
| 3 |
| 4 This document describes the Sky module system. |
| 5 |
| 6 Overview |
| 7 -------- |
| 8 |
| 9 The Sky module system is based on the ```import``` element. In its |
| 10 most basic form, you import a module as follows: |
| 11 |
| 12 ```html |
| 13 <import src="path/to/module.sky" /> |
| 14 ``` |
| 15 |
| 16 As these ```import``` elements are inserted into a document, the |
| 17 document's list of outstanding dependencies grows. When an imported |
| 18 module completes, it is removed from the document's list of |
| 19 outstanding dependencies. |
| 20 |
| 21 Before executing any ```script``` elements, the parser waits until the |
| 22 list of outstanding dependencies is empty. After the parser has |
| 23 finished parsing, the document waits until its list of outstanding |
| 24 dependencies is empty before the module it represents is marked |
| 25 complete. |
| 26 |
| 27 Module API |
| 28 ---------- |
| 29 |
| 30 Within a script in a module, the ```module``` identifier is bound to |
| 31 the ```Module``` object that represents the module: |
| 32 |
| 33 ``` |
| 34 interface Module : EventTarget { |
| 35 constructor (Application application, Document document); // O(1) |
| 36 attribute any exports; // O(1) // defaults to the module's document |
| 37 readonly attribute Document document; // O(1) // the module's document |
| 38 readonly attribute Application application; // O(1) |
| 39 } |
| 40 ``` |
| 41 |
| 42 ### Exporting values ### |
| 43 |
| 44 A module can export a value by assigning the ```exports``` property of |
| 45 its ```Module``` object. By default, the ```exports``` property of a |
| 46 ```Module``` is its ```Document``` object, so that a script-less |
| 47 import is still useful (it exposes its contents, e.g. templates that |
| 48 the import might have been written to provide). |
| 49 |
| 50 Naming modules |
| 51 -------------- |
| 52 |
| 53 The ```as``` attribute on the ```import``` element binds a name to the |
| 54 imported module: |
| 55 |
| 56 ```html |
| 57 <import src="path/to/chocolate.sky" as="chocolate" /> |
| 58 ``` |
| 59 |
| 60 The parser executes the contents of script elements inside a module as |
| 61 if they were executed as follow: |
| 62 |
| 63 ```javascript |
| 64 (new Function(module, name_1, ..., name_n, source_code)).call( |
| 65 source_module, value_1, ..., value_n); |
| 66 ``` |
| 67 |
| 68 Where ```name_1``` through ```name_n``` are the names bound to the |
| 69 various named imports in the script element's document, |
| 70 ```source_code``` is the text content of the script element, |
| 71 ```source_module`` is the ```Module``` object of the script element's |
| 72 module, and ```value_1``` through ```value_n``` are the values |
| 73 exported by the various named imports in the script element's |
| 74 document. |
| 75 |
| 76 When an import fails to load, the ```as``` name for the import gets |
| 77 bound to ```undefined```. |
| OLD | NEW |