@@ -11,7 +11,7 @@ abstract class BoundComponentFactory {
11
11
List <Key > get callArgs;
12
12
Function call (dom.Element element);
13
13
14
- static async .Future <ViewFactory > _viewFactoryFuture (
14
+ static async .Future <ViewFactory > _viewFuture (
15
15
Component component, ViewCache viewCache, DirectiveMap directives) {
16
16
if (component.template != null ) {
17
17
return new async .Future .value (viewCache.fromHtml (component.template, directives));
@@ -65,27 +65,20 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
65
65
Component get _component => _ref.annotation as Component ;
66
66
67
67
String _tag;
68
- async .Future <List <dom.StyleElement >> _styleElementsFuture;
69
- List <dom.StyleElement > _styleElements;
70
- async .Future <ViewFactory > _shadowViewFactoryFuture;
71
- ViewFactory _shadowViewFactory;
68
+ async .Future <Iterable <dom.StyleElement >> _styleElementsFuture;
69
+ async .Future <ViewFactory > _viewFuture;
72
70
73
71
BoundShadowDomComponentFactory (this ._componentFactory, this ._ref, this ._directives) {
74
72
_tag = _component.selector.toLowerCase ();
75
- _styleElementsFuture = async .Future .wait (_component.cssUrls.map (_urlToStyle))
76
- ..then ((stylesElements) => _styleElements = stylesElements);
73
+ _styleElementsFuture = async .Future .wait (_component.cssUrls.map (_styleFuture));
77
74
78
- _shadowViewFactoryFuture = BoundComponentFactory ._viewFactoryFuture (
75
+ _viewFuture = BoundComponentFactory ._viewFuture (
79
76
_component,
80
- // TODO(misko): Why do we create a new one per Component. This kind of defeats the caching.
81
77
new PlatformViewCache (_componentFactory.viewCache, _tag, _componentFactory.platform),
82
78
_directives);
83
- if (_shadowViewFactoryFuture != null ) {
84
- _shadowViewFactoryFuture.then ((viewFactory) => _shadowViewFactory = viewFactory);
85
- }
86
79
}
87
80
88
- async .Future <dom.StyleElement > _urlToStyle (cssUrl) {
81
+ async .Future <dom.StyleElement > _styleFuture (cssUrl) {
89
82
Http http = _componentFactory.http;
90
83
TemplateCache templateCache = _componentFactory.templateCache;
91
84
WebPlatform platform = _componentFactory.platform;
@@ -114,7 +107,7 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
114
107
115
108
// If the css shim is required, it means that scoping does not
116
109
// work, and adding the style to the head of the document is
117
- // preferable .
110
+ // preferrable .
118
111
if (platform.cssShimRequired) {
119
112
dom.document.head.append (styleElement);
120
113
return null ;
@@ -133,57 +126,47 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
133
126
EventHandler eventHandler) {
134
127
var s = traceEnter (View_createComponent );
135
128
try {
136
- var shadowScope = scope.createChild (new HashMap ()); // Isolate
137
- ComponentDirectiveInjector shadowInjector;
138
- dom.ShadowRoot shadowRoot = element.createShadowRoot ();
139
- shadowRoot
129
+ var shadowDom = element.createShadowRoot ()
140
130
..applyAuthorStyles = _component.applyAuthorStyles
141
131
..resetStyleInheritance = _component.resetStyleInheritance;
142
132
143
- List <async.Future > futures = < async .Future > [];
144
- TemplateLoader templateLoader = new TemplateLoader (shadowRoot, futures);
145
- shadowInjector = new ShadowDomComponentDirectiveInjector (
146
- injector, injector.appInjector, shadowScope, templateLoader, shadowRoot);
147
- shadowInjector.bindByKey (_ref.typeKey, _ref.factory , _ref.paramKeys,
148
- _ref.annotation.visibility);
149
- dom.Node firstViewNode = null ;
150
-
151
- // Load ngBase CSS
152
- if (_component.useNgBaseCss == true && baseCss.urls.isNotEmpty) {
153
- if (baseCss.styles == null ) {
154
- futures.add (async .Future
155
- .wait (baseCss.urls.map (_urlToStyle))
156
- .then ((List <dom.StyleElement > cssList) {
157
- baseCss.styles = cssList;
158
- _insertCss (cssList, shadowRoot, shadowRoot.firstChild);
159
- }));
160
- } else {
161
- _insertCss (baseCss.styles, shadowRoot, shadowRoot.firstChild);
162
- }
163
- }
133
+ var shadowScope = scope.createChild (new HashMap ()); // Isolate
164
134
165
- if (_styleElementsFuture != null ) {
166
- if (_styleElements == null ) {
167
- futures.add (_styleElementsFuture .then ((List <dom.StyleElement > styles) =>
168
- _insertCss (styles, shadowRoot, firstViewNode)));
169
- } else {
170
- _insertCss (_styleElements, shadowRoot);
171
- }
135
+ async .Future <Iterable <dom.StyleElement >> cssFuture;
136
+ if (_component.useNgBaseCss == true ) {
137
+ cssFuture = async .Future .wait ([async .Future .wait (baseCss.urls.map (_styleFuture)), _styleElementsFuture]).then ((twoLists) {
138
+ assert (twoLists.length == 2 );return []
139
+ ..addAll (twoLists[0 ])
140
+ ..addAll (twoLists[1 ]);
141
+ });
142
+ } else {
143
+ cssFuture = _styleElementsFuture;
172
144
}
173
145
146
+ ComponentDirectiveInjector shadowInjector;
174
147
175
- if (_shadowViewFactoryFuture != null ) {
176
- if (_shadowViewFactory == null ) {
177
- futures.add (_shadowViewFactoryFuture.then ((ViewFactory viewFactory) =>
178
- firstViewNode = _insertView (viewFactory, shadowRoot, shadowScope, shadowInjector)));
179
- } else {
180
- _insertView (_shadowViewFactory, shadowRoot, shadowScope, shadowInjector);
148
+ TemplateLoader templateLoader = new TemplateLoader (cssFuture.then ((Iterable <dom.StyleElement > cssList) {
149
+ cssList.where ((styleElement) => styleElement != null ).forEach ((styleElement) {
150
+ shadowDom.append (styleElement.clone (true ));
151
+ });
152
+ if (_viewFuture != null ) {
153
+ return _viewFuture.then ((ViewFactory viewFactory) {
154
+ if (shadowScope.isAttached) {
155
+ shadowDom.nodes.addAll (viewFactory.call (shadowInjector.scope, shadowInjector).nodes);
156
+ }
157
+ return shadowDom;
158
+ });
181
159
}
182
- }
160
+ return shadowDom;
161
+ }));
162
+
163
+ var probe;
164
+ shadowInjector = new ShadowDomComponentDirectiveInjector (injector, injector.appInjector, shadowScope, templateLoader, shadowDom);
165
+ shadowInjector.bindByKey (_ref.typeKey, _ref.factory , _ref.paramKeys, _ref.annotation.visibility);
183
166
184
167
if (_componentFactory.config.elementProbeEnabled) {
185
- ElementProbe probe = _componentFactory.expando[shadowRoot ] = shadowInjector.elementProbe;
186
- shadowScope.on (ScopeEvent .DESTROY ).listen ((ScopeEvent ) => _componentFactory.expando[shadowRoot ] = null );
168
+ probe = _componentFactory.expando[shadowDom ] = shadowInjector.elementProbe;
169
+ shadowScope.on (ScopeEvent .DESTROY ).listen ((ScopeEvent ) => _componentFactory.expando[shadowDom ] = null );
187
170
}
188
171
189
172
var controller = shadowInjector.getByKey (_ref.typeKey);
@@ -197,36 +180,6 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
197
180
}
198
181
};
199
182
}
200
-
201
- _insertCss (List <dom.StyleElement > cssList,
202
- dom.ShadowRoot shadowRoot,
203
- [dom.Node insertBefore = null ]) {
204
- var s = traceEnter (View_styles );
205
- for (int i = 0 ; i < cssList.length; i++ ) {
206
- var styleElement = cssList[i];
207
- if (styleElement != null ) {
208
- shadowRoot.insertBefore (styleElement.clone (true ), insertBefore);
209
- }
210
- }
211
- traceLeave (s);
212
- }
213
-
214
- dom.Node _insertView (ViewFactory viewFactory,
215
- dom.ShadowRoot shadowRoot,
216
- Scope shadowScope,
217
- ShadowDomComponentDirectiveInjector shadowInjector) {
218
- dom.Node first = null ;
219
- if (shadowScope.isAttached) {
220
- View shadowView = viewFactory.call (shadowScope, shadowInjector);
221
- List <dom.Node > shadowViewNodes = shadowView.nodes;
222
- for (var j = 0 ; j < shadowViewNodes.length; j++ ) {
223
- var node = shadowViewNodes[j];
224
- if (j == 0 ) first = node;
225
- shadowRoot.append (node);
226
- }
227
- }
228
- return first;
229
- }
230
183
}
231
184
232
185
class _ComponentAssetKey {
0 commit comments