-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathcommon.ts
More file actions
67 lines (55 loc) · 1.88 KB
/
common.ts
File metadata and controls
67 lines (55 loc) · 1.88 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
function createContainer(id: string, title: string, borderColor: string) {
const container = document.createElement('div')
container.id = id
container.style.flex = '1'
container.style.border = `2px solid ${borderColor}`
container.style.padding = '10px'
const appTitle = document.createElement('h2')
appTitle.textContent = title
container.appendChild(appTitle)
document.body.appendChild(container)
return container
}
function createButton(container: HTMLElement, eventType: string, clickHandler: () => void) {
const button = document.createElement('button')
button.id = `${container.id}-${eventType}`
button.textContent = `${container.id}-${eventType}`
button.onclick = clickHandler
container.appendChild(button)
}
export function createApp(id: string, title: string, borderColor: string) {
const container = createContainer(id, title, borderColor)
createButton(container, 'fetch', () => {
void fetch('/ok')
})
createButton(container, 'xhr', () => {
const xhr = new XMLHttpRequest()
xhr.open('GET', '/ok')
xhr.send()
})
createButton(container, 'error', () => {
window.DD_RUM.addError(new Error(`${id}-error`))
})
createButton(container, 'console-error', () => {
console.error(`${id}-console-error`)
})
createButton(container, 'runtime-error', () => {
throw new Error(`${id}-runtime-error`)
})
createButton(container, 'loaf', () => {
const end = performance.now() + 55
while (performance.now() < end) {
// block the handler for ~55ms to trigger a long task
}
})
createButton(container, 'custom-action', () => {
window.DD_RUM.addAction(`${id}-action`)
})
createButton(container, 'vital', () => {
const ref = window.DD_RUM.startDurationVital(`${id}-vital`)
window.DD_RUM.stopDurationVital(ref)
})
createButton(container, 'view', () => {
window.DD_RUM.startView({ name: `${id}-view` })
})
}