| 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 29 matching lines...) Expand all Loading... |
| 40 could be set to the module's Document itself, in case the point of the | 40 could be set to the module's Document itself, in case the point of the |
| 41 module is to expose some ``template`` elements. | 41 module is to expose some ``template`` elements. |
| 42 | 42 |
| 43 ### Exporting element definitions ### | 43 ### Exporting element definitions ### |
| 44 | 44 |
| 45 When importing a module into another, Sky looks at the properties on | 45 When importing a module into another, Sky looks at the properties on |
| 46 the imported module's ``exports`` value, and for each property that is | 46 the imported module's ``exports`` value, and for each property that is |
| 47 an element constructor (generated by ``registerElement()``), it adds | 47 an element constructor (generated by ``registerElement()``), it adds |
| 48 an element to the importee's element registry. | 48 an element to the importee's element registry. |
| 49 | 49 |
| 50 ### IDL ### |
| 51 |
| 52 ```javascript |
| 53 abstract class AbstractModule : EventTarget { |
| 54 readonly attribute Document document; // O(1) // the Documentof the module or
application |
| 55 Promise<any> import(String url); // O(Yikes) // returns the module's exports |
| 56 private Array<Module> getImports(); O(N) // returns the Module objects of all
the imported modules |
| 57 |
| 58 readonly attribute String url; |
| 59 |
| 60 ElementConstructor registerElement(ElementRegistration options); // O(1) |
| 61 // if you call registerElement() with an object that was created by |
| 62 // registerElement(), it just returns the object after registering it, |
| 63 // rather than creating a new constructor |
| 64 // otherwise, it proceeds as follows: |
| 65 // 1. let constructor be the constructor passed in, if any |
| 66 // 2. let prototype be the constructor's prototype; if there is no |
| 67 // constructor, let prototype be Element |
| 68 // 3. create a new Function that: |
| 69 // 1. throws if not called as a constructor |
| 70 // 2. creates an actual Element object |
| 71 // 3. initialises the shadow tree if shadow on the options is true |
| 72 // 4. calls constructor, if it's not null, with the module as the argumen
t |
| 73 // 4. let that new Function's prototype be the aforementioned prototype |
| 74 // 5. let that new Function have tagName and shadow properties set to |
| 75 // the values passed in on options |
| 76 // 6. register the new element |
| 77 |
| 78 readonly attribute ScriptElement? currentScript; // O(1) // returns the <scrip
t> element currently being executed if any, and if it's in this module; else nul
l |
| 79 } |
| 80 |
| 81 class Module : AbstractModule { |
| 82 constructor (Application application, Document document, String url); // O(1) |
| 83 readonly attribute Application application; // O(1) |
| 84 |
| 85 attribute any exports; // O(1) // defaults to {} |
| 86 } |
| 87 |
| 88 class Application : AbstractModule { |
| 89 constructor (Document document, String url); // O(1) |
| 90 attribute String title; // O(1) |
| 91 } |
| 92 ``` |
| 93 |
| 50 | 94 |
| 51 Naming modules | 95 Naming modules |
| 52 -------------- | 96 -------------- |
| 53 | 97 |
| 54 The ``as`` attribute on the ``import`` element binds a name to the | 98 The ``as`` attribute on the ``import`` element binds a name to the |
| 55 imported module: | 99 imported module: |
| 56 | 100 |
| 57 ```html | 101 ```html |
| 58 <import src="path/to/chocolate.sky" as="chocolate" /> | 102 <import src="path/to/chocolate.sky" as="chocolate" /> |
| 59 ``` | 103 ``` |
| 60 | 104 |
| 61 The parser executes the contents of script elements inside a module as | 105 The parser executes the contents of script elements inside a module as |
| 62 if they were executed as follow: | 106 if they were executed as follow: |
| 63 | 107 |
| 64 ```javascript | 108 ```javascript |
| 65 (new Function(name_1, ..., name_n, module, source_code)).call( | 109 (new Function(name_1, ..., name_n, module, source_code)).call( |
| 66 value_1, ..., value_n, source_module); | 110 value_1, ..., value_n, source_module); |
| 67 ``` | 111 ``` |
| 68 | 112 |
| 69 Where ``name_1`` through ``name_n`` are the names bound to the | 113 Where ``name_1`` through ``name_n`` are the names bound to the |
| 70 various named imports in the script element's document, | 114 various named imports in the script element's document, |
| 71 ``source_code`` is the text content of the script element, | 115 ``source_code`` is the text content of the script element, |
| 72 ``source_module`` is the ``Module`` object of the script element's | 116 ``source_module`` is the ``Module`` object of the script element's |
| 73 module, and ``value_1`` through ``value_n`` are the values | 117 module, and ``value_1`` through ``value_n`` are the values |
| 74 exported by the various named imports in the script element's | 118 exported by the various named imports in the script element's |
| 75 document. | 119 document. |
| 76 | 120 |
| 77 When an import fails to load, the ``as`` name for the import gets | 121 When an import fails to load, the ``as`` name for the import gets |
| 78 bound to ``undefined``. | 122 bound to ``undefined``. |
| OLD | NEW |