| 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 any ```script``` elements, the parser waits until the | 21 Before executing any ```script``` elements, the parser waits until the |
| 22 list of outstanding dependencies is empty. After the parser has | 22 list of outstanding dependencies is empty. After the parser has |
| 23 finished parsing, the document waits until its list of outstanding | 23 finished parsing, the document waits until its list of outstanding |
| 24 dependencies is empty before the module it represents is marked | 24 dependencies is empty before the module it represents is marked |
| 25 complete. | 25 complete. |
| 26 | 26 |
| 27 |
| 27 Module API | 28 Module API |
| 28 ---------- | 29 ---------- |
| 29 | 30 |
| 30 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 |
| 31 the ```Module``` object that represents the module: | 32 the ```Module``` object that represents the module: |
| 32 | 33 |
| 33 ```javascript | 34 ```javascript |
| 34 interface Module : EventTarget { | 35 interface Module : EventTarget { |
| 35 constructor (Application application, Document document); // O(1) | 36 constructor (Application application, Document document); // O(1) |
| 36 attribute any exports; // O(1) // defaults to the module's document | 37 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 Document document; // O(1) // the module's document |
| 38 readonly attribute Application application; // O(1) | 39 readonly attribute Application application; // O(1) |
| 39 } | 40 } |
| 40 ``` | 41 ``` |
| 41 | 42 |
| 42 ### Exporting values ### | 43 ### Exporting values ### |
| 43 | 44 |
| 44 A module can export a value by assigning the ```exports``` property of | 45 A module can export a value by assigning the ```exports``` property of |
| 45 its ```Module``` object. By default, the ```exports``` property of a | 46 its ```Module``` object. By default, the ```exports``` property of a |
| 46 ```Module``` is its ```Document``` object, so that a script-less | 47 ```Module``` is its ```Document``` object, so that a script-less |
| 47 import is still useful (it exposes its contents, e.g. templates that | 48 import is still useful (it exposes its contents, e.g. templates that |
| 48 the import might have been written to provide). | 49 the import might have been written to provide). |
| 49 | 50 |
| 51 ### Exporting element definitions ### |
| 52 |
| 53 When importing a module into another, Sky looks at the properties on |
| 54 the imported module's ``exports`` value, and for each property that is |
| 55 an element constructor (generated by ``registerElement()``), it adds |
| 56 an element to the importee's element registry. |
| 57 |
| 58 |
| 50 Naming modules | 59 Naming modules |
| 51 -------------- | 60 -------------- |
| 52 | 61 |
| 53 The ```as``` attribute on the ```import``` element binds a name to the | 62 The ```as``` attribute on the ```import``` element binds a name to the |
| 54 imported module: | 63 imported module: |
| 55 | 64 |
| 56 ```html | 65 ```html |
| 57 <import src="path/to/chocolate.sky" as="chocolate" /> | 66 <import src="path/to/chocolate.sky" as="chocolate" /> |
| 58 ``` | 67 ``` |
| 59 | 68 |
| 60 The parser executes the contents of script elements inside a module as | 69 The parser executes the contents of script elements inside a module as |
| 61 if they were executed as follow: | 70 if they were executed as follow: |
| 62 | 71 |
| 63 ```javascript | 72 ```javascript |
| 64 (new Function(name_1, ..., name_n, module, source_code)).call( | 73 (new Function(name_1, ..., name_n, module, source_code)).call( |
| 65 value_1, ..., value_n, source_module); | 74 value_1, ..., value_n, source_module); |
| 66 ``` | 75 ``` |
| 67 | 76 |
| 68 Where ```name_1``` through ```name_n``` are the names bound to the | 77 Where ```name_1``` through ```name_n``` are the names bound to the |
| 69 various named imports in the script element's document, | 78 various named imports in the script element's document, |
| 70 ```source_code``` is the text content of the script element, | 79 ```source_code``` is the text content of the script element, |
| 71 ```source_module`` is the ```Module``` object of the script element's | 80 ```source_module`` is the ```Module``` object of the script element's |
| 72 module, and ```value_1``` through ```value_n``` are the values | 81 module, and ```value_1``` through ```value_n``` are the values |
| 73 exported by the various named imports in the script element's | 82 exported by the various named imports in the script element's |
| 74 document. | 83 document. |
| 75 | 84 |
| 76 When an import fails to load, the ```as``` name for the import gets | 85 When an import fails to load, the ```as``` name for the import gets |
| 77 bound to ```undefined```. | 86 bound to ```undefined```. |
| OLD | NEW |