From d9fc724e56e99b26192e41eaef46607760f4ac2a Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Wed, 19 Mar 2014 15:50:19 -0700 Subject: [PATCH] fix(component): revert regression of injecting Element/Node into Component --- lib/core_dom/event_handler.dart | 8 ++++++++ lib/core_dom/view_factory.dart | 4 +--- test/core_dom/compiler_spec.dart | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/core_dom/event_handler.dart b/lib/core_dom/event_handler.dart index 113212c62..040e60731 100644 --- a/lib/core_dom/event_handler.dart +++ b/lib/core_dom/event_handler.dart @@ -100,3 +100,11 @@ class EventHandler { return part.replaceAll("-", ""); } } + +@NgInjectableService() +class _ShadowRootEventHandler extends EventHandler { + _ShadowRootEventHandler(dom.ShadowRoot shadowRoot, + Expando expando, + ExceptionHandler exceptionHandler) + : super(shadowRoot, expando, exceptionHandler); +} diff --git a/lib/core_dom/view_factory.dart b/lib/core_dom/view_factory.dart index a1bf4a01c..91271a688 100644 --- a/lib/core_dom/view_factory.dart +++ b/lib/core_dom/view_factory.dart @@ -231,12 +231,10 @@ class _ComponentFactory implements Function { var shadowModule = new Module() ..type(type) ..type(NgElement) - ..type(EventHandler) + ..type(EventHandler, implementedBy: _ShadowRootEventHandler) ..value(Scope, shadowScope) ..value(TemplateLoader, templateLoader) ..value(dom.ShadowRoot, shadowDom) - ..value(dom.Element, null) - ..value(dom.Node, shadowDom) ..factory(ElementProbe, (_) => probe); shadowInjector = injector.createChild([shadowModule], name: _SHADOW); probe = _expando[shadowDom] = new ElementProbe( diff --git a/test/core_dom/compiler_spec.dart b/test/core_dom/compiler_spec.dart index 79e9ae599..28433aada 100644 --- a/test/core_dom/compiler_spec.dart +++ b/test/core_dom/compiler_spec.dart @@ -217,6 +217,7 @@ void main() { ..type(SimpleAttachComponent) ..type(SimpleComponent) ..type(ExprAttrComponent) + ..type(LogElementComponent) ..type(SayHelloFilter); }); @@ -521,6 +522,13 @@ void main() { expect(logger).toEqual(['SimpleAttachComponent']); })); + + it('should inject compenent element as the dom.Element', async((Logger log, TestBed _, MockHttpBackend backend) { + backend.whenGET('foo.html').respond('
WORKED
'); + _.compile(''); + Element element = _.rootElement; + expect(log).toEqual([element, element, element.shadowRoot]); + })); }); describe('invalid components', () { @@ -941,3 +949,15 @@ class SimpleAttachComponent implements NgAttachAware, NgShadowRootAware { attach() => logger('attach'); onShadowRoot(_) => logger('onShadowRoot'); } + +@NgComponent( + selector: 'log-element', + templateUrl: 'foo.html') +class LogElementComponent{ + LogElementComponent(Logger logger, Element element, Node node, + ShadowRoot shadowRoot) { + logger(element); + logger(node); + logger(shadowRoot); + } +}