@@ -52,8 +52,6 @@ const int CONTENT_PORT_KEY_ID = 16;
52
52
const int EVENT_HANDLER_KEY_ID = 17 ;
53
53
const int KEEP_ME_LAST = 18 ;
54
54
55
- EventHandler eventHandler (DirectiveInjector di) => di._eventHandler;
56
-
57
55
class DirectiveInjector implements DirectiveBinder {
58
56
static bool _isInit = false ;
59
57
static initUID () {
@@ -102,8 +100,8 @@ class DirectiveInjector implements DirectiveBinder {
102
100
, KEEP_ME_LAST
103
101
];
104
102
105
- final DirectiveInjector _parent ;
106
- final Injector _appInjector ;
103
+ final DirectiveInjector parent ;
104
+ final Injector appInjector ;
107
105
final Node _node;
108
106
final NodeAttrs _nodeAttrs;
109
107
final Animate _animate;
@@ -142,8 +140,17 @@ class DirectiveInjector implements DirectiveBinder {
142
140
143
141
static Binding _temp_binding = new Binding ();
144
142
145
- DirectiveInjector (this ._parent, this ._appInjector, this ._node, this ._nodeAttrs, this ._eventHandler,
146
- this .scope, this ._animate);
143
+ DirectiveInjector (parent, appInjector, this ._node, this ._nodeAttrs, this ._eventHandler,
144
+ this .scope, this ._animate)
145
+ : appInjector = appInjector,
146
+ parent = parent == null ? new DefaultDirectiveInjector (appInjector) : parent;
147
+
148
+ DirectiveInjector ._default (this .parent, this .appInjector)
149
+ : _node = null ,
150
+ _nodeAttrs = null ,
151
+ _eventHandler = null ,
152
+ scope = null ,
153
+ _animate = null ;
147
154
148
155
bind (key, {dynamic toValue: DEFAULT_VALUE ,
149
156
Function toFactory: DEFAULT_VALUE ,
@@ -183,17 +190,12 @@ class DirectiveInjector implements DirectiveBinder {
183
190
else { throw 'Maximum number of directives per element reached.' ; }
184
191
}
185
192
186
- // Get a key from the directive injector chain. When it is exhausted, get from
187
- // the current application injector chain.
188
193
Object get (Type type) => getByKey (new Key (type));
189
194
190
- // Same behavior as get but skips the current injector.
191
- Object parentGet (Type type) => parentGetByKey (new Key (type));
192
-
193
195
Object getByKey (Key key) {
194
196
var oldTag = _TAG_GET .makeCurrent ();
195
197
try {
196
- return _getByKey (key, _appInjector );
198
+ return _getByKey (key);
197
199
} on ResolvingError catch (e, s) {
198
200
e.appendKey (key);
199
201
rethrow ;
@@ -202,15 +204,7 @@ class DirectiveInjector implements DirectiveBinder {
202
204
}
203
205
}
204
206
205
- Object parentGetByKey (Key key) {
206
- if (_parent == null ) {
207
- return _appInjector.getByKey (key);
208
- } else {
209
- return _parent._getByKey (key, _appInjector);
210
- }
211
- }
212
-
213
- Object _getByKey (Key key, Injector appInjector) {
207
+ Object _getByKey (Key key) {
214
208
int uid = key.uid;
215
209
if (uid == null || uid == UNDEFINED_ID ) return appInjector.getByKey (key);
216
210
bool isDirective = uid < 0 ;
@@ -230,10 +224,8 @@ class DirectiveInjector implements DirectiveBinder {
230
224
if (_key8 == null ) break ; if (identical (_key8, k)) return _obj8 == null ? _obj8 = _new (_pKeys8, _factory8) : _obj8;
231
225
if (_key9 == null ) break ; if (identical (_key9, k)) return _obj9 == null ? _obj9 = _new (_pKeys9, _factory9) : _obj9;
232
226
} while (false );
233
- var parent = this ._parent;
234
- if (parent == null ) return i.getByKey (k);
235
227
switch (visType) {
236
- case VISIBILITY_LOCAL : return i .getByKey (k);
228
+ case VISIBILITY_LOCAL : return appInjector .getByKey (k);
237
229
case VISIBILITY_DIRECT_CHILD : return parent._getDirectiveByKey (k, VISIBILITY_LOCAL , i);
238
230
case VISIBILITY_CHILDREN : return parent._getDirectiveByKey (k, VISIBILITY_CHILDREN , i);
239
231
// SHADOW
@@ -242,7 +234,6 @@ class DirectiveInjector implements DirectiveBinder {
242
234
case VISIBILITY_COMPONENT_CHILDREN : return parent._getDirectiveByKey (k, VISIBILITY_CHILDREN , i);
243
235
default : throw null ;
244
236
}
245
-
246
237
}
247
238
248
239
List get directives {
@@ -262,7 +253,7 @@ class DirectiveInjector implements DirectiveBinder {
262
253
263
254
Object _getById (int keyId) {
264
255
switch (keyId) {
265
- case INJECTOR_KEY_ID : return _appInjector ;
256
+ case INJECTOR_KEY_ID : return appInjector ;
266
257
case DIRECTIVE_INJECTOR_KEY_ID : return this ;
267
258
case NODE_KEY_ID : return _node;
268
259
case ELEMENT_KEY_ID : return _node;
@@ -272,8 +263,7 @@ class DirectiveInjector implements DirectiveBinder {
272
263
case ELEMENT_PROBE_KEY_ID : return elementProbe;
273
264
case NG_ELEMENT_KEY_ID : return ngElement;
274
265
case EVENT_HANDLER_KEY_ID : return _eventHandler;
275
- case CONTENT_PORT_KEY_ID :
276
- return _parent == null ? null : _parent._getById (keyId);
266
+ case CONTENT_PORT_KEY_ID : return parent._getById (keyId);
277
267
default : new NoProviderError (_KEYS [keyId]);
278
268
}
279
269
}
@@ -282,30 +272,29 @@ class DirectiveInjector implements DirectiveBinder {
282
272
var oldTag = _TAG_GET .makeCurrent ();
283
273
int size = paramKeys.length;
284
274
var obj;
285
- var appInjector = this ._appInjector;
286
275
if (size > 15 ) {
287
276
var params = new List (paramKeys.length);
288
277
for (var i = 0 ; i < paramKeys.length; i++ ) {
289
- params[i] = _getByKey (paramKeys[i], appInjector );
278
+ params[i] = _getByKey (paramKeys[i]);
290
279
}
291
280
_TAG_INSTANTIATE .makeCurrent ();
292
281
obj = Function .apply (fn, params);
293
282
} else {
294
- var a01 = size >= 01 ? _getByKey (paramKeys[00 ], appInjector ) : null ;
295
- var a02 = size >= 02 ? _getByKey (paramKeys[01 ], appInjector ) : null ;
296
- var a03 = size >= 03 ? _getByKey (paramKeys[02 ], appInjector ) : null ;
297
- var a04 = size >= 04 ? _getByKey (paramKeys[03 ], appInjector ) : null ;
298
- var a05 = size >= 05 ? _getByKey (paramKeys[04 ], appInjector ) : null ;
299
- var a06 = size >= 06 ? _getByKey (paramKeys[05 ], appInjector ) : null ;
300
- var a07 = size >= 07 ? _getByKey (paramKeys[06 ], appInjector ) : null ;
301
- var a08 = size >= 08 ? _getByKey (paramKeys[07 ], appInjector ) : null ;
302
- var a09 = size >= 09 ? _getByKey (paramKeys[08 ], appInjector ) : null ;
303
- var a10 = size >= 10 ? _getByKey (paramKeys[09 ], appInjector ) : null ;
304
- var a11 = size >= 11 ? _getByKey (paramKeys[10 ], appInjector ) : null ;
305
- var a12 = size >= 12 ? _getByKey (paramKeys[11 ], appInjector ) : null ;
306
- var a13 = size >= 13 ? _getByKey (paramKeys[12 ], appInjector ) : null ;
307
- var a14 = size >= 14 ? _getByKey (paramKeys[13 ], appInjector ) : null ;
308
- var a15 = size >= 15 ? _getByKey (paramKeys[14 ], appInjector ) : null ;
283
+ var a01 = size >= 01 ? _getByKey (paramKeys[00 ]) : null ;
284
+ var a02 = size >= 02 ? _getByKey (paramKeys[01 ]) : null ;
285
+ var a03 = size >= 03 ? _getByKey (paramKeys[02 ]) : null ;
286
+ var a04 = size >= 04 ? _getByKey (paramKeys[03 ]) : null ;
287
+ var a05 = size >= 05 ? _getByKey (paramKeys[04 ]) : null ;
288
+ var a06 = size >= 06 ? _getByKey (paramKeys[05 ]) : null ;
289
+ var a07 = size >= 07 ? _getByKey (paramKeys[06 ]) : null ;
290
+ var a08 = size >= 08 ? _getByKey (paramKeys[07 ]) : null ;
291
+ var a09 = size >= 09 ? _getByKey (paramKeys[08 ]) : null ;
292
+ var a10 = size >= 10 ? _getByKey (paramKeys[09 ]) : null ;
293
+ var a11 = size >= 11 ? _getByKey (paramKeys[10 ]) : null ;
294
+ var a12 = size >= 12 ? _getByKey (paramKeys[11 ]) : null ;
295
+ var a13 = size >= 13 ? _getByKey (paramKeys[12 ]) : null ;
296
+ var a14 = size >= 14 ? _getByKey (paramKeys[13 ]) : null ;
297
+ var a15 = size >= 15 ? _getByKey (paramKeys[14 ]) : null ;
309
298
_TAG_INSTANTIATE .makeCurrent ();
310
299
switch (size) {
311
300
case 00 : obj = fn (); break ;
@@ -333,7 +322,7 @@ class DirectiveInjector implements DirectiveBinder {
333
322
334
323
ElementProbe get elementProbe {
335
324
if (_elementProbe == null ) {
336
- ElementProbe parentProbe = _parent == null ? null : _parent.elementProbe ;
325
+ ElementProbe parentProbe = parent is DirectiveInjector ? parent.elementProbe : null ;
337
326
_elementProbe = new ElementProbe (parentProbe, _node, this , scope);
338
327
}
339
328
return _elementProbe;
@@ -364,7 +353,7 @@ class TemplateDirectiveInjector extends DirectiveInjector {
364
353
case VIEW_PORT_KEY_ID : return ((_viewPort) == null ) ?
365
354
_viewPort = new ViewPort (this , scope, _node, _animate) : _viewPort;
366
355
case BOUND_VIEW_FACTORY_KEY_ID : return (_boundViewFactory == null ) ?
367
- _boundViewFactory = _viewFactory.bind (this ._parent ) : _boundViewFactory;
356
+ _boundViewFactory = _viewFactory.bind (this .parent ) : _boundViewFactory;
368
357
default : return super ._getById (keyId);
369
358
}
370
359
}
@@ -420,9 +409,27 @@ class ShadowDomComponentDirectiveInjector extends ComponentDirectiveInjector {
420
409
421
410
ElementProbe get elementProbe {
422
411
if (_elementProbe == null ) {
423
- ElementProbe parentProbe = _parent == null ? null : _parent.elementProbe;
412
+ ElementProbe parentProbe =
413
+ parent is DirectiveInjector ? parent.elementProbe : parent.getByKey (ELEMENT_PROBE_KEY );
424
414
_elementProbe = new ElementProbe (parentProbe, _shadowRoot, this , scope);
425
415
}
426
416
return _elementProbe;
427
417
}
428
418
}
419
+
420
+ @Injectable ()
421
+ class DefaultDirectiveInjector extends DirectiveInjector {
422
+ DefaultDirectiveInjector (Injector appInjector): super ._default (null , appInjector);
423
+ DefaultDirectiveInjector .newAppInjector (DirectiveInjector parent, Injector appInjector)
424
+ : super ._default (parent, appInjector);
425
+
426
+ Object getByKey (Key key) => appInjector.getByKey (key);
427
+ _getDirectiveByKey (Key key, int visType, Injector i) =>
428
+ parent == null ? i.getByKey (key) : parent._getDirectiveByKey (key, visType, i);
429
+ _getById (int keyId) {
430
+ switch (keyId) {
431
+ case CONTENT_PORT_KEY_ID : return null ;
432
+ default : throw new NoProviderError (DirectiveInjector ._KEYS [keyId]);
433
+ }
434
+ }
435
+ }
0 commit comments