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 module's element |
17 document's list of outstanding dependencies grows. When an imported | 17 tree, the module's list of outstanding dependencies grows. When an |
18 module completes, it is removed from the document's list of | 18 imported module completes, it is removed from the importing module's |
19 outstanding dependencies. | 19 list of outstanding dependencies. |
20 | 20 |
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 module waits until its list of outstanding dependencies is empty |
25 before the module it represents is marked complete. | 25 before marking itself complete. |
26 | 26 |
27 The ``as`` attribute on the ``import`` element binds a name to the | 27 The ``as`` attribute on the ``import`` element binds a name to the |
28 imported module: | 28 imported module: |
29 | 29 |
30 ```html | 30 ```html |
31 <import src="path/to/chocolate.sky" as="chocolate" /> | 31 <import src="path/to/chocolate.sky" as="chocolate" /> |
32 ``` | 32 ``` |
33 | 33 |
34 | 34 |
35 Module API | 35 Module API |
36 ---------- | 36 ---------- |
37 | 37 |
38 Each module consists of one or more libraries. The first library in a | 38 Each module consists of one or more libraries. The first library in a |
39 module is the *element tree library*, which imports the dart:sky | 39 module is the *element tree library*, which imports the dart:sky |
40 module and then consists of the following code for a Sky module: | 40 module and then consists of the following code for a Sky module: |
41 | 41 |
42 ```dart | 42 ```dart |
43 final Module module = new Module(); | 43 final Module module = new Module(); |
44 ``` | 44 ``` |
45 | 45 |
46 ...and the following code for a Sky application: | 46 ...and the following code for a Sky application: |
47 | 47 |
48 ```dart | 48 ```dart |
49 final Module module = new Application(); | 49 final Module module = new Application(); |
50 ``` | 50 ``` |
51 | 51 |
52 The ``<script>`` elements found in the document create the subsequent | 52 The ``<script>`` elements found in the module's element tree create |
53 libraries. Each one first imports the ``dart:mirror`` library, then | 53 the subsequent libraries. Each one first imports the ``dart:mirror`` |
54 the ``dart:sky`` module, then the first library described above, then | 54 library, then the ``dart:sky`` module, then the first library |
55 all the modules referenced by ``<import>`` element up to that | 55 described above, then all the modules referenced by ``<import>`` |
56 ``<script>`` element and all the libraries defined by ``<script>`` | 56 element up to that ``<script>`` element and all the libraries defined |
57 elements up to that point, interleaved so as to maintain the same | 57 by ``<script>`` elements up to that point, interleaved so as to |
58 relative order as those elements were first seen by the parser. | 58 maintain the same relative order as those elements were first seen by |
| 59 the parser. |
59 | 60 |
60 When a library imports a module, it actually imports all the libraries | 61 When a library imports a module, it actually imports all the libraries |
61 that were declared by that module except the aforementioned element | 62 that were declared by that module except the aforementioned element |
62 tree library. If the ``as`` attribute is present on the ``import`` | 63 tree library. If the ``as`` attribute is present on the ``import`` |
63 element, all the libraries are bound to the same name. | 64 element, all the libraries are bound to the same name. |
64 | 65 |
65 At the end of the ``<script>`` block's source, if it parsed correctly | 66 At the end of the ``<script>`` block's source, if it parsed correctly |
66 and completely, the conceptual equivalent of the following code is | 67 and completely, the conceptual equivalent of the following code is |
67 appended (but without affecting the library's list of declarations and | 68 appended (but without affecting the library's list of declarations and |
68 without any possibility of it clashing with identifiers described in | 69 without any possibility of it clashing with identifiers described in |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 122 } |
122 | 123 |
123 class Application extends AbstractModule { | 124 class Application extends AbstractModule { |
124 Application({String url, Root elements, this.gestureManager}) : | 125 Application({String url, Root elements, this.gestureManager}) : |
125 super(url: url, elements: elements); // O(1) | 126 super(url: url, elements: elements); // O(1) |
126 external String get title; // O(1) | 127 external String get title; // O(1) |
127 external void set title(String newValue); // O(1) | 128 external void set title(String newValue); // O(1) |
128 final GestureManager gestureManager; | 129 final GestureManager gestureManager; |
129 } | 130 } |
130 ``` | 131 ``` |
OLD | NEW |