feat(elements): remove attribute/input from config (#22413)

PR Close #22413
This commit is contained in:
Andrew Seguin 2018-03-15 17:18:40 -07:00 committed by Miško Hevery
parent 2e450f6fda
commit 688096b7a3
3 changed files with 2 additions and 41 deletions

View File

@ -52,15 +52,13 @@ export type WithProperties<P> = {
/** /**
* Initialization configuration for the NgElementConstructor which contains the injector to be used * 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 * 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 * provide a custom strategy factory to be used instead of the default.
* of attribute names to component inputs.
* *
* @experimental * @experimental
*/ */
export interface NgElementConfig { export interface NgElementConfig {
injector: Injector; injector: Injector;
strategyFactory?: NgElementStrategyFactory; strategyFactory?: NgElementStrategyFactory;
attributeToPropertyInputs?: {[key: string]: string};
} }
/** /**
@ -84,8 +82,7 @@ export function createCustomElement<P>(
const strategyFactory = const strategyFactory =
config.strategyFactory || new ComponentNgElementStrategyFactory(component, config.injector); config.strategyFactory || new ComponentNgElementStrategyFactory(component, config.injector);
const attributeToPropertyInputs = const attributeToPropertyInputs = getDefaultAttributeToPropertyInputs(inputs);
config.attributeToPropertyInputs || getDefaultAttributeToPropertyInputs(inputs);
class NgElementImpl extends NgElement { class NgElementImpl extends NgElement {
static readonly observedAttributes = Object.keys(attributeToPropertyInputs); static readonly observedAttributes = Object.keys(attributeToPropertyInputs);

View File

@ -93,39 +93,6 @@ if (typeof customElements !== 'undefined') {
expect(strategy.inputs.get('fooFoo')).toBe('foo-foo-value'); expect(strategy.inputs.get('fooFoo')).toBe('foo-foo-value');
expect(strategy.inputs.get('barBar')).toBe('barBar-value'); expect(strategy.inputs.get('barBar')).toBe('barBar-value');
}); });
describe('with different attribute strategy', () => {
let NgElementCtorWithChangedAttr: NgElementConstructor<WithFooBar>;
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');
});
});
}); });
} }

View File

@ -12,9 +12,6 @@ export declare abstract class NgElement extends HTMLElement {
/** @experimental */ /** @experimental */
export interface NgElementConfig { export interface NgElementConfig {
attributeToPropertyInputs?: {
[key: string]: string;
};
injector: Injector; injector: Injector;
strategyFactory?: NgElementStrategyFactory; strategyFactory?: NgElementStrategyFactory;
} }