Skip to content

Commit 0051309

Browse files
JeidnxMyIgel
authored andcommitted
fix: snabbdom callsites
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
1 parent b1ff944 commit 0051309

File tree

9 files changed

+37
-38
lines changed

9 files changed

+37
-38
lines changed

lib/config_default.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,17 @@ export interface Domain {
4242
domain: string;
4343
}
4444

45-
export interface LinkInfo {
45+
interface Info {
4646
name: string;
4747
title: string;
4848
href: string;
49-
image: string;
50-
width: string;
51-
height: string;
49+
image?: string;
50+
width?: string;
51+
height?: string;
5252
}
5353

54-
export type NodeInfo = LinkInfo;
54+
export type LinkInfo = Info;
55+
export type NodeInfo = Info;
5556

5657
export interface Link {
5758
title: string;

lib/infobox/link.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
4444
let img = [];
4545
let time = linkData[0].target.lastseen.format("DDMMYYYYHmmss");
4646

47-
header = patch(
47+
patch(
4848
header,
4949
h(
5050
"div",
@@ -66,7 +66,7 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
6666
),
6767
]),
6868
),
69-
) as unknown as HTMLDivElement;
69+
);
7070

7171
helper.attributeEntry(
7272
children,
@@ -104,9 +104,9 @@ export const Link = function (el: HTMLElement, linkData: LinkData[], linkScale:
104104
}
105105

106106
let elNew = h("table", children);
107-
let pTable = patch(table, elNew);
108-
(pTable.elm as unknown as HTMLElement).classList.add("attributes");
109-
images = patch(images, h("div", img)) as unknown as HTMLDivElement;
107+
patch(table, elNew);
108+
table.classList.add("attributes");
109+
patch(images, h("div", img));
110110
};
111111

112112
self.setData = function setData(data: { links: LinkData[] }) {

lib/infobox/node.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NodeInfo } from "../config_default.js";
88

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

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

200200
let devicePictures = showDevicePictures(config.devicePictures, node);
201201
let devicePicturesContainerData = {
202-
attrs: {
202+
props: {
203203
class: "hw-img-container",
204204
},
205205
};
206-
devicePicture = patch(
207-
devicePicture,
208-
devicePictures ? h("div", devicePicturesContainerData, devicePictures) : h("div"),
209-
) as unknown as HTMLDivElement;
206+
patch(devicePicture, devicePictures ? h("div", devicePicturesContainerData, devicePictures) : h("div"));
210207

211208
let children = [];
212209

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

239236
let elNew = h("table", children);
240-
table = patch(table, elNew) as unknown as HTMLTableElement;
241-
// @ts-ignore
242-
table.elm.classList.add("attributes");
237+
patch(table, elNew);
238+
table.classList.add("attributes");
243239

244240
patch(neighbours, h("h3", _.t("node.link", node.neighbours.length) + " (" + node.neighbours.length + ")"));
245241
if (node.neighbours.length > 0) {
@@ -253,7 +249,7 @@ export function Node(el: HTMLElement, node: NodeData, linkScale: (t: any) => any
253249
img.push(h("h4", nodeInfo.name) as unknown as HTMLElement);
254250
img.push(showStatImg(nodeInfo, node));
255251
});
256-
images = patch(images, h("div", img)) as unknown as HTMLDivElement;
252+
patch(images, h("div", img));
257253
}
258254
};
259255

lib/linklist.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export const Linklist = function (linkScale: (t: any) => any): CanRender & CanSe
9292
let h2 = document.createElement("h2");
9393
h2.textContent = _.t("node.links");
9494
d.appendChild(h2);
95-
table.el.elm.classList.add("link-list");
96-
d.appendChild(table.el.elm);
95+
table.el.classList.add("link-list");
96+
d.appendChild(table.el);
9797
};
9898

9999
self.setData = function setData(d: ObjectsLinksAndNodes) {

lib/nodelist.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ export const Nodelist = function (): CanSetData & CanRender {
101101
let h2 = document.createElement("h2");
102102
h2.textContent = _.t("node.all");
103103
d.appendChild(h2);
104-
table.el.elm.classList.add("node-list");
105-
d.appendChild(table.el.elm);
104+
table.el.classList.add("node-list");
105+
d.appendChild(table.el);
106106
};
107107

108108
self.setData = function setData(nodesData: ObjectsLinksAndNodes) {

lib/proportions.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { classModule, eventListenersModule, h, init, propsModule, styleModule } from "snabbdom";
1+
import { classModule, eventListenersModule, h, init, propsModule, styleModule, toVNode } from "snabbdom";
22
import * as d3Interpolate from "d3-interpolate";
33
import { _ } from "./utils/language.js";
44
import { DataDistributor, Filter, ObjectsLinksAndNodes } from "./datadistributor.js";
@@ -97,7 +97,8 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
9797
return h("tr", [th, td]);
9898
});
9999
let tableNew = h("table", { props: { className: "proportion" } }, items);
100-
return patch(table, tableNew) as unknown as HTMLTableElement;
100+
patch(table, tableNew);
101+
return table;
101102
}
102103

103104
self.setData = function setData(data: ObjectsLinksAndNodes) {
@@ -243,12 +244,10 @@ export const Proportions = function (filterManager: ReturnType<typeof DataDistri
243244
h2.classList.add("proportion-header");
244245
h2.textContent = _.t(heading);
245246
h2.onclick = function onclick() {
246-
// @ts-ignore
247-
table.elm.classList.toggle("hide");
247+
table.classList.toggle("hide");
248248
};
249249
el.appendChild(h2);
250-
// @ts-ignore
251-
el.appendChild(table.elm);
250+
el.appendChild(table);
252251
}
253252
};
254253
return self;

lib/simplenodelist.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const SimpleNodelist = function (nodesState: string, field: string, title
7070
});
7171

7272
let tbodyNew = h("tbody", items);
73-
tbody = patch(tbody, tbodyNew) as unknown as HTMLTableSectionElement;
73+
patch(tbody, tbodyNew);
7474
};
7575

7676
return self;

lib/sorttable.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ export const SortTable = function (
1515
sortIndex: number,
1616
renderRow: (element: any, i: number, all: []) => any,
1717
) {
18-
const self = { el: undefined, setData: undefined };
18+
const self: {
19+
el: HTMLElement;
20+
setData: (data: any[]) => void;
21+
} = { el: undefined, setData: undefined };
1922
let data: any[];
2023
let sortReverse = false;
2124
self.el = document.createElement("table");

lib/utils/helper.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ export function attributeEntry(children: VNode[], label: string, value: string |
133133
}
134134
}
135135

136-
export function showStat(linkInfo: LinkInfo | NodeInfo, subst: ReplaceMapping): HTMLElement {
136+
export function showStat(linkInfo: LinkInfo, subst: ReplaceMapping): HTMLDivElement {
137137
let content = h("img", {
138-
attrs: {
138+
props: {
139139
src: listReplace(linkInfo.image, subst),
140140
width: linkInfo.width,
141141
height: linkInfo.height,
@@ -149,17 +149,17 @@ export function showStat(linkInfo: LinkInfo | NodeInfo, subst: ReplaceMapping):
149149
h(
150150
"a",
151151
{
152-
attrs: {
152+
props: {
153153
href: listReplace(linkInfo.href, subst),
154154
target: "_blank",
155155
title: listReplace(linkInfo.title, subst),
156156
},
157157
},
158158
content,
159159
),
160-
) as unknown as HTMLElement;
160+
) as unknown as HTMLDivElement;
161161
}
162-
return h("div", content) as unknown as HTMLElement;
162+
return h("div", content) as unknown as HTMLDivElement;
163163
}
164164

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

170170
return h("img", {
171-
attrs: { src: listReplace(pictures, subst), class: "hw-img" },
171+
props: { src: listReplace(pictures, subst), class: "hw-img" },
172172
on: {
173173
// hide non-existent images
174174
error: function (e: any) {

0 commit comments

Comments
 (0)