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