MCPcopy Index your code
hub / github.com/microsoft/SandDance / createElement

Function createElement

docs/app/js/sanddance-app.js:6648–6675  ·  view source on GitHub ↗
(tag, attrs, ...children)

Source from the content-addressed store, hash-verified

6646 return str.replace(/([a-z\d])([A-Z])/g, "$1" + separator + "$2").replace(/([A-Z]+)([A-Z][a-z\d]+)/g, "$1" + separator + "$2").toLowerCase();
6647}
6648function createElement(tag, attrs, ...children) {
6649 if (typeof tag === "function") {
6650 const fn = tag;
6651 const props = attrs;
6652 props.children = children;
6653 return fn(props);
6654 } else {
6655 const ns = tagNamespace(tag);
6656 const el = ns ? document.createElementNS(ns, tag) : document.createElement(tag);
6657 const map = attrs;
6658 let ref;
6659 for(let name in map)if (name && map.hasOwnProperty(name)) {
6660 let value = map[name];
6661 if (name === "className" && value !== void 0) setAttribute(el, ns, "class", value.toString());
6662 else if (name === "disabled" && !value) ;
6663 else if (value === null || value === undefined) continue;
6664 else if (value === true) setAttribute(el, ns, name, name);
6665 else if (typeof value === "function") {
6666 if (name === "ref") ref = value;
6667 else el[name.toLowerCase()] = value;
6668 } else if (typeof value === "object") setAttribute(el, ns, name, flatten(value));
6669 else setAttribute(el, ns, name, value.toString());
6670 }
6671 if (children && children.length > 0) appendChildren(el, children);
6672 if (ref) ref(el);
6673 return el;
6674 }
6675}
6676function setAttribute(el, ns, name, value) {
6677 if (ns) el.setAttributeNS(null, name, value);
6678 else el.setAttribute(name, value);

Callers

nothing calls this directly

Calls 7

fnFunction · 0.70
tagNamespaceFunction · 0.70
setAttributeFunction · 0.70
flattenFunction · 0.70
appendChildrenFunction · 0.70
refFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected