Skip to content

Commit

Permalink
feat: optimise detection of data and svg names (#1058)
Browse files Browse the repository at this point in the history
Co-authored-by: chris <chris@bumblehead.com>
  • Loading branch information
iambumblehead and bumblehead committed Oct 25, 2023
1 parent 6ee1e6b commit 71813ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
10 changes: 4 additions & 6 deletions src/h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type VNodeChildren = ArrayOrElement<VNodeChildElement>;
export function addNS(
data: any,
children: Array<VNode | string> | undefined,
sel: string | undefined
sel: string | undefined,
): void {
data.ns = "http://www.w3.org/2000/svg";
if (sel !== "foreignObject" && children !== undefined) {
Expand All @@ -37,7 +37,7 @@ export function h(sel: string, children: VNodeChildren): VNode;
export function h(
sel: string,
data: VNodeData | null,
children: VNodeChildren
children: VNodeChildren,
): VNode;
export function h(sel: any, b?: any, c?: any): VNode {
let data: VNodeData = {};
Expand Down Expand Up @@ -74,14 +74,12 @@ export function h(sel: any, b?: any, c?: any): VNode {
undefined,
undefined,
children[i],
undefined
undefined,
);
}
}
if (
sel[0] === "s" &&
sel[1] === "v" &&
sel[2] === "g" &&
sel.startsWith("svg") &&
(sel.length === 3 || sel[3] === "." || sel[3] === "#")
) {
addNS(data, children, sel);
Expand Down
12 changes: 2 additions & 10 deletions src/tovnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
const elmChildren = node.childNodes;
for (i = 0, n = elmAttrs.length; i < n; i++) {
name = elmAttrs[i].nodeName;
if (
name[0] === "d" &&
name[1] === "a" &&
name[2] === "t" &&
name[3] === "a" &&
name[4] === "-"
) {
if (name.startsWith("data-")) {
dataset[name.slice(5)] = elmAttrs[i].nodeValue || "";
} else if (name !== "id" && name !== "class") {
attrs[name] = elmAttrs[i].nodeValue;
Expand All @@ -41,9 +35,7 @@ export function toVNode(node: Node, domApi?: DOMAPI): VNode {
if (Object.keys(dataset).length > 0) data.dataset = dataset;

if (
sel[0] === "s" &&
sel[1] === "v" &&
sel[2] === "g" &&
sel.startsWith("svg") &&
(sel.length === 3 || sel[3] === "." || sel[3] === "#")
) {
addNS(data, children, sel);
Expand Down

0 comments on commit 71813ff

Please sign in to comment.