From 779ccb800d6db85100418c3e4a89a6003048bcab Mon Sep 17 00:00:00 2001 From: James deBoer Date: Wed, 2 Apr 2014 13:03:14 -0700 Subject: [PATCH] feat(directives): Add deprecated warning to applyAuthorStyle, resetStyleInheritance Closes #838 For #801 --- lib/core/annotation.dart | 33 +++++++- test/core/core_directive_spec.dart | 4 - test/core_dom/shadow_root_options_spec.dart | 88 --------------------- 3 files changed, 29 insertions(+), 96 deletions(-) delete mode 100644 test/core_dom/shadow_root_options_spec.dart diff --git a/lib/core/annotation.dart b/lib/core/annotation.dart index 78b8388e5..f97d84d5b 100644 --- a/lib/core/annotation.dart +++ b/lib/core/annotation.dart @@ -188,6 +188,9 @@ abstract class NgAnnotation { } +bool _applyAuthorStylesDeprecationWarningPrinted = false; +bool _resetStyleInheritanceDeprecationWarningPrinted = false; + /** * Meta-data marker placed on a class which should act as a controller for the * component. Angular components are a light-weight version of web-components. @@ -224,14 +227,34 @@ class NgComponent extends NgAnnotation { /** * Set the shadow root applyAuthorStyles property. See shadow-DOM * documentation for further details. + * + * This feature will be removed in Chrome 35. */ - final bool applyAuthorStyles; + @deprecated + bool get applyAuthorStyles { + if (!_applyAuthorStylesDeprecationWarningPrinted && _applyAuthorStyles == true) { + print("WARNING applyAuthorStyles is deprecated in component $selector"); + _applyAuthorStylesDeprecationWarningPrinted = true; + } + return _applyAuthorStyles; + } + final bool _applyAuthorStyles; /** * Set the shadow root resetStyleInheritance property. See shadow-DOM * documentation for further details. + * + * This feature will be removed in Chrome 35. */ - final bool resetStyleInheritance; + @deprecated + bool get resetStyleInheritance { + if (!_resetStyleInheritanceDeprecationWarningPrinted && _resetStyleInheritance == true) { + print("WARNING resetStyleInheritance is deprecated in component $selector"); + _resetStyleInheritanceDeprecationWarningPrinted = true; + } + return _resetStyleInheritance; + } + final bool _resetStyleInheritance; /** * An expression under which the component's controller instance will be @@ -244,8 +267,8 @@ class NgComponent extends NgAnnotation { this.template, this.templateUrl, cssUrl, - this.applyAuthorStyles, - this.resetStyleInheritance, + applyAuthorStyles, + resetStyleInheritance, this.publishAs, module, map, @@ -254,6 +277,8 @@ class NgComponent extends NgAnnotation { exportExpressions, exportExpressionAttrs}) : _cssUrls = cssUrl, + _applyAuthorStyles = applyAuthorStyles, + _resetStyleInheritance = resetStyleInheritance, super(selector: selector, children: NgAnnotation.COMPILE_CHILDREN, visibility: visibility, diff --git a/test/core/core_directive_spec.dart b/test/core/core_directive_spec.dart index 2e6168468..9f8159280 100644 --- a/test/core/core_directive_spec.dart +++ b/test/core/core_directive_spec.dart @@ -23,8 +23,6 @@ void main() { expect(annotation.template).toEqual('template'); expect(annotation.templateUrl).toEqual('templateUrl'); expect(annotation.cssUrls).toEqual(['cssUrls']); - expect(annotation.applyAuthorStyles).toEqual(true); - expect(annotation.resetStyleInheritance).toEqual(true); expect(annotation.publishAs).toEqual('ctrl'); expect(annotation.map).toEqual({ 'foo': '=>foo', @@ -83,8 +81,6 @@ class NullParser implements Parser { template: 'template', templateUrl: 'templateUrl', cssUrl: const ['cssUrls'], - applyAuthorStyles: true, - resetStyleInheritance: true, publishAs: 'ctrl', module: AnnotatedIoComponent.module, visibility: NgDirective.LOCAL_VISIBILITY, diff --git a/test/core_dom/shadow_root_options_spec.dart b/test/core_dom/shadow_root_options_spec.dart deleted file mode 100644 index 0a8770c38..000000000 --- a/test/core_dom/shadow_root_options_spec.dart +++ /dev/null @@ -1,88 +0,0 @@ -library shadow_root_options_spec; - -import '../_specs.dart'; - -@NgComponent( - selector: 'reset-style-inheritance', - template: '
Reset me foo
', - applyAuthorStyles: false, - resetStyleInheritance: true -) -class ResetStyleInheritanceComponent { - static var lastTemplateLoader; - ResetStyleInheritanceComponent(Element elt, TemplateLoader tl) { - lastTemplateLoader = tl.template; - } -} - -@NgComponent( - selector: 'apply-author-style', - template: '
Style me foo
', - applyAuthorStyles: true -) -class ApplyAuthorStyleComponent { - static var lastTemplateLoader; - ApplyAuthorStyleComponent(Element elt, TemplateLoader tl) { - lastTemplateLoader = tl.template; - } -} - -@NgComponent( - selector: 'default-options', - template: '
Style me foo
' -) -class DefaultOptionsComponent { - static var lastTemplateLoader; - DefaultOptionsComponent(Element elt, TemplateLoader tl) { - lastTemplateLoader = tl.template; - } -} - -main() { - describe('shadow dom options', () { - Compiler $compile; - DirectiveMap directives; - Injector injector; - Scope $rootScope; - - beforeEachModule((Module module) { - module - ..type(ApplyAuthorStyleComponent) - ..type(ResetStyleInheritanceComponent) - ..type(DefaultOptionsComponent); - return (Injector _injector) { - injector = _injector; - $compile = injector.get(Compiler); - $rootScope = injector.get(Scope); - directives = injector.get(DirectiveMap); - }; - }); - - it('should respect the apply-author-style option', async(() { - var element = $( - '' + - 'not included' + - 'not included'); - element.forEach((elt) { document.body.append(elt); }); // we need the computed style. - $compile(element, directives)(injector, element); - - microLeap(); - expect(element[1].shadowRoot.query('div').getComputedStyle().border).toContain('3px solid'); - // ""0px none"" is the default style. - expect(element[2].shadowRoot.query('div').getComputedStyle().border).toContain('0px none'); - })); - - it('should respect the reset-style-inheritance option', async(() { - var element = $( - '' + // font-size inherit's by default - 'not included' + - 'not included'); - element.forEach((elt) { document.body.append(elt); }); // we need the computed style. - $compile(element, directives)(injector, element); - - microLeap(); - expect(element[1].shadowRoot.query('div').getComputedStyle().fontSize).toEqual('16px'); - expect(element[2].shadowRoot.query('div').getComputedStyle().fontSize).toEqual('20px'); - })); - }); -}