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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ### | 50 ### IDL ### |
51 | 51 |
52 ```javascript | 52 ```javascript |
| 53 dictionary InternalElementOptions { |
| 54 String tagName; |
| 55 Boolean shadow = false; |
| 56 Object prototype = Element; |
| 57 } |
| 58 interface InternalElementConstructorWithoutShadow { |
| 59 constructor (Module module); |
| 60 attribute String tagName; |
| 61 } |
| 62 interface InternalElementConstructorWithShadow { |
| 63 constructor (Module module); |
| 64 attribute String tagName; |
| 65 attribute Boolean shadow; |
| 66 } |
| 67 typedef ElementRegistrationOptions (InternalElementOptions or |
| 68 InternalElementConstructorWithoutShadow or |
| 69 InternalElementConstructorWithShadow); |
| 70 |
53 abstract class AbstractModule : EventTarget { | 71 abstract class AbstractModule : EventTarget { |
54 readonly attribute Document document; // O(1) // the Documentof the module or
application | 72 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 | 73 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 | 74 private Array<Module> getImports(); O(N) // returns the Module objects of all
the imported modules |
57 | 75 |
58 readonly attribute String url; | 76 readonly attribute String url; |
59 | 77 |
60 ElementConstructor registerElement(ElementRegistration options); // O(1) | 78 ElementConstructor registerElement(Object options); // O(1) |
61 // if you call registerElement() with an object that was created by | 79 // if you call registerElement() with an object that was created by |
62 // registerElement(), it just returns the object after registering it, | 80 // registerElement(), it just returns the object after registering it, |
63 // rather than creating a new constructor | 81 // rather than creating a new constructor |
64 // otherwise, it proceeds as follows: | 82 // otherwise, it proceeds as follows: |
65 // 1. let constructor be the constructor passed in, if any | 83 // - if options is a Function (i.e. it is either an |
66 // 2. let prototype be the constructor's prototype; if there is no | 84 // InternalElementConstructorWithoutShadow object or an |
67 // constructor, let prototype be Element | 85 // InternalElementConstructorWithShadow object), then let |
68 // 3. create a new Function that: | 86 // constructor be that function, and let prototype be that |
69 // 1. throws if not called as a constructor | 87 // functions's prototype; otherwise, let constructor be a no-op |
70 // 2. creates an actual Element object | 88 // function and let prototype be the prototype property of the |
71 // 3. initialises the shadow tree if shadow on the options is true | 89 // object passed in (the InternalElementOptions; prototype |
72 // 4. calls constructor, if it's not null, with the module as the argumen
t | 90 // defaults to Element). |
73 // 4. let that new Function's prototype be the aforementioned prototype | 91 // - let shadow be option's shadow property's value coerced to a |
74 // 5. let that new Function have tagName and shadow properties set to | 92 // boolean, if the property is present, or else the value false. |
75 // the values passed in on options | 93 // - let shadow be option's tagName property's value. |
76 // 6. register the new element | 94 // - create a new Function that: |
| 95 // - throws if not called as a constructor |
| 96 // - creates an actual element object (the C++-backed object) |
| 97 // - initialises the shadow tree if shadow on the options is |
| 98 // true |
| 99 // - calls constructor, if it's not null, with the module as |
| 100 // the argument |
| 101 // - is marked as created by registerElement() so that it can |
| 102 // be recognised if used as an argument to registerElement() |
| 103 // - let that new Function's prototype be the aforementioned prototype |
| 104 // - let that new Function have tagName and shadow properties set to |
| 105 // the aforementioned tagName and shadow |
| 106 // - register the new tagName with this constructor |
| 107 // - return the new Function (which is, not coincidentally, an |
| 108 // InternalElementConstructorWithShadow) |
77 | 109 |
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 | 110 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 } | 111 } |
80 | 112 |
81 class Module : AbstractModule { | 113 class Module : AbstractModule { |
82 constructor (Application application, Document document, String url); // O(1) | 114 constructor (Application application, Document document, String url); // O(1) |
83 readonly attribute Application application; // O(1) | 115 readonly attribute Application application; // O(1) |
84 | 116 |
85 attribute any exports; // O(1) // defaults to {} | 117 attribute any exports; // O(1) // defaults to {} |
86 } | 118 } |
(...skipping 26 matching lines...) Expand all Loading... |
113 Where ``name_1`` through ``name_n`` are the names bound to the | 145 Where ``name_1`` through ``name_n`` are the names bound to the |
114 various named imports in the script element's document, | 146 various named imports in the script element's document, |
115 ``source_code`` is the text content of the script element, | 147 ``source_code`` is the text content of the script element, |
116 ``source_module`` is the ``Module`` object of the script element's | 148 ``source_module`` is the ``Module`` object of the script element's |
117 module, and ``value_1`` through ``value_n`` are the values | 149 module, and ``value_1`` through ``value_n`` are the values |
118 exported by the various named imports in the script element's | 150 exported by the various named imports in the script element's |
119 document. | 151 document. |
120 | 152 |
121 When an import fails to load, the ``as`` name for the import gets | 153 When an import fails to load, the ``as`` name for the import gets |
122 bound to ``undefined``. | 154 bound to ``undefined``. |
OLD | NEW |