@@ -11,10 +11,9 @@ abstract class BoundComponentFactory {
11
11
List <Key > get callArgs;
12
12
Function call (dom.Element element);
13
13
14
- static async .Future <ViewFactory > _viewFuture (
14
+ static async .Future <ViewFactory > _viewFactoryFuture (
15
15
Component component, ViewCache viewCache, DirectiveMap directives,
16
16
TypeToUriMapper uriMapper, ResourceUrlResolver resourceResolver, Type type) {
17
-
18
17
if (component.template != null ) {
19
18
// TODO(chirayu): Replace this line with
20
19
// var baseUri = uriMapper.uriForType(type);
@@ -77,71 +76,95 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
77
76
Component get _component => _ref.annotation as Component ;
78
77
79
78
String _tag;
80
- async .Future <Iterable <dom.StyleElement >> _styleElementsFuture;
81
- async .Future <ViewFactory > _viewFuture;
79
+ async .Future <List <dom.StyleElement >> _styleElementsFuture;
80
+ List <dom.StyleElement > _styleElements;
81
+ async .Future <ViewFactory > _shadowViewFactoryFuture;
82
+ ViewFactory _shadowViewFactory;
82
83
83
84
BoundShadowDomComponentFactory (this ._componentFactory, this ._ref,
84
85
DirectiveMap directives, this ._injector) {
85
86
_tag = _ref.annotation.selector.toLowerCase ();
86
- _styleElementsFuture = _componentFactory.cssLoader (_tag, _component.cssUrls, type: _ref.type);
87
+ _styleElementsFuture = _componentFactory.cssLoader (_tag, _component.cssUrls, type: _ref.type)
88
+ .then ((styleElements) => _styleElements = styleElements);
87
89
88
90
final viewCache = new ShimmingViewCache (_componentFactory.viewCache,
89
91
_tag, _componentFactory.platformShim);
90
- _viewFuture = BoundComponentFactory ._viewFuture (_component, viewCache, directives,
91
- _componentFactory.uriMapper, _componentFactory.resourceResolver, _ref.type);
92
+
93
+ _shadowViewFactoryFuture = BoundComponentFactory ._viewFactoryFuture (_component,
94
+ viewCache, directives, _componentFactory.uriMapper,
95
+ _componentFactory.resourceResolver, _ref.type);
96
+
97
+ if (_shadowViewFactoryFuture != null ) {
98
+ _shadowViewFactoryFuture.then ((viewFactory) => _shadowViewFactory = viewFactory);
99
+ }
92
100
}
93
101
94
102
List <Key > get callArgs => _CALL_ARGS ;
95
103
static final _CALL_ARGS = [DIRECTIVE_INJECTOR_KEY , SCOPE_KEY , VIEW_KEY , NG_BASE_CSS_KEY ,
96
104
SHADOW_BOUNDARY_KEY ];
105
+
97
106
Function call (dom.Element element) {
98
107
return (DirectiveInjector injector, Scope scope, View view, NgBaseCss baseCss,
99
108
ShadowBoundary parentShadowBoundary) {
100
109
var s = traceEnter (View_createComponent );
101
110
try {
102
- var shadowDom = element.createShadowRoot ();
111
+ var shadowRoot = element.createShadowRoot ();
103
112
104
113
var shadowBoundary;
105
114
if (_componentFactory.platformShim.shimRequired) {
106
115
shadowBoundary = parentShadowBoundary;
107
116
} else {
108
- shadowBoundary = new ShadowRootBoundary (shadowDom );
117
+ shadowBoundary = new ShadowRootBoundary (shadowRoot );
109
118
}
110
119
111
- //_styleFuture(cssUrl, resolveUri: false)
112
120
var shadowScope = scope.createChild (new HashMap ()); // Isolate
113
- ComponentDirectiveInjector shadowInjector;
114
-
115
- final baseUrls = (_component.useNgBaseCss) ? baseCss.urls : [];
116
- final baseUrlsFuture = _componentFactory.cssLoader (_tag, baseUrls);
117
- final cssFuture = mergeFutures (baseUrlsFuture, _styleElementsFuture);
118
-
119
- async .Future <dom.Node > initShadowDom (_) {
120
- if (_viewFuture == null ) return new async .Future .value (shadowDom);
121
- return _viewFuture.then ((ViewFactory viewFactory) {
122
- if (shadowScope.isAttached) {
123
- shadowDom.nodes.addAll (
124
- viewFactory.call (shadowInjector.scope, shadowInjector).nodes);
125
- }
126
- return shadowDom;
127
- });
128
- }
129
-
130
- TemplateLoader templateLoader = new TemplateLoader (
131
- cssFuture.then (shadowBoundary.insertStyleElements).then (initShadowDom));
121
+ List <async.Future > futures = < async .Future > [];
122
+ TemplateLoader templateLoader = new TemplateLoader (shadowRoot, futures);
132
123
133
124
var probe;
134
125
var eventHandler = new ShadowRootEventHandler (
135
- shadowDom, injector.getByKey (EXPANDO_KEY ), injector.getByKey (EXCEPTION_HANDLER_KEY ));
136
- shadowInjector = new ComponentDirectiveInjector (injector, _injector, eventHandler, shadowScope,
137
- templateLoader, shadowDom, null , view, shadowBoundary);
126
+ shadowRoot, injector.getByKey (EXPANDO_KEY ), injector.getByKey (EXCEPTION_HANDLER_KEY ));
127
+ final shadowInjector = new ComponentDirectiveInjector (injector, _injector, eventHandler, shadowScope,
128
+ templateLoader, shadowRoot, null , view, shadowBoundary);
129
+ shadowInjector.bindByKey (_ref.typeKey, _ref.factory , _ref.paramKeys, _ref.annotation.visibility);
138
130
131
+ if (_component.useNgBaseCss && baseCss.urls.isNotEmpty) {
132
+ if (baseCss.styles == null ) {
133
+ final f = _componentFactory.cssLoader (_tag, baseCss.urls).then ((cssList) {
134
+ baseCss.styles = cssList;
135
+ shadowBoundary.insertStyleElements (cssList, prepend: true );
136
+ });
137
+ futures.add (f);
138
+ } else {
139
+ shadowBoundary.insertStyleElements (baseCss.styles, prepend: true );
140
+ }
141
+ }
139
142
140
- shadowInjector.bindByKey (_ref.typeKey, _ref.factory , _ref.paramKeys, _ref.annotation.visibility);
143
+ if (_styleElementsFuture != null ) {
144
+ if (_styleElements == null ) {
145
+ final f = _styleElementsFuture.then (shadowBoundary.insertStyleElements);
146
+ futures.add (f);
147
+ } else {
148
+ shadowBoundary.insertStyleElements (_styleElements);
149
+ }
150
+ }
151
+
152
+ if (_shadowViewFactoryFuture != null ) {
153
+ if (_shadowViewFactory == null ) {
154
+ final f = _shadowViewFactoryFuture.then ((ViewFactory viewFactory) =>
155
+ _insertView (viewFactory, shadowRoot, shadowScope, shadowInjector));
156
+ futures.add (f);
157
+ } else {
158
+ final f = new Future .microtask (() {
159
+ _insertView (_shadowViewFactory, shadowRoot, shadowScope, shadowInjector);
160
+ });
161
+ futures.add (f);
162
+ }
163
+ }
141
164
142
165
if (_componentFactory.config.elementProbeEnabled) {
143
- probe = _componentFactory.expando[shadowDom ] = shadowInjector.elementProbe;
144
- shadowScope.on (ScopeEvent .DESTROY ).listen ((ScopeEvent ) => _componentFactory.expando[shadowDom ] = null );
166
+ ElementProbe probe = _componentFactory.expando[shadowRoot ] = shadowInjector.elementProbe;
167
+ shadowScope.on (ScopeEvent .DESTROY ).listen ((ScopeEvent ) => _componentFactory.expando[shadowRoot ] = null );
145
168
}
146
169
147
170
var controller = shadowInjector.getByKey (_ref.typeKey);
@@ -155,6 +178,16 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
155
178
}
156
179
};
157
180
}
181
+
182
+ dom.Node _insertView (ViewFactory viewFactory,
183
+ dom.ShadowRoot shadowRoot,
184
+ Scope shadowScope,
185
+ ComponentDirectiveInjector shadowInjector) {
186
+ if (shadowScope.isAttached) {
187
+ shadowRoot.nodes.addAll (
188
+ viewFactory.call (shadowInjector.scope, shadowInjector).nodes);
189
+ }
190
+ }
158
191
}
159
192
160
193
@Injectable ()
0 commit comments