feat(elements): remove attribute/input from config (#22413)
PR Close #22413
This commit is contained in:
parent
2e450f6fda
commit
688096b7a3
|
@ -52,15 +52,13 @@ export type WithProperties<P> = {
|
|||
/**
|
||||
* 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<P>(
|
|||
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);
|
||||
|
|
|
@ -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<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');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,6 @@ export declare abstract class NgElement extends HTMLElement {
|
|||
|
||||
/** @experimental */
|
||||
export interface NgElementConfig {
|
||||
attributeToPropertyInputs?: {
|
||||
[key: string]: string;
|
||||
};
|
||||
injector: Injector;
|
||||
strategyFactory?: NgElementStrategyFactory;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue