angular/modules/benchmarks/src/defer/init.ts
Joey Perrott 9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00

52 lines
1.4 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ApplicationRef} from '@angular/core';
import {bindAction, profile} from '../util';
import {buildTable, emptyTable, initTableUtils} from './util';
const DEFAULT_COLS_COUNT = '40';
const DEFAULT_ROWS_COUNT = '200';
function getUrlParamValue(name: string): string | null {
const url = new URL(document.location.href);
return url.searchParams.get(name);
}
export function syncUrlParamsToForm(): {cols: string; rows: string} {
let cols = getUrlParamValue('cols') ?? DEFAULT_COLS_COUNT;
let rows = getUrlParamValue('rows') ?? DEFAULT_ROWS_COUNT;
(document.getElementById('cols') as HTMLInputElement).value = cols;
(document.getElementById('rows') as HTMLInputElement).value = rows;
return {cols, rows};
}
export function init(appRef: ApplicationRef) {
const table = appRef.components[0].instance;
function destroyDom() {
table.data = emptyTable;
appRef.tick();
}
function createDom() {
table.data = buildTable();
appRef.tick();
}
function noop() {}
initTableUtils();
bindAction('#destroyDom', destroyDom);
bindAction('#createDom', createDom);
bindAction('#createDomProfile', profile(createDom, destroyDom, 'create'));
bindAction('#updateDomProfile', profile(createDom, noop, 'update'));
}