element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
35 lines (34 loc) • 1.3 kB
JavaScript
import { directive, Directive, noChange, } from '../../lit-exports/all-lit-exports.js';
import { assignInputs } from '../properties/assign-inputs.js';
import { extractElement } from './directive-helpers.js';
/**
* Assign an object matching an element's inputs to its inputs.
*
* @deprecated Instead of using this directive, assign inputs directly on the element's
* interpolation opening tag interpolation.
* @example Html`<${MyElement} ${assign(MyElement, {value: 1})}>...` should be
* html`<${MyElement.assign({value: 1})}>...`
*/
export function assign(declarativeElementOrInputs, inputsObject) {
/**
* The directive generics (in listenDirective) are not strong enough to maintain their values.
* Thus, the directive call is wrapped in this function.
*/
if (inputsObject) {
return assignDirective(declarativeElementOrInputs, inputsObject);
}
else {
return assignDirective(undefined, declarativeElementOrInputs);
}
}
const assignDirective = directive(class extends Directive {
element;
constructor(partInfo) {
super(partInfo);
this.element = extractElement(partInfo, 'assign');
}
render(elementDefinition, inputsObject) {
assignInputs(this.element, inputsObject);
return noChange;
}
});