| 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: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 Before compiling script or inserting an element that is not already | 21 Before compiling 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 Each module consists of one or more libraries. The first library in a |
| 32 the ``Module`` object that represents the module. | 32 module is the *element tree library*, which imports the sky:core |
| 33 module and then consists of the following code for a Sky module: |
| 33 | 34 |
| 34 ### Exporting values ### | 35 ```dart |
| 36 final Module module = new Module(); |
| 37 ``` |
| 35 | 38 |
| 36 A module can export a value by assigning the ``exports`` property of | 39 ...and the following code for a Sky application: |
| 37 its ``Module`` object. By default, the ``exports`` property of a | 40 |
| 38 ``Module`` is an empty Object. Properties can be added to the object, | 41 ```dart |
| 39 or, it can be set to an entirely different object; for example, it | 42 final Module module = new Application(); |
| 40 could be set to the module's ``Document`` itself, in case the point of | 43 ``` |
| 41 the module is to expose some ``template`` elements. | 44 |
| 45 The ``<script>`` elements found in the document create the subsequent |
| 46 libraries. Each one first imports the ``dart:mirror`` library, then |
| 47 the ``sky:core`` module, then the first library described above, then |
| 48 all the modules referenced by ``<import>`` element up to that |
| 49 ``<script>`` element and all the libraries defined by ``<script>`` |
| 50 elements up to that point, interleaved so as to maintain the same |
| 51 relative order as those elements were first seen by the parser. |
| 52 |
| 53 When a library imports a module, it actually imports all the libraries |
| 54 that were declared by that module except the element tree library. |
| 55 |
| 56 At the end of the ``<script>`` block's source, if it parsed correctly |
| 57 and completely, the following code is appended: |
| 58 |
| 59 ```dart |
| 60 class _ { } |
| 61 module.registerElements(reflectClass(_).owner); |
| 62 ``` |
| 63 |
| 64 TODO(ianh): decide what URL and name we should give the libraries, as |
| 65 exposed in MirrorSystem.getName(libraryMirror.qualifiedName) etc |
| 66 |
| 67 The ``Module`` class is defined in ``sky:core`` as follows: |
| 68 |
| 69 |
| 70 TODO(ianh): dartification of the rest of this file |
| 42 | 71 |
| 43 ### Exporting element definitions ### | 72 ### Exporting element definitions ### |
| 44 | 73 |
| 45 When importing a module into another, Sky runs the following steps: | 74 When importing a module into another, Sky runs the following steps: |
| 46 - let export be the imported module's ``exports`` value | 75 - let export be the imported module's ``exports`` value |
| 47 - try to import export | 76 - try to import export |
| 48 - if that fails: | 77 - if that fails: |
| 49 - try to import each property of export | 78 - try to import each property of export |
| 50 | 79 |
| 51 "Try to import" a value means to run the following steps: | 80 "Try to import" a value means to run the following steps: |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 Where ``name_1`` through ``name_n`` are the names bound to the | 186 Where ``name_1`` through ``name_n`` are the names bound to the |
| 158 various named imports in the script element's document, | 187 various named imports in the script element's document, |
| 159 ``source_code`` is the text content of the script element, | 188 ``source_code`` is the text content of the script element, |
| 160 ``source_module`` is the ``Module`` object of the script element's | 189 ``source_module`` is the ``Module`` object of the script element's |
| 161 module, and ``value_1`` through ``value_n`` are the values | 190 module, and ``value_1`` through ``value_n`` are the values |
| 162 exported by the various named imports in the script element's | 191 exported by the various named imports in the script element's |
| 163 document. | 192 document. |
| 164 | 193 |
| 165 When an import fails to load, the ``as`` name for the import gets | 194 When an import fails to load, the ``as`` name for the import gets |
| 166 bound to ``undefined``. | 195 bound to ``undefined``. |
| OLD | NEW |