|
| 1 | +export function createButton(containerApp: HTMLDivElement, id: string, clickHandler: () => void): HTMLButtonElement { |
| 2 | + const button = document.createElement('button') |
| 3 | + const appName = containerApp.id |
| 4 | + button.id = `${appName}-${id}` |
| 5 | + button.textContent = `${appName}-${id}` |
| 6 | + button.onclick = () => clickHandler() |
| 7 | + containerApp.appendChild(button) |
| 8 | + return button |
| 9 | +} |
| 10 | + |
| 11 | +export function createAppContainer(id: string, title: string, borderColor: string): HTMLDivElement { |
| 12 | + const appContainer = document.createElement('div') |
| 13 | + appContainer.id = id |
| 14 | + appContainer.style.flex = '1' |
| 15 | + appContainer.style.border = `2px solid ${borderColor}` |
| 16 | + appContainer.style.padding = '10px' |
| 17 | + |
| 18 | + const appTitle = document.createElement('h2') |
| 19 | + appTitle.textContent = title |
| 20 | + appContainer.appendChild(appTitle) |
| 21 | + |
| 22 | + return appContainer |
| 23 | +} |
| 24 | + |
| 25 | +const containerApp = createAppContainer('app2', 'App 2 (mf-app2-service v0.2.0)', 'green') |
| 26 | +document.body.appendChild(containerApp) |
| 27 | + |
| 28 | +createButton(containerApp, 'fetch-button', () => { |
| 29 | + fetch('/ok').then( |
| 30 | + () => { |
| 31 | + /* empty */ |
| 32 | + }, |
| 33 | + () => { |
| 34 | + /* empty */ |
| 35 | + } |
| 36 | + ) |
| 37 | +}) |
| 38 | + |
| 39 | +createButton(containerApp, 'xhr-button', () => { |
| 40 | + const xhr = new XMLHttpRequest() |
| 41 | + xhr.open('GET', '/ok') |
| 42 | + xhr.send() |
| 43 | +}) |
| 44 | + |
| 45 | +createButton(containerApp, 'error-button', () => { |
| 46 | + window.DD_RUM.addError(new Error('mf-app2-error')) |
| 47 | +}) |
| 48 | + |
| 49 | +createButton(containerApp, 'console-error-button', () => { |
| 50 | + console.error('mf-app2-console-error') |
| 51 | +}) |
| 52 | + |
| 53 | +createButton(containerApp, 'runtime-error-button', () => { |
| 54 | + throw new Error('mf-app2-runtime-error') |
| 55 | +}) |
| 56 | + |
| 57 | +createButton(containerApp, 'loaf-button', () => { |
| 58 | + const end = performance.now() + 55 |
| 59 | + while (performance.now() < end) { |
| 60 | + // block the handler for ~55ms to trigger a long task |
| 61 | + } |
| 62 | +}) |
| 63 | + |
| 64 | +createButton(containerApp, 'custom-action-button', () => { |
| 65 | + window.DD_RUM.addAction('mf-app2-action') |
| 66 | +}) |
| 67 | + |
| 68 | +createButton(containerApp, 'vital-button', () => { |
| 69 | + const ref = window.DD_RUM.startDurationVital('mf-app2-vital') |
| 70 | + window.DD_RUM.stopDurationVital(ref) |
| 71 | +}) |
| 72 | + |
| 73 | +createButton(containerApp, 'view-button', () => { |
| 74 | + window.DD_RUM.startView({ name: 'mf-app2-view' }) |
| 75 | +}) |
0 commit comments