element-vir
Version:
Heroic. Reactive. Declarative. Type safe. Web components without compromise.
27 lines (26 loc) • 880 B
JavaScript
import { getObjectTypedKeys } from '@augment-vir/common';
/**
* This is used to create the parameters passed to the `render`, `init`, and `cleanup` element
* definition methods whenever they are called.
*
* @category Internal
*/
export function createRenderParams({ element, eventsMap, cssVars, slotNamesMap, }) {
function updateState(newStatePartial) {
getObjectTypedKeys(newStatePartial).forEach((stateKey) => {
const newValue = newStatePartial[stateKey];
element.instanceState[stateKey] = newValue;
});
}
const renderParams = {
cssVars,
slotNames: slotNamesMap,
dispatch: (event) => element.dispatchEvent(event),
events: eventsMap,
host: element,
inputs: element.instanceInputs,
state: element.instanceState,
updateState,
};
return renderParams;
}