-
Notifications
You must be signed in to change notification settings - Fork 29
/
render.tsx
29 lines (25 loc) · 1.07 KB
/
render.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { h, render } from 'preact';
import { Constants } from '../types';
import { IGraphNode } from 'vscode-js-profile-core/out/cpu/model';
import { TimeView } from './table-view';
export const renderTableTag = (tag: HTMLScriptElement) => {
let target: HTMLElement;
if (tag.nextElementSibling?.classList.contains('js-debug-table')) {
target = tag.nextElementSibling as HTMLElement;
} else {
target = document.createElement('div');
target.classList.add('js-debug-table');
tag.parentNode?.insertBefore(target, tag.nextSibling);
}
const graph: IGraphNode = JSON.parse(tag.innerHTML);
render(<TimeView data={Object.values(graph)} />, target);
};
export const renderAllTables = () => {
const nodeList = document.querySelectorAll(`script[type="${Constants.TableMimeType}"]`);
for (let i = 0; i < nodeList.length; i++) {
renderTableTag(nodeList[i] as HTMLScriptElement);
}
};