@@ -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,73 +76,93 @@ 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
+
130
+ if (_component.useNgBaseCss && baseCss.urls.isNotEmpty) {
131
+ if (baseCss.styles == null ) {
132
+ final f = _componentFactory.cssLoader (_tag, baseCss.urls).then ((cssList) {
133
+ baseCss.styles = cssList;
134
+ shadowBoundary.insertStyleElements (cssList);
135
+ });
136
+ futures.add (f);
137
+ } else {
138
+ shadowBoundary.insertStyleElements (baseCss.styles);
139
+ }
140
+ }
138
141
142
+ if (_styleElementsFuture != null ) {
143
+ if (_styleElements == null ) {
144
+ final f = _styleElementsFuture.then (shadowBoundary.insertStyleElements);
145
+ futures.add (f);
146
+ } else {
147
+ shadowBoundary.insertStyleElements (_styleElements);
148
+ }
149
+ }
139
150
140
- shadowInjector.bindByKey (_ref.typeKey, _ref.factory , _ref.paramKeys, _ref.annotation.visibility);
151
+ if (_shadowViewFactoryFuture != null ) {
152
+ if (_shadowViewFactory == null ) {
153
+ futures.add (_shadowViewFactoryFuture.then ((ViewFactory viewFactory) =>
154
+ _insertView (viewFactory, shadowRoot, shadowScope, shadowInjector)));
155
+ } else {
156
+ _insertView (_shadowViewFactory, shadowRoot, shadowScope, shadowInjector);
157
+ }
158
+ }
141
159
142
160
if (_componentFactory.config.elementProbeEnabled) {
143
- probe = _componentFactory.expando[shadowDom ] = shadowInjector.elementProbe;
144
- shadowScope.on (ScopeEvent .DESTROY ).listen ((ScopeEvent ) => _componentFactory.expando[shadowDom ] = null );
161
+ ElementProbe probe = _componentFactory.expando[shadowRoot ] = shadowInjector.elementProbe;
162
+ shadowScope.on (ScopeEvent .DESTROY ).listen ((ScopeEvent ) => _componentFactory.expando[shadowRoot ] = null );
145
163
}
146
164
165
+ shadowInjector.bindByKey (_ref.typeKey, _ref.factory , _ref.paramKeys, _ref.annotation.visibility);
147
166
var controller = shadowInjector.getByKey (_ref.typeKey);
148
167
BoundComponentFactory ._setupOnShadowDomAttach (controller, templateLoader, shadowScope);
149
168
shadowScope.context[_component.publishAs] = controller;
@@ -154,6 +173,16 @@ class BoundShadowDomComponentFactory implements BoundComponentFactory {
154
173
}
155
174
};
156
175
}
176
+
177
+ dom.Node _insertView (ViewFactory viewFactory,
178
+ dom.ShadowRoot shadowRoot,
179
+ Scope shadowScope,
180
+ ComponentDirectiveInjector shadowInjector) {
181
+ if (shadowScope.isAttached) {
182
+ shadowRoot.nodes.addAll (
183
+ viewFactory.call (shadowInjector.scope, shadowInjector).nodes);
184
+ }
185
+ }
157
186
}
158
187
159
188
@Injectable ()
0 commit comments