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