Skip to content

Commit

Permalink
fix: snabbdom callsites
Browse files Browse the repository at this point in the history
The `attrs` parameter doesn't seem to work anymore, `props` does.
Also using the return type of patch is generally not needed, since patch
mutates the node itself
  • Loading branch information
Jeidnx authored and MyIgel committed Jan 18, 2025
1 parent b1ff944 commit 0051309
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 38 deletions.
11 changes: 6 additions & 5 deletions lib/config_default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ export interface Domain {
domain: string;
}

export interface LinkInfo {
interface Info {
name: string;
title: string;
href: string;
image: string;
width: string;
height: string;
image?: string;
width?: string;
height?: string;
}

export type NodeInfo = LinkInfo;
export type LinkInfo = Info;
export type NodeInfo = Info;

export interface Link {
title: string;
Expand Down
10 changes: 5 additions & 5 deletions lib/infobox/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
let img = [];
let time = linkData[0].target.lastseen.format("DDMMYYYYHmmss");

header = patch(
patch(
header,
h(
"div",
Expand All @@ -66,7 +66,7 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
),
]),
),
) as unknown as HTMLDivElement;
);

helper.attributeEntry(
children,
Expand Down Expand Up @@ -104,9 +104,9 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
}

let elNew = h("table", children);
let pTable = patch(table, elNew);
(pTable.elm as unknown as HTMLElement).classList.add("attributes");
images = patch(images, h("div", img)) as unknown as HTMLDivElement;
patch(table, elNew);
table.classList.add("attributes");
patch(images, h("div", img));
};

self.setData = function setData(data: { links: LinkData[] }) {
Expand Down
16 changes: 6 additions & 10 deletions lib/infobox/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NodeInfo } from "../config_default.js";

const patch = init([classModule, propsModule, styleModule, eventListenersModule]);

function showStatImg(nodeInfo: NodeInfo, node: NodeData) {
function showStatImg(nodeInfo: NodeInfo, node: NodeData): HTMLDivElement {
let config = window.config;
let subst = {
"{NODE_ID}": node.node_id,
Expand Down Expand Up @@ -199,14 +199,11 @@ export function Node(el: HTMLElement, node: NodeData, linkScale: (t: any) => any

let devicePictures = showDevicePictures(config.devicePictures, node);
let devicePicturesContainerData = {
attrs: {
props: {
class: "hw-img-container",
},
};
devicePicture = patch(
devicePicture,
devicePictures ? h("div", devicePicturesContainerData, devicePictures) : h("div"),
) as unknown as HTMLDivElement;
patch(devicePicture, devicePictures ? h("div", devicePicturesContainerData, devicePictures) : h("div"));

let children = [];

Expand Down Expand Up @@ -237,9 +234,8 @@ export function Node(el: HTMLElement, node: NodeData, linkScale: (t: any) => any
children.push(h("tr", [h("th", _.t("node.gateway")), showGateway(node)]));

let elNew = h("table", children);
table = patch(table, elNew) as unknown as HTMLTableElement;
// @ts-ignore
table.elm.classList.add("attributes");
patch(table, elNew);
table.classList.add("attributes");

patch(neighbours, h("h3", _.t("node.link", node.neighbours.length) + " (" + node.neighbours.length + ")"));
if (node.neighbours.length > 0) {
Expand All @@ -253,7 +249,7 @@ export function Node(el: HTMLElement, node: NodeData, linkScale: (t: any) => any
img.push(h("h4", nodeInfo.name) as unknown as HTMLElement);
img.push(showStatImg(nodeInfo, node));
});
images = patch(images, h("div", img)) as unknown as HTMLDivElement;
patch(images, h("div", img));
}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/linklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const Linklist = function (linkScale: (t: any) => any): CanRender & CanSe
let h2 = document.createElement("h2");
h2.textContent = _.t("node.links");
d.appendChild(h2);
table.el.elm.classList.add("link-list");
d.appendChild(table.el.elm);
table.el.classList.add("link-list");
d.appendChild(table.el);
};

self.setData = function setData(d: ObjectsLinksAndNodes) {
Expand Down
4 changes: 2 additions & 2 deletions lib/nodelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export const Nodelist = function (): CanSetData & CanRender {
let h2 = document.createElement("h2");
h2.textContent = _.t("node.all");
d.appendChild(h2);
table.el.elm.classList.add("node-list");
d.appendChild(table.el.elm);
table.el.classList.add("node-list");
d.appendChild(table.el);
};

self.setData = function setData(nodesData: ObjectsLinksAndNodes) {
Expand Down
11 changes: 5 additions & 6 deletions lib/proportions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { classModule, eventListenersModule, h, init, propsModule, styleModule } from "snabbdom";
import { classModule, eventListenersModule, h, init, propsModule, styleModule, toVNode } from "snabbdom";
import * as d3Interpolate from "d3-interpolate";
import { _ } from "./utils/language.js";
import { DataDistributor, Filter, ObjectsLinksAndNodes } from "./datadistributor.js";
Expand Down Expand Up @@ -97,7 +97,8 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
return h("tr", [th, td]);
});
let tableNew = h("table", { props: { className: "proportion" } }, items);
return patch(table, tableNew) as unknown as HTMLTableElement;
patch(table, tableNew);
return table;
}

self.setData = function setData(data: ObjectsLinksAndNodes) {
Expand Down Expand Up @@ -243,12 +244,10 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
h2.classList.add("proportion-header");
h2.textContent = _.t(heading);
h2.onclick = function onclick() {
// @ts-ignore
table.elm.classList.toggle("hide");
table.classList.toggle("hide");
};
el.appendChild(h2);
// @ts-ignore
el.appendChild(table.elm);
el.appendChild(table);
}
};
return self;
Expand Down
2 changes: 1 addition & 1 deletion lib/simplenodelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const SimpleNodelist = function (nodesState: string, field: string, title
});

let tbodyNew = h("tbody", items);
tbody = patch(tbody, tbodyNew) as unknown as HTMLTableSectionElement;
patch(tbody, tbodyNew);
};

return self;
Expand Down
5 changes: 4 additions & 1 deletion lib/sorttable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const SortTable = function (
sortIndex: number,
renderRow: (element: any, i: number, all: []) => any,
) {
const self = { el: undefined, setData: undefined };
const self: {
el: HTMLElement;
setData: (data: any[]) => void;
} = { el: undefined, setData: undefined };
let data: any[];
let sortReverse = false;
self.el = document.createElement("table");
Expand Down
12 changes: 6 additions & 6 deletions lib/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ export function attributeEntry(children: VNode[], label: string, value: string |
}
}

export function showStat(linkInfo: LinkInfo | NodeInfo, subst: ReplaceMapping): HTMLElement {
export function showStat(linkInfo: LinkInfo, subst: ReplaceMapping): HTMLDivElement {
let content = h("img", {
attrs: {
props: {
src: listReplace(linkInfo.image, subst),
width: linkInfo.width,
height: linkInfo.height,
Expand All @@ -149,17 +149,17 @@ export function showStat(linkInfo: LinkInfo | NodeInfo, subst: ReplaceMapping):
h(
"a",
{
attrs: {
props: {
href: listReplace(linkInfo.href, subst),
target: "_blank",
title: listReplace(linkInfo.title, subst),
},
},
content,
),
) as unknown as HTMLElement;
) as unknown as HTMLDivElement;
}
return h("div", content) as unknown as HTMLElement;
return h("div", content) as unknown as HTMLDivElement;
}

export const showDevicePicture = function showDevicePicture(pictures: string, subst: ReplaceMapping) {
Expand All @@ -168,7 +168,7 @@ export const showDevicePicture = function showDevicePicture(pictures: string, su
}

return h("img", {
attrs: { src: listReplace(pictures, subst), class: "hw-img" },
props: { src: listReplace(pictures, subst), class: "hw-img" },
on: {
// hide non-existent images
error: function (e: any) {
Expand Down

0 comments on commit 0051309

Please sign in to comment.