@muban/muban
Version:
Writing components for server-rendered HTML
27 lines (26 loc) • 1.09 kB
JavaScript
import { convertSourceValue } from './convertSourceValue';
export function createAttributePropertySource() {
return () => ({
sourceName: 'attr',
hasProp: (propInfo) => Boolean(propInfo.source.target &&
propInfo.type !== Function &&
propInfo.source.target.hasAttribute(propInfo.source.name)),
getProp: (propInfo) => {
var _a;
let value;
const rawValue = propInfo.type !== Function
? (_a = propInfo.source.target.getAttribute(propInfo.source.name)) !== null && _a !== void 0 ? _a : undefined
: undefined;
if (rawValue !== undefined) {
value = convertSourceValue(propInfo, rawValue);
}
else if (propInfo.type === Boolean) {
// TODO: output warning about undefined booleans once we document
// how these should behave for all type of sources
// eslint-disable-next-line no-console
console.warn();
}
return value;
},
});
}