feat: optimise detection of data and svg names (#1058)

Co-authored-by: chris <chris@bumblehead.com>
pull/1064/head
iambumblehead 1 year ago committed by GitHub
parent 6ee1e6b5aa
commit 71813ff558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,7 +16,7 @@ export type VNodeChildren = ArrayOrElement<VNodeChildElement>;
export function addNS( export function addNS(
data: any, data: any,
children: Array<VNode | string> | undefined, children: Array<VNode | string> | undefined,
sel: string | undefined sel: string | undefined,
): void { ): void {
data.ns = "http://www.w3.org/2000/svg"; data.ns = "http://www.w3.org/2000/svg";
if (sel !== "foreignObject" && children !== undefined) { if (sel !== "foreignObject" && children !== undefined) {
@ -37,7 +37,7 @@ export function h(sel: string, children: VNodeChildren): VNode;
export function h( export function h(
sel: string, sel: string,
data: VNodeData | null, data: VNodeData | null,
children: VNodeChildren children: VNodeChildren,
): VNode; ): VNode;
export function h(sel: any, b?: any, c?: any): VNode { export function h(sel: any, b?: any, c?: any): VNode {
let data: VNodeData = {}; let data: VNodeData = {};
@ -74,14 +74,12 @@ export function h(sel: any, b?: any, c?: any): VNode {
undefined, undefined,
undefined, undefined,
children[i], children[i],
undefined undefined,
); );
} }
} }
if ( if (
sel[0] === "s" && sel.startsWith("svg") &&
sel[1] === "v" &&
sel[2] === "g" &&
(sel.length === 3 || sel[3] === "." || sel[3] === "#") (sel.length === 3 || sel[3] === "." || sel[3] === "#")
) { ) {
addNS(data, children, sel); addNS(data, children, sel);

@ -21,13 +21,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
const elmChildren = node.childNodes; const elmChildren = node.childNodes;
for (i = 0, n = elmAttrs.length; i < n; i++) { for (i = 0, n = elmAttrs.length; i < n; i++) {
name = elmAttrs[i].nodeName; name = elmAttrs[i].nodeName;
if ( if (name.startsWith("data-")) {
name[0] === "d" &&
name[1] === "a" &&
name[2] === "t" &&
name[3] === "a" &&
name[4] === "-"
) {
dataset[name.slice(5)] = elmAttrs[i].nodeValue || ""; dataset[name.slice(5)] = elmAttrs[i].nodeValue || "";
} else if (name !== "id" && name !== "class") { } else if (name !== "id" && name !== "class") {
attrs[name] = elmAttrs[i].nodeValue; attrs[name] = elmAttrs[i].nodeValue;
@ -41,9 +35,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
if (Object.keys(dataset).length > 0) data.dataset = dataset; if (Object.keys(dataset).length > 0) data.dataset = dataset;
if ( if (
sel[0] === "s" && sel.startsWith("svg") &&
sel[1] === "v" &&
sel[2] === "g" &&
(sel.length === 3 || sel[3] === "." || sel[3] === "#") (sel.length === 3 || sel[3] === "." || sel[3] === "#")
) { ) {
addNS(data, children, sel); addNS(data, children, sel);

Loading…
Cancel
Save