From 688096b7a3bad86613ca00f01ef5550200a481cc Mon Sep 17 00:00:00 2001 From: Andrew Seguin Date: Thu, 15 Mar 2018 17:18:40 -0700 Subject: [PATCH] feat(elements): remove attribute/input from config (#22413) PR Close #22413 --- .../elements/src/create-custom-element.ts | 7 ++-- .../test/create-custom-element_spec.ts | 33 ------------------- tools/public_api_guard/elements/elements.d.ts | 3 -- 3 files changed, 2 insertions(+), 41 deletions(-) diff --git a/packages/elements/src/create-custom-element.ts b/packages/elements/src/create-custom-element.ts index 1e03bbec3f..4797d2136c 100644 --- a/packages/elements/src/create-custom-element.ts +++ b/packages/elements/src/create-custom-element.ts @@ -52,15 +52,13 @@ export type WithProperties

= { /** * Initialization configuration for the NgElementConstructor which contains the injector to be used * for retrieving the component's factory as well as the default context for the component. May - * provide a custom strategy factory to be used instead of the default. May provide a custom mapping - * of attribute names to component inputs. + * provide a custom strategy factory to be used instead of the default. * * @experimental */ export interface NgElementConfig { injector: Injector; strategyFactory?: NgElementStrategyFactory; - attributeToPropertyInputs?: {[key: string]: string}; } /** @@ -84,8 +82,7 @@ export function createCustomElement

( const strategyFactory = config.strategyFactory || new ComponentNgElementStrategyFactory(component, config.injector); - const attributeToPropertyInputs = - config.attributeToPropertyInputs || getDefaultAttributeToPropertyInputs(inputs); + const attributeToPropertyInputs = getDefaultAttributeToPropertyInputs(inputs); class NgElementImpl extends NgElement { static readonly observedAttributes = Object.keys(attributeToPropertyInputs); diff --git a/packages/elements/test/create-custom-element_spec.ts b/packages/elements/test/create-custom-element_spec.ts index b6cdb4ee98..43f643bbd8 100644 --- a/packages/elements/test/create-custom-element_spec.ts +++ b/packages/elements/test/create-custom-element_spec.ts @@ -93,39 +93,6 @@ if (typeof customElements !== 'undefined') { expect(strategy.inputs.get('fooFoo')).toBe('foo-foo-value'); expect(strategy.inputs.get('barBar')).toBe('barBar-value'); }); - - describe('with different attribute strategy', () => { - let NgElementCtorWithChangedAttr: NgElementConstructor; - let element: HTMLElement; - - beforeAll(() => { - strategyFactory = new TestStrategyFactory(); - strategy = strategyFactory.testStrategy; - NgElementCtorWithChangedAttr = createCustomElement(TestComponent, { - injector, - strategyFactory, - attributeToPropertyInputs: {'attr-1': 'fooFoo', 'attr-2': 'barbar'} - }); - - customElements.define('test-element-with-changed-attributes', NgElementCtorWithChangedAttr); - }); - - beforeEach(() => { element = new NgElementCtorWithChangedAttr(injector); }); - - it('should affect which attributes are watched', () => { - expect(NgElementCtorWithChangedAttr.observedAttributes).toEqual(['attr-1', 'attr-2']); - }); - - it('should send attribute values as inputs when connected', () => { - const element = new NgElementCtorWithChangedAttr(injector); - element.setAttribute('attr-1', 'value-1'); - element.setAttribute('attr-2', 'value-2'); - element.connectedCallback(); - - expect(strategy.getInputValue('fooFoo')).toBe('value-1'); - expect(strategy.getInputValue('barbar')).toBe('value-2'); - }); - }); }); } diff --git a/tools/public_api_guard/elements/elements.d.ts b/tools/public_api_guard/elements/elements.d.ts index 748c2d3175..4902a453b8 100644 --- a/tools/public_api_guard/elements/elements.d.ts +++ b/tools/public_api_guard/elements/elements.d.ts @@ -12,9 +12,6 @@ export declare abstract class NgElement extends HTMLElement { /** @experimental */ export interface NgElementConfig { - attributeToPropertyInputs?: { - [key: string]: string; - }; injector: Injector; strategyFactory?: NgElementStrategyFactory; }