_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
angular/modules/benchmarks/src/hydration/util.ts_0_1299
/** * @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 {getIntParameter} from '../util'; export class TableCell { constructor( public row: number, public col: number, public value: string, ) {} } let tableCreateCount: number; let maxRow: number; let maxCol: number; let numberData: TableCell[][]; let charData: TableCell[][]; export function initTableUtils() { maxRow = getIntParameter('rows'); maxCol = getIntParameter('cols'); tableCreateCount = 0; numberData = []; charData = []; for (let r = 0; r < maxRow; r++) { const numberRow: TableCell[] = []; numberData.push(numberRow); const charRow: TableCell[] = []; charData.push(charRow); for (let c = 0; c < maxCol; c++) { numberRow.push(new TableCell(r, c, `${c}/${r}`)); charRow.push(new TableCell(r, c, `${charValue(c)}/${charValue(r)}`)); } } } function charValue(i: number): string { return String.fromCharCode('A'.charCodeAt(0) + (i % 26)); } export const emptyTable: TableCell[][] = []; export function buildTable(): TableCell[][] { tableCreateCount++; return tableCreateCount % 2 ? numberData : charData; }
{ "end_byte": 1299, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/util.ts" }
angular/modules/benchmarks/src/hydration/BUILD.bazel_0_974
load("//tools:defaults.bzl", "ng_module", "ts_library") package(default_visibility = ["//visibility:public"]) ng_module( name = "shared_lib", srcs = [ "init.ts", "table.ts", "util.ts", ], tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//packages/core", "//packages/platform-browser", ], ) ts_library( name = "perf_tests_lib", testonly = 1, srcs = ["hydration.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], ) ts_library( name = "e2e_tests_lib", testonly = 1, srcs = ["hydration.e2e-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 974, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/BUILD.bazel" }
angular/modules/benchmarks/src/hydration/hydration.perf-spec.ts_0_2193
/** * @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 { runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; interface Worker { id: string; prepare?(): void; work(): void; } const CreateWorker: Worker = { id: 'create', prepare: () => $('#prepare').click(), work: () => $('#createDom').click(), }; const UpdateWorker: Worker = { id: 'update', prepare: () => { $('#prepare').click(); $('#createDom').click(); }, work: () => $('#updateDom').click(), }; // In order to make sure that we don't change the ids of the benchmarks, we need to // determine the current test package name from the Bazel target. This is necessary // because previous to the Bazel conversion, the benchmark test ids contained the test // name. e.g. "largeTable.ng2_switch.createDestroy". We determine the name of the // Bazel package where this test runs from the current test target. The Bazel target // looks like: "//modules/benchmarks/src/largetable/{pkg_name}:{target_name}". const testPackageName = process.env['BAZEL_TARGET']!.split(':')[0].split('/').pop(); describe('hydration benchmark perf', () => { afterEach(verifyNoBrowserErrors); [CreateWorker, UpdateWorker].forEach((worker) => { describe(worker.id, () => { it(`should run benchmark for ${testPackageName}`, async () => { await runTableBenchmark({ id: `hydration.${testPackageName}.${worker.id}`, url: '/', ignoreBrowserSynchronization: true, worker, }); }); }); }); }); function runTableBenchmark(config: { id: string; url: string; ignoreBrowserSynchronization?: boolean; worker: Worker; }) { return runBenchmark({ id: config.id, url: config.url, ignoreBrowserSynchronization: config.ignoreBrowserSynchronization, params: [ {name: 'cols', value: 40}, {name: 'rows', value: 200}, ], prepare: config.worker.prepare, work: config.worker.work, }); }
{ "end_byte": 2193, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/hydration.perf-spec.ts" }
angular/modules/benchmarks/src/hydration/baseline/index.html_0_1113
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <!--nghm--> <h2>Params</h2> <form> Cols: <input type="number" id="cols" name="cols" value="" /> <br /> Rows: <input type="number" id="rows" name="rows" value="" /> <br /> <button>Apply</button> </form> <h2>Hydration Benchmark (baseline)</h2> <p> <button id="prepare">prepare</button> <button id="createDom">createDom</button> <button id="updateDom">updateDom</button> <button id="createDomProfile">profile createDom</button> <button id="updateDomProfile">profile updateDom</button> </p> <div> <app id="root"></app> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <div id="table"></div> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 1113, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/baseline/index.html" }
angular/modules/benchmarks/src/hydration/baseline/BUILD.bazel_0_1356
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "main", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/hydration:shared_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [ ":main", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/hydration:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":prodserver", deps = ["//modules/benchmarks/src/hydration:e2e_tests_lib"], )
{ "end_byte": 1356, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/baseline/BUILD.bazel" }
angular/modules/benchmarks/src/hydration/baseline/index.ts_0_569
/** * @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 {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {init, syncUrlParamsToForm} from '../init'; import {AppComponent} from '../table'; syncUrlParamsToForm(); bootstrapApplication(AppComponent, { providers: [provideProtractorTestingSupport()], }).then((appRef) => init(appRef, false /* insertSsrContent */));
{ "end_byte": 569, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/baseline/index.ts" }
angular/modules/benchmarks/src/hydration/main/index.html_0_1109
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <!--nghm--> <h2>Params</h2> <form> Cols: <input type="number" id="cols" name="cols" value="" /> <br /> Rows: <input type="number" id="rows" name="rows" value="" /> <br /> <button>Apply</button> </form> <h2>Hydration Benchmark (main)</h2> <p> <button id="prepare">prepare</button> <button id="createDom">createDom</button> <button id="updateDom">updateDom</button> <button id="createDomProfile">profile createDom</button> <button id="updateDomProfile">profile updateDom</button> </p> <div> <app id="root"></app> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <div id="table"></div> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 1109, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/main/index.html" }
angular/modules/benchmarks/src/hydration/main/BUILD.bazel_0_1356
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "main", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/hydration:shared_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [ ":main", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/hydration:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":prodserver", deps = ["//modules/benchmarks/src/hydration:e2e_tests_lib"], )
{ "end_byte": 1356, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/main/BUILD.bazel" }
angular/modules/benchmarks/src/hydration/main/index.ts_0_708
/** * @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 { bootstrapApplication, provideClientHydration, provideProtractorTestingSupport, } from '@angular/platform-browser'; import {init, syncUrlParamsToForm} from '../init'; import {AppComponent, setupTransferState} from '../table'; const params = syncUrlParamsToForm(); setupTransferState(params.cols, params.rows); bootstrapApplication(AppComponent, { providers: [provideClientHydration(), provideProtractorTestingSupport()], }).then((appRef) => init(appRef, true /* insertSsrContent */));
{ "end_byte": 708, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/hydration/main/index.ts" }
angular/modules/benchmarks/src/defer/init.ts_0_1458
/** * @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')); }
{ "end_byte": 1458, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/init.ts" }
angular/modules/benchmarks/src/defer/defer.e2e-spec.ts_0_742
/** * @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 { openBrowser, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; describe('defer benchmark', () => { afterEach(verifyNoBrowserErrors); it(`should render the table`, async () => { openBrowser({ url: '', ignoreBrowserSynchronization: true, params: [ {name: 'cols', value: 5}, {name: 'rows', value: 5}, ], }); await $('#createDom').click(); expect($('#root').getText()).toContain('Cell'); }); });
{ "end_byte": 742, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/defer.e2e-spec.ts" }
angular/modules/benchmarks/src/defer/README.md_0_418
# Defer benchmark This folder contains defer benchmark that tests the process of `@defer` block creation. There are 2 folders in this benchmark: * `baseline` - renders a component using an `@if` condition, we use it as a baseline * `main` - the same code as the `baseline`, but instead of the `@if`, we use `@defer` to compare defer blocks against conditionals The benchmarks are based on `largetable` benchmarks.
{ "end_byte": 418, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/README.md" }
angular/modules/benchmarks/src/defer/util.ts_0_1299
/** * @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 {getIntParameter} from '../util'; export class TableCell { constructor( public row: number, public col: number, public value: string, ) {} } let tableCreateCount: number; let maxRow: number; let maxCol: number; let numberData: TableCell[][]; let charData: TableCell[][]; export function initTableUtils() { maxRow = getIntParameter('rows'); maxCol = getIntParameter('cols'); tableCreateCount = 0; numberData = []; charData = []; for (let r = 0; r < maxRow; r++) { const numberRow: TableCell[] = []; numberData.push(numberRow); const charRow: TableCell[] = []; charData.push(charRow); for (let c = 0; c < maxCol; c++) { numberRow.push(new TableCell(r, c, `${c}/${r}`)); charRow.push(new TableCell(r, c, `${charValue(c)}/${charValue(r)}`)); } } } function charValue(i: number): string { return String.fromCharCode('A'.charCodeAt(0) + (i % 26)); } export const emptyTable: TableCell[][] = []; export function buildTable(): TableCell[][] { tableCreateCount++; return tableCreateCount % 2 ? numberData : charData; }
{ "end_byte": 1299, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/util.ts" }
angular/modules/benchmarks/src/defer/BUILD.bazel_0_946
load("//tools:defaults.bzl", "ng_module", "ts_library") package(default_visibility = ["//visibility:public"]) ng_module( name = "shared_lib", srcs = [ "init.ts", "util.ts", ], tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//packages/core", "//packages/platform-browser", ], ) ts_library( name = "perf_tests_lib", testonly = 1, srcs = ["defer.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], ) ts_library( name = "e2e_tests_lib", testonly = 1, srcs = ["defer.e2e-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 946, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/BUILD.bazel" }
angular/modules/benchmarks/src/defer/defer.perf-spec.ts_0_2161
/** * @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 { runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; interface Worker { id: string; prepare?(): void; work(): void; } const CreateWorker: Worker = { id: 'create', prepare: () => $('#destroyDom').click(), work: () => $('#createDom').click(), }; const UpdateWorker: Worker = { id: 'update', prepare: () => { $('#createDom').click(); }, work: () => $('#createDom').click(), }; // In order to make sure that we don't change the ids of the benchmarks, we need to // determine the current test package name from the Bazel target. This is necessary // because previous to the Bazel conversion, the benchmark test ids contained the test // name. e.g. "largeTable.ng2_switch.createDestroy". We determine the name of the // Bazel package where this test runs from the current test target. The Bazel target // looks like: "//modules/benchmarks/src/largetable/{pkg_name}:{target_name}". const testPackageName = process.env['BAZEL_TARGET']!.split(':')[0].split('/').pop(); describe('defer benchmark perf', () => { afterEach(verifyNoBrowserErrors); [CreateWorker, UpdateWorker].forEach((worker) => { describe(worker.id, () => { it(`should run benchmark for ${testPackageName}`, async () => { await runTableBenchmark({ id: `defer.${testPackageName}.${worker.id}`, url: '/', ignoreBrowserSynchronization: true, worker, }); }); }); }); }); function runTableBenchmark(config: { id: string; url: string; ignoreBrowserSynchronization?: boolean; worker: Worker; }) { return runBenchmark({ id: config.id, url: config.url, ignoreBrowserSynchronization: config.ignoreBrowserSynchronization, params: [ {name: 'cols', value: 40}, {name: 'rows', value: 200}, ], prepare: config.worker.prepare, work: config.worker.work, }); }
{ "end_byte": 2161, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/defer.perf-spec.ts" }
angular/modules/benchmarks/src/defer/baseline/index.html_0_1023
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2>Params</h2> <form> Cols: <input type="number" id="cols" name="cols" value="" /> <br /> Rows: <input type="number" id="rows" name="rows" value="" /> <br /> <button>Apply</button> </form> <h2>Defer Benchmark (baseline)</h2> <p> <button id="destroyDom">destroyDom</button> <button id="createDom">createDom</button> <button id="createDomProfile">profile createDom</button> <button id="updateDomProfile">profile updateDom</button> </p> <div> <app id="root"></app> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 1023, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/baseline/index.html" }
angular/modules/benchmarks/src/defer/baseline/app.component.ts_0_1333
/** * @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 {Component, Input} from '@angular/core'; import {DomSanitizer, SafeStyle} from '@angular/platform-browser'; import {TableCell} from '../util'; let trustedEmptyColor: SafeStyle; let trustedGreyColor: SafeStyle; @Component({ standalone: true, selector: 'app', template: ` <table> <tbody> @for (row of data; track $index) { <tr> @for (cell of row; track $index) { <td [style.backgroundColor]="getColor(cell.row)"> @if (condition) { <!-- Use static text in cells to avoid the need to run a new change detection cycle. --> Cell } </td> } </tr> } </tbody> </table> `, }) export class AppComponent { @Input() data: TableCell[][] = []; condition = true; constructor(sanitizer: DomSanitizer) { trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('white'); trustedGreyColor = sanitizer.bypassSecurityTrustStyle('grey'); } getColor(row: number) { return row % 2 ? trustedEmptyColor : trustedGreyColor; } }
{ "end_byte": 1333, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/baseline/app.component.ts" }
angular/modules/benchmarks/src/defer/baseline/BUILD.bazel_0_1344
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "main", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/defer:shared_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [ ":main", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/defer:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":prodserver", deps = ["//modules/benchmarks/src/defer:e2e_tests_lib"], )
{ "end_byte": 1344, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/baseline/BUILD.bazel" }
angular/modules/benchmarks/src/defer/baseline/index.ts_0_527
/** * @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 {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {init, syncUrlParamsToForm} from '../init'; import {AppComponent} from './app.component'; syncUrlParamsToForm(); bootstrapApplication(AppComponent, { providers: [provideProtractorTestingSupport()], }).then(init);
{ "end_byte": 527, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/baseline/index.ts" }
angular/modules/benchmarks/src/defer/main/index.html_0_1019
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2>Params</h2> <form> Cols: <input type="number" id="cols" name="cols" value="" /> <br /> Rows: <input type="number" id="rows" name="rows" value="" /> <br /> <button>Apply</button> </form> <h2>Defer Benchmark (main)</h2> <p> <button id="destroyDom">destroyDom</button> <button id="createDom">createDom</button> <button id="createDomProfile">profile createDom</button> <button id="updateDomProfile">profile updateDom</button> </p> <div> <app id="root"></app> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 1019, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/main/index.html" }
angular/modules/benchmarks/src/defer/main/app.component.ts_0_1355
/** * @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 {Component, Input} from '@angular/core'; import {DomSanitizer, SafeStyle} from '@angular/platform-browser'; import {TableCell} from '../util'; let trustedEmptyColor: SafeStyle; let trustedGreyColor: SafeStyle; @Component({ standalone: true, selector: 'app', template: ` <table> <tbody> @for (row of data; track $index) { <tr> @for (cell of row; track $index) { <td [style.backgroundColor]="getColor(cell.row)"> @defer (when condition; on immediate) { <!-- Use static text in cells to avoid the need to run a new change detection cycle. --> Cell } </td> } </tr> } </tbody> </table> `, }) export class AppComponent { @Input() data: TableCell[][] = []; condition = true; constructor(sanitizer: DomSanitizer) { trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('white'); trustedGreyColor = sanitizer.bypassSecurityTrustStyle('grey'); } getColor(row: number) { return row % 2 ? trustedEmptyColor : trustedGreyColor; } }
{ "end_byte": 1355, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/main/app.component.ts" }
angular/modules/benchmarks/src/defer/main/BUILD.bazel_0_1344
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "main", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/defer:shared_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [ ":main", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/defer:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":prodserver", deps = ["//modules/benchmarks/src/defer:e2e_tests_lib"], )
{ "end_byte": 1344, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/main/BUILD.bazel" }
angular/modules/benchmarks/src/defer/main/index.ts_0_527
/** * @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 {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {init, syncUrlParamsToForm} from '../init'; import {AppComponent} from './app.component'; syncUrlParamsToForm(); bootstrapApplication(AppComponent, { providers: [provideProtractorTestingSupport()], }).then(init);
{ "end_byte": 527, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/defer/main/index.ts" }
angular/modules/benchmarks/src/expanding_rows/index.html_0_535
<!DOCTYPE html> <html> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h1>Change Detection Benchmark</h1> <div id="rendererMode">...</div> <benchmark-root>Loading...</benchmark-root> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 535, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/index.html" }
angular/modules/benchmarks/src/expanding_rows/benchmarkable_expanding_row.ts_0_2028
/** * @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 {Component} from '@angular/core'; export interface MlbTeam { name: string; id: number; division: string; stadium: string; projection: string; } @Component({ selector: 'benchmarkable-expanding-row', template: ` <cfc-expanding-row-host *ngIf="showExpandingRow"> <cfc-expanding-row *ngFor="let team of teams" [rowId]="$any(team.id)"> <cfc-expanding-row-summary> Team {{ team.id }} </cfc-expanding-row-summary> <cfc-expanding-row-details-caption> {{ team.name }} <a href="https://www.google.com" class="cfc-demo-expanding-row-caption-link"> {{ team.id }} </a> </cfc-expanding-row-details-caption> <cfc-expanding-row-details-content> <ul ace-list> <li>Division: {{ team.division }}</li> <li> <a href="https://www.google.com">{{ team.stadium }}</a> </li> <li>Projected Record: {{ team.projection }}</li> </ul> </cfc-expanding-row-details-content> </cfc-expanding-row> </cfc-expanding-row-host>`, standalone: false, }) export class BenchmarkableExpandingRow { // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. showExpandingRow!: boolean; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. teams!: MlbTeam[]; // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. private fakeTeams!: MlbTeam[]; init(): void { this.teams = this.fakeTeams; this.showExpandingRow = true; } reset(numItems = 5000): void { this.showExpandingRow = false; this.fakeTeams = []; for (let i = 0; i < numItems; i++) { this.fakeTeams.push({ name: `name ${i}`, id: i, division: `division ${i}`, stadium: `stadium ${i}`, projection: `projection ${i}`, }); } } }
{ "end_byte": 2028, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/benchmarkable_expanding_row.ts" }
angular/modules/benchmarks/src/expanding_rows/index_aot.ts_0_581
/** * @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 */ // This benchmark uses i18n in its `ExpandingRowSummary` component so `$localize` must be loaded. import '@angular/localize/init'; import {enableProdMode} from '@angular/core'; import {platformBrowser} from '@angular/platform-browser'; import {ExpandingRowBenchmarkModule} from './benchmark'; enableProdMode(); platformBrowser().bootstrapModule(ExpandingRowBenchmarkModule);
{ "end_byte": 581, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/index_aot.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_css.ts_0_1878
/** * @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 */ export const expanding_row_css = ` ::ng-deep [cfcExpandingRowHost] { display: block; margin-bottom: 2; } :host(cfc-expanding-row), :host(cfc-expanding-row-summary), :host(cfc-expanding-row-details-caption), :host(cfc-expanding-row-details-content) { display: block; } .cfc-expanding-row { background: white; border-top: 1 solid black; box-shadow: 0 1 1 gray; transition: margin 1 1; will-change: margin; } .cfc-expanding-row.cfc-expanding-row-is-expanded { margin: 1 (-1); } .cfc-expanding-row:focus { outline: none; } .cfc-expanding-row-summary { display: flex; border-left: 6 solid transparent; cursor: pointer; padding: 6 2; } .cfc-expanding-row-summary:focus { outline: none; border-left-color: $cfc-color-active; } // Adjust icons to be positioned correctly in the row. .cfc-expanding-row-summary::ng-deep cfc-icon { margin-top: 3; } .cfc-expanding-row-details-caption { display: flex; cursor: pointer; padding: 4 2; } .cfc-expanding-row-details-caption::ng-deep a, .cfc-expanding-row-details-caption::ng-deep a:visited, .cfc-expanding-row-details-caption::ng-deep a .cfc-external-link-content { border-color: $cfc-color-text-primary-inverse; color: $cfc-color-text-primary-inverse; } // Adjust icons to be positioned correctly in the row. ::ng-deep cfc-icon { margin-top: 3; } .cfc-expanding-row-details-content { padding: 2; } .cfc-expanding-row-details-content::ng-deep .ace-kv-list.cfc-full-bleed { width: 200px; } .cfc-expanding-row-accessibility-text { display: none; }`;
{ "end_byte": 1878, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_css.ts" }
angular/modules/benchmarks/src/expanding_rows/benchmarkable_expanding_row_module.ts_0_619
/** * @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 {CommonModule} from '@angular/common'; import {NgModule} from '@angular/core'; import {BenchmarkableExpandingRow} from './benchmarkable_expanding_row'; import {ExpandingRowModule} from './expanding_row_module'; @NgModule({ declarations: [BenchmarkableExpandingRow], exports: [BenchmarkableExpandingRow], imports: [CommonModule, ExpandingRowModule], }) export class BenchmarkableExpandingRowModule {}
{ "end_byte": 619, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/benchmarkable_expanding_row_module.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_module.ts_0_1177
/** * @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 {CommonModule} from '@angular/common'; import {NgModule} from '@angular/core'; import {ExpandingRow} from './expanding_row'; import {ExpandingRowDetailsCaption} from './expanding_row_details_caption'; import {ExpandingRowDetailsContent} from './expanding_row_details_content'; import {ExpandingRowHost} from './expanding_row_host'; import {ExpandingRowSummary} from './expanding_row_summary'; import {ExpandingRowUncollapsible} from './expanding_row_uncollapsible'; /** The main module for the cfc-expanding-row component. */ @NgModule({ declarations: [ ExpandingRow, ExpandingRowDetailsCaption, ExpandingRowDetailsContent, ExpandingRowHost, ExpandingRowSummary, ExpandingRowUncollapsible, ], exports: [ ExpandingRow, ExpandingRowDetailsCaption, ExpandingRowDetailsContent, ExpandingRowHost, ExpandingRowSummary, ExpandingRowUncollapsible, ], imports: [CommonModule], }) export class ExpandingRowModule {}
{ "end_byte": 1177, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_module.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_summary.ts_0_7523
/** * @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 { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Host, HostListener, OnDestroy, ViewChild, } from '@angular/core'; import {Subscription} from 'rxjs'; import {ExpandingRow} from './expanding_row'; import {expanding_row_css} from './expanding_row_css'; const KEY_CODE_TAB = 9; /** * This component should be used within cfc-expanding-row component. Note that * summary is visible only when the row is collapsed. */ @Component({ selector: 'cfc-expanding-row-summary', styles: [expanding_row_css], template: ` <div *ngIf="!expandingRow.isExpanded" #expandingRowSummaryMainElement class="cfc-expanding-row-summary" tabindex="-1" (click)="expandingRow.handleSummaryClick()" (focus)="handleFocus()" > <ng-content></ng-content> <div class="cfc-expanding-row-accessibility-text">.</div> <div class="cfc-expanding-row-accessibility-text" i18n="This is the label used to indicate that the user is in a list of expanding rows." > Row {{ expandingRow.index + 1 }} in list of expanding rows. </div> <div *ngIf="isPreviouslyFocusedRow()" class="cfc-expanding-row-accessibility-text" i18n="This is the label used for the first row in list of expanding rows." > Use arrow keys to navigate. </div> </div>`, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, }) export class ExpandingRowSummary implements OnDestroy { /** * A reference to the main element. This element should be focusable. We need * reference to compute collapsed height of the row. We also use this * reference for focus and blur methods below. */ @ViewChild('expandingRowSummaryMainElement') mainElementRef!: ElementRef; /** Subscription for changes in parent isExpanded property. */ private isExpandedSubscription: Subscription; /** Subscription for changes in parent index property. */ private indexSubscription: Subscription; /** * We need the parent cfc-expanding-row component here to hide this element * when the row is expanded. cfc-expanding-row-details-caption element * will act as a header for expanded rows. We also need to relay tab-in and * click events to the parent. */ constructor( @Host() public expandingRow: ExpandingRow, changeDetectorRef: ChangeDetectorRef, ) { this.expandingRow.summaryViewChild = this; this.isExpandedSubscription = this.expandingRow.isExpandedChange.subscribe(() => { changeDetectorRef.markForCheck(); }); this.indexSubscription = this.expandingRow.indexChange.subscribe(() => { changeDetectorRef.markForCheck(); }); } /** When component is destroyed, unlisten to isExpanded. */ ngOnDestroy(): void { if (this.isExpandedSubscription) { this.isExpandedSubscription.unsubscribe(); } if (this.indexSubscription) { this.indexSubscription.unsubscribe(); } } /** * Handles focus event on the element. We basically want to detect any focus * in this component and relay this information to parent cfc-expanding-row * component. */ handleFocus(): void { // Clicking causes a focus event to occur before the click event. Filter // out click events using the cdkFocusMonitor. // // TODO(b/62385992) Use the KeyboardFocusService to detect focus cause // instead of creating multiple monitors on a page. if ( this.expandingRow.expandingRowMainElement.nativeElement.classList.contains( 'cdk-mouse-focused', ) ) { return; } if (!this.expandingRow.isFocused && !this.expandingRow.isExpanded) { this.expandingRow.handleSummaryFocus(); } } /** * Handles tab & shift+tab presses on expanding row summaries in case there * are tabbable elements inside the summaries. */ @HostListener('keydown', ['$event']) handleKeyDown(event: KeyboardEvent) { const charCode = event.which || event.keyCode; if (charCode === KEY_CODE_TAB) { this.handleTabKeypress(event); } } /** * Handles tab and shift+tab presses inside expanding row summaries; * * From inside collapsed row summary: * - Tab: If focus was on the last focusable child, should shift focus to * the next focusable element outside the list of expanding rows. * - Shift+tab: If focus was on first focusable child, should shift focus to * the main collapsed row summary element * If focus was on main collapsed row summary element, should * shift focus to the last focusable element before the list of * expanding rows. */ handleTabKeypress(event: KeyboardEvent): void { const focusableChildren = this.getFocusableChildren(); if (focusableChildren.length === 0) { return; } // Shift+tab on expanding row summary should focus on last focusable element // before expanding row list. Otherwise, if shift+tab is pressed on first // focusable child inside expanding row summary, it should focus on main // expanding row summary element. if (event.shiftKey && document.activeElement === this.mainElementRef.nativeElement) { event.preventDefault(); this.expandingRow.expandingRowHost.focusOnPreviousFocusableElement(); return; } else if (event.shiftKey && document.activeElement === focusableChildren[0]) { event.preventDefault(); this.expandingRow.focus(); } // If tab is pressed on the last focusable element inside an expanding row // summary, focus should be set to the next focusable element after the list // of expanding rows. if ( !event.shiftKey && document.activeElement === focusableChildren[focusableChildren.length - 1] ) { event.preventDefault(); this.expandingRow.expandingRowHost.focusOnNextFocusableElement(); } } /** * Finds the row that had focus before focus left the list of expanding rows * and checks if the current row summary is that row. */ isPreviouslyFocusedRow(): boolean { if (!this.expandingRow.expandingRowHost.contentRows) { return false; } const expandingRowHost = this.expandingRow.expandingRowHost; if (!this.mainElementRef || !expandingRowHost.lastFocusedRow) { return false; } if (!expandingRowHost.lastFocusedRow.summaryViewChild.mainElementRef) { return false; } // If the current expanding row summary was the last focused one before // focus exited the list, then return true to trigger the screen reader if ( this.mainElementRef.nativeElement === expandingRowHost.lastFocusedRow.summaryViewChild.mainElementRef.nativeElement ) { return true; } return false; } /** Puts the DOM focus on the main element. */ focus(): void { if (this.mainElementRef && document.activeElement !== this.mainElementRef.nativeElement) { this.mainElementRef.nativeElement.focus(); } } /** Removes the DOM focus on the main element. */ blur(): void { if (!this.mainElementRef) { return; } this.mainElementRef.nativeElement.blur(); } /** Returns array of focusable elements within this component. */ private getFocusableChildren(): HTMLElement[] { return []; } }
{ "end_byte": 7523, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_summary.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_host.ts_0_1890
/** * @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 { AfterContentInit, AfterViewInit, ChangeDetectionStrategy, Component, ContentChildren, ElementRef, EventEmitter, forwardRef, HostListener, Input, OnDestroy, Output, QueryList, ViewChild, } from '@angular/core'; import {Subscription} from 'rxjs'; import { EXPANDING_ROW_HOST_INJECTION_TOKEN, ExpandingRow, ExpandingRowHostBase, } from './expanding_row'; /** * We use this class in <cfc-expanding-row/> template to identify the row. * The [cfcExpandingRowHost] directive also uses this class to check if a given * HTMLElement is within an <cfc-expanding-row/>. */ const EXPANDING_ROW_CLASS_NAME = 'cfc-expanding-row'; /** Throttle duration in milliseconds for repeated key presses. */ export const EXPANDING_ROW_KEYPRESS_THORTTLE_MS = 50; /** * This type union is created to make arguments of handleUpOrDownPress* * methods in ExpandingRowHost class more readable. */ type UpOrDown = 'up' | 'down'; /** * This is the wrapper directive for the cfc-expanding-row components. Note that * we wanted to make this a directive instead of component because child * cfc-expanding-row components does not have to be a direct child. */ @Component({ selector: 'cfc-expanding-row-host', template: ` <div #firstFocusable (focus)="focusOnLastFocusedRow()" tabindex="0"></div> <ng-content></ng-content> <div #lastFocusable (focus)="focusOnLastFocusedRow()" tabindex="0"></div>`, changeDetection: ChangeDetectionStrategy.OnPush, providers: [{provide: EXPANDING_ROW_HOST_INJECTION_TOKEN, useExisting: ExpandingRowHost}], standalone: false, }) export class ExpandingRowHost implements AfterViewInit, OnDestroy, ExpandingRowHostBase
{ "end_byte": 1890, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_host.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_host.ts_1891_10418
{ /** * An HTML selector (e.g. "body") for the scroll element. We need this to * make some scroll adjustments. */ @Input() scrollElementSelector = '.cfc-panel-body-scrollable'; /** * An HTML selector (e.g. "body") for the click root. While the row is * expanded, and user clicks outside of the expanded row, we collapse this row * But to do this, we need to know the clickable area. */ @Input() clickRootElementSelector = 'cfc-panel-body'; /** * The @Output will be triggered when the user wants to focus on the * previously expanded row, and we are already at the first row. The logs team * will use this to prepend data on demand. */ @Output() onPrepend = new EventEmitter<void>(); /** A reference to the last focusable element in list of expanding rows. */ @ViewChild('lastFocusable', {static: true}) lastFocusableElement!: ElementRef; /** A reference to the first focusable element in list of expanding rows. */ @ViewChild('firstFocusable', {static: true}) firstFocusableElement!: ElementRef; /** * A reference to all child cfc-expanding-row elements. We will need for * keyboard accessibility and scroll adjustments. For example, we need to know * which row is previous row when user presses "left arrow" on a focused row. */ @ContentChildren(forwardRef(() => ExpandingRow), {descendants: true}) contentRows!: QueryList<ExpandingRow>; /** * Keeps track of the last row that had focus before focus left the list * of expanding rows. */ lastFocusedRow?: ExpandingRow = undefined; /** * Focused rows just show a blue left border. This node is not expanded. We * need to keep a reference to the focused row to unfocus when another row * is focused. */ private focusedRow?: ExpandingRow = undefined; /** * This is the expanded row. If there is an expanded row there shouldn't be * any focused rows. We need a reference to this. For example we need to * collapse the currently expanded row, if another row is expanded. */ private expandedRow?: ExpandingRow = undefined; /** * This is just handleRootMouseUp.bind(this). handleRootMouseUp handles * click events on root element (defined by clickRootElementSelector @Input) * Since we attach the click listener dynamically, we need to keep this * function around. This enables us to detach the click listener when * component is destroyed. */ private handleRootMouseUpBound = this.handleRootMouseUp.bind(this); /** * 16px is the margin animation we have on cfc-expanding-row component. * We need this value to compute scroll adjustments. */ private static rowMargin = 16; /** Subscription to changes in the expanding rows. */ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. private rowChangeSubscription!: Subscription; /** * When component initializes we need to attach click listener to the root * element. This click listener will allows us to collapse the * currently expanded row when user clicks outside of it. */ ngAfterViewInit(): void { const clickRootElement: HTMLElement = this.getClickRootElement(); if (!clickRootElement) { return; } clickRootElement.addEventListener('mouseup', this.handleRootMouseUpBound); this.rowChangeSubscription = this.contentRows.changes.subscribe(() => { this.recalcRowIndexes(); }); this.recalcRowIndexes(); } /** * Detaches the click listener on the root element. Note that we are attaching * this listener on ngAfterViewInit function. */ ngOnDestroy(): void { const clickRootElement: HTMLElement = this.getClickRootElement(); if (!clickRootElement) { return; } clickRootElement.removeEventListener('mouseup', this.handleRootMouseUpBound); if (this.rowChangeSubscription) { this.rowChangeSubscription.unsubscribe(); } } /** * Handles caption element click on a cfc-expanding-row component. Note * that caption element is visible only when the row is expanded. So this * means we will collapse the expanded row. The scroll adjustment below * makes sure that the mouse stays under the summary of the expanded row * when the row collapses. */ handleRowCaptionClick(row: ExpandingRow): void { const scrollAdjustment: number = -ExpandingRowHost.rowMargin; const scrollElement: HTMLElement = this.getScrollElement() as HTMLElement; if (!scrollElement) { return; } scrollElement.scrollTop += scrollAdjustment; } /** * Handles summary element click on a cfc-expanding-row component. Note * that summary element is visible only when the row is collapsed. So this * event will fired prior to expansion of a collapsed row. Scroll adjustment * below makes sure mouse stays on the caption element when the collapsed * row expands. */ handleRowSummaryClick(row: ExpandingRow): void { const hadPreviousSelection: boolean = !!this.expandedRow; const previousSelectedRowIndex: number = this.getRowIndex(this.expandedRow as ExpandingRow); const newSelectedRowIndex: number = this.getRowIndex(row); const previousCollapsedHeight: number = this.getSelectedRowCollapsedHeight(); const previousExpansionHeight = this.getSelectedRowExpandedHeight(); if (this.expandedRow) { return; } let scrollAdjustment = 0; const scrollElement: HTMLElement = this.getScrollElement() as HTMLElement; if (!scrollElement) { return; } if (previousExpansionHeight > 0 && previousCollapsedHeight >= 0) { scrollAdjustment = previousExpansionHeight - previousCollapsedHeight; } const newSelectionIsInfrontOfPrevious: boolean = newSelectedRowIndex > previousSelectedRowIndex; const multiplier = newSelectionIsInfrontOfPrevious ? -1 : 0; scrollAdjustment = scrollAdjustment * multiplier + ExpandingRowHost.rowMargin; scrollElement.scrollTop += scrollAdjustment; } /** * Handles expansion of a row. When a new row expands, we need to remove * previous expansion and collapse. We also need to save the currently * expanded row so that we can collapse this row once another row expands. */ handleRowExpand(row: ExpandingRow): void { this.removePreviousFocus(); this.removePreviousExpansion(); this.expandedRow = row; } /** * Handles focus on a row. When a new row gets focus (note that this is * different from expansion), we need to remove previous focus and expansion. * We need to save the reference to this focused row so that we can unfocus * this row when another row is focused. */ handleRowFocus(row: ExpandingRow): void { // Do not blur then refocus the row if it's already selected. if (row === this.focusedRow) { return; } this.removePreviousFocus(); this.removePreviousExpansion(); this.focusedRow = row; } /** * Called when shift+tabbing from the first focusable element after the list * of expanding rows or tabbing from the last focusable element before. */ focusOnLastFocusedRow(): void { if (!this.lastFocusedRow) { this.lastFocusedRow = this.contentRows.toArray()[0]; } this.lastFocusedRow.focus(); } /** * Function that is called by expanding row summary to focus on the last * focusable element before the list of expanding rows. */ focusOnPreviousFocusableElement(): void { this.lastFocusedRow = this.focusedRow; } /** * Function that is called by expanding row summary to focus on the next * focusable element after the list of expanding rows. */ focusOnNextFocusableElement(): void { this.lastFocusedRow = this.focusedRow; } /** * Handles keydown event on the host. We are just concerned with up, * down arrow, ESC, and ENTER presses here. Note that Up/Down presses * can be repeated. * * - Up: Focuses on the row above. * - Down: Focuses on the row below. * - Escape: Collapses the expanded row. * - Enter: Expands the focused row. */ @HostListener('keydown', ['$event']) handleKeyDown(event: KeyboardEvent) {} /** * Recursively returns true if target HTMLElement is within a * cfc-expanding-row component. It will return false otherwise. * We need this function in handleRootMouseUp to collapse the expanded row * when user clicks outside of all expanded rows. */ private isTargetInRow(target: HTMLElement): boolean { return target.classList.contains(EXPANDING_ROW_CLASS_NAME); }
{ "end_byte": 10418, "start_byte": 1891, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_host.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_host.ts_10422_16750
/** * Gets the click root element that is described by clickRootElementSelector * @Input value. */ private getClickRootElement(): HTMLElement { return document.querySelector(this.clickRootElementSelector) as HTMLElement; } /** * Handles all of the mouseup events on the click root. When user clicks * outside of an expanded row, we need to collapse that row. * We trigger collapse by calling handleCaptionClick() on the expanded row. */ private handleRootMouseUp(event: MouseEvent): void { if (!this.expandedRow) { return; } if (!this.isTargetInRow(event.target as {} as HTMLElement)) { this.expandedRow.handleCaptionClick(event); } } /** * Check if element is collapsible. Elements marked as uncollapsible will not collapse an * open row when clicked. */ isCollapsible(element: HTMLElement | null): boolean { const clickRoot = this.getClickRootElement(); while (element && element !== clickRoot) { if (element.hasAttribute('cfcUncollapsible')) { return false; } element = element.parentElement; } return true; } /** * Removes focus state from a previously focused row. We blur this row and * set the focusedRow to undefined in this method. This usually happens when * another row is focused. */ private removePreviousFocus(): void { if (this.focusedRow) { this.focusedRow.blur(); this.focusedRow = undefined; } } /** * Removes the expanded state from a previously expanded row. We collapse this * row and set the expandedRow to undefined in this method. This usually * happens when another row is expanded. */ private removePreviousExpansion(): void { if (this.expandedRow) { this.expandedRow.collapse(); this.expandedRow = undefined; } } /** * Gets the collapsed height of the currently expanded row. We need this for * scroll adjustments. Note that collapsed height of a cfc-expanding-row * component is equal to height of cfc-expanding-row-summary component within * the row. */ private getSelectedRowCollapsedHeight(): number { if (this.expandedRow) { return this.expandedRow.collapsedHeight; } else { return -1; } } /** * Gets the current height of the expanded row. We need this value for the * scroll adjustment computation. */ private getSelectedRowExpandedHeight(): number { if (this.expandedRow) { return this.expandedRow.getHeight(); } else { return -1; } } /** * Gets the HTML element described by scrollElementSelector @Input value. * We need this value for scroll adjustments. */ private getScrollElement(): HTMLElement | undefined { if (!this.scrollElementSelector) { return undefined; } return document.querySelector(this.scrollElementSelector) as HTMLElement; } /** * Handles escape presses on the host element. Escape removes previous focus * if there is one. If there is an expanded row, escape row collapses this * row and focuses on it. A subsequent escape press will blur this row. */ private handleEscapePress(): void { this.removePreviousFocus(); if (this.expandedRow) { this.expandedRow.collapse(); this.expandedRow.focus(); this.expandedRow = undefined; } } /** * Handles enter keypress. If there is a focused row, an enter key press on * host element will expand this row. */ private handleEnterPress(): void { if (document.activeElement !== this.focusedRowSummary()) { return; } if (this.focusedRow) { this.focusedRow.expand(); } } /** Returns the HTMLElement that is the currently focused row summary. */ private focusedRowSummary(): HTMLElement | undefined { return this.focusedRow ? this.focusedRow.summaryViewChild.mainElementRef.nativeElement : undefined; } /** * Returns the index of a given row. This enables us to figure out the row * above/below the focused row. */ private getRowIndex(rowToLookFor: ExpandingRow): number { return rowToLookFor ? rowToLookFor.index : -1; } /** * Handles up/down arrow presses on the host element. Up arrow press will * focus/expand on the row above. Down arrow press will focus/expand the row * below. If we have a focus on the current row, this function will focus on * the computed (the one above or below) row. If host has an expanded row, * this function will expand the computed row. */ private handleUpOrDownPressOnce(upOrDown: UpOrDown, event: KeyboardEvent): void { event.preventDefault(); // If row is expanded but focus is inside the expanded element, arrow // key presses should not do anything. if ( this.expandedRow && document.activeElement !== this.expandedRow.expandingRowMainElement.nativeElement ) { return; } // If focus is inside a collapsed row header, arrow key presses should not // do anything. if (this.focusedRow && document.activeElement !== this.focusedRowSummary()) { return; } // We only want screen reader to read the message the first time we enter // the list of expanding rows, so we must reset the variable here this.lastFocusedRow = undefined; const rowToLookFor: ExpandingRow | undefined = this.expandedRow || this.focusedRow; if (!rowToLookFor) { return; } const isFocus: boolean = rowToLookFor === this.focusedRow; const rowIndex: number = this.getRowIndex(rowToLookFor); const contentRowsArray: ExpandingRow[] = this.contentRows.toArray(); if (rowIndex < 0) { return; } const potentialIndex: number = (upOrDown === 'up' ? -1 : +1) + rowIndex; if (potentialIndex < 0) { this.onPrepend.emit(); return; } if (potentialIndex >= contentRowsArray.length) { return; } const potentialRow: ExpandingRow = contentRowsArray[potentialIndex]; if (isFocus) { potentialRow.focus(); } else { potentialRow.expand(); } } // Updates all of the rows with their new index. private recalcRowIndexes() { let index = 0; setTimeout(() => { this.contentRows.forEach((row: ExpandingRow) => { row.index = index++; }); }); } }
{ "end_byte": 16750, "start_byte": 10422, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_host.ts" }
angular/modules/benchmarks/src/expanding_rows/BUILD.bazel_0_1484
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module", "ts_library") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "application_lib", srcs = glob( ["**/*.ts"], exclude = ["**/*.perf-spec.ts"], ), deps = [ "//packages:types", "//packages/common", "//packages/core", "//packages/localize/init", "//packages/platform-browser", "@npm//rxjs", ], ) ts_library( name = "perf_lib", testonly = 1, srcs = ["expanding_rows.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], ) app_bundle( name = "bundle", entry_point = ":index_aot.ts", deps = [ ":application_lib", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = [ ":perf_lib", ], )
{ "end_byte": 1484, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/BUILD.bazel" }
angular/modules/benchmarks/src/expanding_rows/expanding_rows.perf-spec.ts_0_654
/** * @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 {runBenchmark} from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$, browser} from 'protractor'; describe('benchmarks', () => { it('should work for create', async () => { browser.rootEl = '#root'; await runBenchmark({ id: 'create', url: '', ignoreBrowserSynchronization: true, params: [], prepare: () => $('#reset').click(), work: () => $('#init').click(), }); }); });
{ "end_byte": 654, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_rows.perf-spec.ts" }
angular/modules/benchmarks/src/expanding_rows/benchmark.ts_0_2327
/** * @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 {CommonModule} from '@angular/common'; import {AfterViewInit, Component, NgModule, ViewChild, ViewEncapsulation} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {BenchmarkModule} from './benchmark_module'; import {BenchmarkableExpandingRow} from './benchmarkable_expanding_row'; import {BenchmarkableExpandingRowModule} from './benchmarkable_expanding_row_module'; @Component({ selector: 'benchmark-root', encapsulation: ViewEncapsulation.None, template: ` <h2>cfc-expanding-row initialization benchmark</h2> <section> <button id="reset" (click)="reset()">Reset</button> <button id="init" (click)="init()">Init</button> <button id="run" (click)="runAll()">Run All</button> </section> <benchmark-area> <benchmarkable-expanding-row></benchmarkable-expanding-row> </benchmark-area>`, standalone: false, }) export class InitializationRoot implements AfterViewInit { @ViewChild(BenchmarkableExpandingRow, {static: true}) expandingRow!: BenchmarkableExpandingRow; ngAfterViewInit() {} reset() { this.expandingRow.reset(); } init() { this.expandingRow.init(); } async runAll() { await execTimed('initialization_benchmark', async () => { await this.doInit(); }); } async handleInitClick() { await this.doInit(); } private async doInit() { await execTimed('initial_load', async () => { this.expandingRow.init(); }); } } @NgModule({ declarations: [InitializationRoot], exports: [InitializationRoot], imports: [CommonModule, BenchmarkableExpandingRowModule, BenchmarkModule, BrowserModule], bootstrap: [InitializationRoot], }) // Component benchmarks must export a BenchmarkModule. export class ExpandingRowBenchmarkModule {} export async function execTimed(description: string, func: () => Promise<void>) { console.time(description); await func(); await nextTick(200); console.timeEnd(description); } export async function nextTick(delay = 1) { return new Promise<void>((res, rej) => { setTimeout(() => { res(); }, delay); }); }
{ "end_byte": 2327, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/benchmark.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row.ts_0_4036
/** * @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 { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, HostListener, Inject, InjectionToken, Input, Output, QueryList, ViewChild, } from '@angular/core'; import {expanding_row_css} from './expanding_row_css'; import {ExpandingRowSummary} from './expanding_row_summary'; import {ExpandingRowToggleEvent} from './expanding_row_toggle_event'; /** * Injection token to break cylic dependency between ExpandingRow and * ExpandingRowHost */ export const EXPANDING_ROW_HOST_INJECTION_TOKEN = new InjectionToken<ExpandingRowHostBase>( 'ExpandingRowHost', ); /** The base class for ExpandingRowHost component to break cylic dependency. */ export interface ExpandingRowHostBase { /** * A reference to all child cfc-expanding-row elements. We will need for * keyboard accessibility and scroll adjustments. For example, we need to know * which row is previous row when user presses "left arrow" on a focused row. */ contentRows: QueryList<ExpandingRow>; /** * Keeps track of the last row that had focus before focus left the list * of expanding rows. */ lastFocusedRow?: ExpandingRow; /** * Handles summary element click on a cfc-expanding-row component. Note * that summary element is visible only when the row is collapsed. So this * event will fired prior to expansion of a collapsed row. Scroll adjustment * below makes sure mouse stays on the caption element when the collapsed * row expands. */ handleRowSummaryClick(row: ExpandingRow): void; /** * Check if element is collapsible. Elements marked as uncollapsible will not collapse an * open row when clicked. */ isCollapsible(element: HTMLElement | null): boolean; /** * Handles caption element click on a cfc-expanding-row component. Note * that caption element is visible only when the row is expanded. So this * means we will collapse the expanded row. The scroll adjustment below * makes sure that the mouse stays under the summary of the expanded row * when the row collapses. */ handleRowCaptionClick(row: ExpandingRow): void; /** * Handles expansion of a row. When a new row expands, we need to remove * previous expansion and collapse. We also need to save the currently * expanded row so that we can collapse this row once another row expands. */ handleRowExpand(row: ExpandingRow): void; /** * Handles focus on a row. When a new row gets focus (note that this is * different from expansion), we need to remove previous focus and expansion. * We need to save the reference to this focused row so that we can unfocus * this row when another row is focused. */ handleRowFocus(row: ExpandingRow): void; /** * Function that is called by expanding row summary to focus on the last * focusable element before the list of expanding rows. */ focusOnPreviousFocusableElement(): void; /** * Function that is called by expanding row summary to focus on the next * focusable element after the list of expanding rows. */ focusOnNextFocusableElement(): void; } /** * This component is used to render a single expanding row. It should contain * cfc-expanding-row-summary, cfc-expanding-row-details-caption and * cfc-expanding-row-details-content components. */ @Component({ selector: 'cfc-expanding-row', styles: [expanding_row_css], template: ` <div #expandingRowMainElement class="cfc-expanding-row" cdkMonitorSubtreeFocus [attr.tabindex]="isExpanded ? '0' : '-1'" [class.cfc-expanding-row-has-focus]="isFocused" [class.cfc-expanding-row-is-expanded]="isExpanded" ve="CfcExpandingRow" > <ng-content></ng-content> </div>`, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, }) export
{ "end_byte": 4036, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row.ts_4037_12318
class ExpandingRow { /** * The identifier for this node provided by the user code. We need this * while we are emitting onToggle event. */ @Input() rowId!: string; /** * An ElementRef to the main element in this component. We need a reference * to this element to compute the height. The height of cfc-expanding-row * is used in [cfcExpandingRowHost] directive for scroll adjustments. */ @ViewChild('expandingRowMainElement', {static: true}) expandingRowMainElement!: ElementRef; /** * This @Output event emitter will be triggered when the user expands or * collapses this node. */ @Output() onToggle = new EventEmitter<ExpandingRowToggleEvent>(); /** * A boolean indicating if this node is expanded. This value is used to * hide/show summary, caption, and content of the expanding row. There should * only be one expanded row within [cfcExpandingRowHost] directive. And if * there is an expanded row, there shouldn't be any focused rows. */ set isExpanded(value: boolean) { const changed: boolean = this.isExpandedInternal !== value; this.isExpandedInternal = value; if (changed) { this.isExpandedChange.emit(); this.changeDetectorRef.markForCheck(); } } /** TS getter for isExpanded property. */ get isExpanded(): boolean { return this.isExpandedInternal; } /** Triggered when isExpanded property changes. */ isExpandedChange = new EventEmitter<void>(); /** Triggered when index property changes. */ indexChange = new EventEmitter<void>(); /** * A boolean indicating if this node is focused. This value is used to add * a CSS class that should render a blue border on the right. There should * only be one focused row in [cfcExpandingRowHost] directive. */ set isFocused(value: boolean) { this.isFocusedInternal = value; this.changeDetectorRef.markForCheck(); } /** TS getter for isFocused property. */ get isFocused(): boolean { return this.isFocusedInternal; } /** The index of the row in the context of the entire collection. */ set index(value: number) { const changed: boolean = this.indexInternal !== value; this.indexInternal = value; if (changed) { this.indexChange.emit(); this.changeDetectorRef.markForCheck(); } } /** TS getter for index property. */ get index(): number { return this.indexInternal; } /** * We should probably rename this to summaryContentChild. Because technically * this is not a @ViewChild that is in a template. This will be transcluded. * Note that we are not using @ContentChild directive here. The @ContentChild * will cause cyclic reference if the class definition for ExpandingRowSummary * component is not in the same file as ExpandingRow. */ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. summaryViewChild!: ExpandingRowSummary; /** * We compute the collapsed height (which is just height of * cfc-expanding-row-summary component) in this component. This is used in * [cfcExpandingRowHost] for scroll adjustment calculation. */ collapsedHeight = -1; /** Internal storage for isExpanded public property. */ private isExpandedInternal = false; /** Internal storage for isFocused public property. */ private isFocusedInternal = false; /** Internal storage for index public property. */ // TODO(b/109816955): remove '!', see go/strict-prop-init-fix. private indexInternal!: number; /** * This holds a reference to [cfcExpandingRowHost] directive. We need * this reference to notify the host when this row expands/collapses or is * focused. */ constructor( public elementRef: ElementRef, @Inject(EXPANDING_ROW_HOST_INJECTION_TOKEN) public expandingRowHost: ExpandingRowHostBase, private readonly changeDetectorRef: ChangeDetectorRef, ) {} /** * Handles click on cfc-expanding-row-summary component. This will expand * this row and collapse the previously expanded row. The collapse & blur * is handled in [cfcExpandingRowHost] directive. */ handleSummaryClick(): void { this.collapsedHeight = this.elementRef.nativeElement.querySelector( '.cfc-expanding-row-summary', ).offsetHeight; this.expandingRowHost.handleRowSummaryClick(this); this.expand(); } /** * When user tabs into child cfc-expanding-row-summary component. This method * will make sure we focuse on this row, and blur on previously focused row. */ handleSummaryFocus(): void { this.focus(); } /** * cfc-expanding-row-details-caption component will call this function to * notify click on its host element. Note that caption is only shown when * the row is expanded. Hence this will collapse this row and put the focus * on it. * If an uncollapsible element exists in the caption, clicking that element will * not trigger the row collapse. */ handleCaptionClick(event: MouseEvent): void { if (this.expandingRowHost.isCollapsible(event.target as {} as HTMLElement)) { this.expandingRowHost.handleRowCaptionClick(this); this.collapse(); this.focus(); } } /** * Gets the height of this component. This height is used in parent * [cfcExpandingRowHost] directive to compute scroll adjustment. */ getHeight(): number { return this.expandingRowMainElement.nativeElement.offsetHeight; } /** * Expands this row. This will notify the host so that it can collapse * previously expanded row. This function also emits onToggle @Output event * to the user code. */ expand(): void { this.isExpanded = true; this.expandingRowHost.handleRowExpand(this); // setTimeout here makes sure we scroll this row into view after animation. setTimeout(() => { this.expandingRowMainElement.nativeElement.focus(); }); this.onToggle.emit({rowId: this.rowId, isExpand: true}); } /** * Collapses this row. Setting isExpanded to false will make sure we hide * the caption and details, and show cfc-expanding-row-summary component. * This also emits onToggle @Output event to the user code. */ collapse(): void { this.isExpanded = false; this.onToggle.emit({rowId: this.rowId, isExpand: false}); } /** * Blurs this row. This should remove the blue border on the left if there * is any. This function will remove DOM focus on the * cfc-expanding-row-summary * component. */ blur(): void { this.isFocused = false; this.summaryViewChild.blur(); } /** * Focuses this row. This should put blue border on the left. If there is * any previous focus/selection, those should be gone. Parent * [cfcExpandingRowHost] component takes care of that. */ focus(): void { this.isFocused = true; this.expandingRowHost.handleRowFocus(this); // Summary child is not present currently. We need to NG2 to update the // template. setTimeout(() => { this.summaryViewChild.focus(); }); } /** * We listen for TAB press here to make sure we trap the focus on the * expanded * row. If the row is not expanded, we don't care about this event since focus * trap should work for expanded rows only. */ @HostListener('keydown', ['$event']) handleKeyDown(event: KeyboardEvent) { const charCode = event.which || event.keyCode; switch (charCode) { case 9: if (!this.isExpanded) { return; } this.trapFocus(event); break; default: break; } } /** * When this row is expanded, this function traps the focus between focusable * elements contained in this row. */ private trapFocus(event: KeyboardEvent): void { const rowElement: HTMLElement = this.expandingRowMainElement.nativeElement; const focusableEls: HTMLElement[] = []; let lastFocusableEl: HTMLElement = rowElement; if (focusableEls.length) { lastFocusableEl = focusableEls[focusableEls.length - 1]; } if (event.target === lastFocusableEl && !event.shiftKey) { rowElement.focus(); event.preventDefault(); } else if (event.target === rowElement && event.shiftKey) { lastFocusableEl.focus(); event.preventDefault(); } } }
{ "end_byte": 12318, "start_byte": 4037, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_toggle_event.ts_0_564
/** * @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 */ /** * This interface is used to send toggle (expand/collapse) events to the user * code. */ export interface ExpandingRowToggleEvent { /** The identifier of the row that was toggled. */ rowId: string; /** * A boolean indicating whether or not this row was expanded. This is set to * false if the row was collapsed. */ isExpand: boolean; }
{ "end_byte": 564, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_toggle_event.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_uncollapsible.ts_0_457
/** * @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 {Directive} from '@angular/core'; /** * This directive is used to flag an element to NOT trigger collapsing an * expanded row */ @Directive({ selector: '[cfcUncollapsible]', standalone: false, }) export class ExpandingRowUncollapsible {}
{ "end_byte": 457, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_uncollapsible.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_details_caption.ts_0_1863
/** * @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 { ChangeDetectionStrategy, ChangeDetectorRef, Component, Host, Input, OnDestroy, } from '@angular/core'; import {Subject} from 'rxjs'; import {takeUntil} from 'rxjs/operators'; import {ExpandingRow} from './expanding_row'; import {expanding_row_css} from './expanding_row_css'; /** * This component should be within cfc-expanding-row component. The caption * is only visible when the row is expanded. */ @Component({ selector: 'cfc-expanding-row-details-caption', styles: [expanding_row_css], template: ` <div *ngIf="expandingRow.isExpanded" (click)="expandingRow.handleCaptionClick($event)" [style.backgroundColor]="color" class="cfc-expanding-row-details-caption" > <ng-content></ng-content> </div>`, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, }) export class ExpandingRowDetailsCaption implements OnDestroy { /** The background color of this component. */ @Input() color: string = 'blue'; /** This is triggered when this component is destroyed. */ private readonly onDestroy = new Subject<void>(); /** * We need a reference to parent cfc-expanding-row component here to hide * this component when the row is collapsed. We also need to relay clicks * to the parent component. */ constructor( @Host() public expandingRow: ExpandingRow, changeDetectorRef: ChangeDetectorRef, ) { this.expandingRow.isExpandedChange.pipe(takeUntil(this.onDestroy)).subscribe(() => { changeDetectorRef.markForCheck(); }); } /** When component is destroyed, unlisten to isExpanded. */ ngOnDestroy(): void { this.onDestroy.next(); } }
{ "end_byte": 1863, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_details_caption.ts" }
angular/modules/benchmarks/src/expanding_rows/benchmark_module.ts_0_1257
/** * @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 {Component, ErrorHandler, Injectable, NgModule} from '@angular/core'; @Component({ selector: 'benchmark-area', template: '<ng-content></ng-content>', styles: [ ` :host { padding: 1; margin: 1; background-color: white; width: 1000px; display: block; } `, ], host: { 'class': 'cfc-ng2-region', }, standalone: false, }) export class BenchmarkArea {} declare interface ExtendedWindow extends Window { benchmarkErrors?: string[]; } const extendedWindow = window as ExtendedWindow; @Injectable({providedIn: 'root'}) export class BenchmarkErrorHandler implements ErrorHandler { handleError(error: Error) { if (!extendedWindow.benchmarkErrors) { extendedWindow.benchmarkErrors = []; } extendedWindow.benchmarkErrors.push(error.message); console.error(error); } } @NgModule({ declarations: [BenchmarkArea], exports: [BenchmarkArea], providers: [{provide: ErrorHandler, useClass: BenchmarkErrorHandler}], }) export class BenchmarkModule {}
{ "end_byte": 1257, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/benchmark_module.ts" }
angular/modules/benchmarks/src/expanding_rows/expanding_row_details_content.ts_0_1636
/** * @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 { ChangeDetectionStrategy, ChangeDetectorRef, Component, Host, OnDestroy, } from '@angular/core'; import {Subscription} from 'rxjs'; import {ExpandingRow} from './expanding_row'; import {expanding_row_css} from './expanding_row_css'; /** * This component should be within cfc-expanding-row component. Note that the * content is visible only when the row is expanded. */ @Component({ styles: [expanding_row_css], selector: 'cfc-expanding-row-details-content', template: ` <div class="cfc-expanding-row-details-content" *ngIf="expandingRow.isExpanded"> <ng-content></ng-content> </div>`, changeDetection: ChangeDetectionStrategy.OnPush, standalone: false, }) export class ExpandingRowDetailsContent implements OnDestroy { /** Used for unsubscribing to changes in isExpanded parent property. */ private isExpandedChangeSubscription: Subscription; /** * We need a reference to parent cfc-expanding-row component to make sure we * hide this component if the row is collapsed. */ constructor( @Host() public expandingRow: ExpandingRow, changeDetectorRef: ChangeDetectorRef, ) { this.isExpandedChangeSubscription = this.expandingRow.isExpandedChange.subscribe(() => { changeDetectorRef.markForCheck(); }); } /** Unsubscribe from changes in parent isExpanded property. */ ngOnDestroy(): void { this.isExpandedChangeSubscription.unsubscribe(); } }
{ "end_byte": 1636, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/expanding_rows/expanding_row_details_content.ts" }
angular/modules/benchmarks/src/class_bindings/styles.css_0_50
.hello { color: red; } .bye { color: blue; }
{ "end_byte": 50, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/class_bindings/styles.css" }
angular/modules/benchmarks/src/class_bindings/class_bindings.perf-spec.ts_0_960
/** * @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 {runBenchmark} from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$, browser} from 'protractor'; describe('class bindings perf', () => { it('should work for update', async () => { browser.rootEl = '#root'; await runBenchmark({ id: 'create', url: '', ignoreBrowserSynchronization: true, params: [], prepare: () => $('#destroy').click(), work: () => $('#create').click(), }); }); it('should work for update', async () => { browser.rootEl = '#root'; await runBenchmark({ id: 'update', url: '', ignoreBrowserSynchronization: true, params: [], prepare: () => $('#create').click(), work: () => $('#update').click(), }); }); });
{ "end_byte": 960, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/class_bindings/class_bindings.perf-spec.ts" }
angular/modules/benchmarks/src/class_bindings/app.module.ts_0_586
/** * @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 {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {AppComponent} from './app.component'; import {ClassBindingsComponent} from './class_bindings.component'; @NgModule({ declarations: [AppComponent, ClassBindingsComponent], imports: [BrowserModule], providers: [], bootstrap: [AppComponent], }) export class AppModule {}
{ "end_byte": 586, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/class_bindings/app.module.ts" }
angular/modules/benchmarks/src/class_bindings/app.component.ts_0_1035
/** * @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 {Component} from '@angular/core'; @Component({ selector: 'app-root', template: ` <button id="create" (click)="create()">Create</button> <button id="update" (click)="update()">Update</button> <button id="destroy" (click)="destroy()">Destroy</button> <class-bindings *ngIf="show" [msg]="msg" [list]="list" ><class-bindings> </class-bindings ></class-bindings> `, standalone: false, }) export class AppComponent { show = false; msg = 'hello'; list: {i: number; text: string}[] = []; constructor() { for (let i = 0; i < 1000; i++) { this.list.push({i, text: 'foobar' + i}); } } create() { this.show = true; } update() { this.msg = this.msg === 'hello' ? 'bye' : 'hello'; this.list[0].text = this.msg; } destroy() { this.show = false; } }
{ "end_byte": 1035, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/class_bindings/app.component.ts" }
angular/modules/benchmarks/src/class_bindings/class_bindings.component.ts_0_1011
/** * @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 {Component, Input} from '@angular/core'; @Component({ selector: 'class-bindings', template: ` <div> <p>{{ msg }}</p> <div *ngFor="let obj of list; let i = index" [title]="msg + i"> <span [class]="msg">{{ obj.text }}</span> <span class="baz">one</span> <span class="qux">two</span> <div> <span class="qux">three</span> <span class="qux">four</span> <span class="baz">five</span> <div> <span class="qux">six</span> <span class="baz">seven</span> <span [class]="msg">eight</span> </div> </div> </div> </div> `, standalone: false, }) export class ClassBindingsComponent { @Input() msg: string = ''; @Input() list: string[] | null = null; }
{ "end_byte": 1011, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/class_bindings/class_bindings.component.ts" }
angular/modules/benchmarks/src/class_bindings/BUILD.bazel_0_748
load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) component_benchmark( name = "benchmark", driver = ":class_bindings.perf-spec.ts", driver_deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//@types/jasmine", "@npm//protractor", ], ng_deps = [ "//packages:types", "//packages/common", "//packages/core", "//packages/platform-browser", "@npm//rxjs", ], ng_srcs = glob( ["**/*.ts"], exclude = ["**/*.perf-spec.ts"], ), prefix = "", styles = ["styles.css"], )
{ "end_byte": 748, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/class_bindings/BUILD.bazel" }
angular/modules/benchmarks/src/js-web-frameworks/js-web-frameworks.perf-spec.ts_0_2637
/** * @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 { runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; interface Worker { id: string; prepare?(): void; work(): void; } const Create1KWorker: Worker = { id: 'create1K', prepare: () => $('#deleteAll').click(), work: () => $('#create1KRows').click(), }; const Delete1KWorker: Worker = { id: 'delete1K', prepare: () => $('#create1KRows').click(), work: () => { $('#deleteAll').click(); }, }; const SelectWorker: Worker = { id: 'select', prepare: () => $('#create1KRows').click(), work: () => { $('tbody>tr:nth-of-type(2)>td:nth-of-type(2)>a').click(); }, }; const UpdateWorker: Worker = { id: 'update', prepare: () => $('#create1KRows').click(), work: () => { $('#update').click(); }, }; const SwapWorker: Worker = { id: 'swap', prepare: () => $('#create1KRows').click(), work: () => { $('#swap').click(); }, }; // In order to make sure that we don't change the ids of the benchmarks, we need to // determine the current test package name from the Bazel target. This is necessary // because previous to the Bazel conversion, the benchmark test ids contained the test // name. e.g. "largeTable.ng2_switch.createDestroy". We determine the name of the // Bazel package where this test runs from the current test target. The Bazel target // looks like: "//modules/benchmarks/src/largetable/{pkg_name}:{target_name}". const testPackageName = process.env['BAZEL_TARGET']!.split(':')[0].split('/').pop(); describe('js-web-frameworks benchmark perf', () => { afterEach(verifyNoBrowserErrors); [Create1KWorker, Delete1KWorker, UpdateWorker, SelectWorker, SwapWorker].forEach((worker) => { describe(worker.id, () => { it(`should run benchmark for ${testPackageName}`, async () => { await runTableBenchmark({ id: `js-web-frameworks.${testPackageName}.${worker.id}`, url: '/', ignoreBrowserSynchronization: true, worker: worker, }); }); }); }); }); function runTableBenchmark(config: { id: string; url: string; ignoreBrowserSynchronization?: boolean; worker: Worker; }) { return runBenchmark({ id: config.id, url: config.url, ignoreBrowserSynchronization: config.ignoreBrowserSynchronization, params: [], prepare: config.worker.prepare, work: config.worker.work, }); }
{ "end_byte": 2637, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/js-web-frameworks.perf-spec.ts" }
angular/modules/benchmarks/src/js-web-frameworks/BUILD.bazel_0_382
load("//tools:defaults.bzl", "ts_library") package(default_visibility = ["//visibility:public"]) ts_library( name = "perf_lib", testonly = True, srcs = ["js-web-frameworks.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 382, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/BUILD.bazel" }
angular/modules/benchmarks/src/js-web-frameworks/ng2/index.html_0_862
<!DOCTYPE html> <html> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2> Angular <a href="https://www.stefankrause.net/wp/?p=504" target="_blank" >JS Web Frameworks benchmark</a > </h2> <p> <button id="create1KRows">create 1K rows</button> <button id="create10KRows">create 10K rows</button> <button id="deleteAll">delete all rows</button> <button id="update">update every 10th row</button> <button id="swap">swap 2 rows</button> </p> <div> <js-web-frameworks id="root">Loading...</js-web-frameworks> </div> <!-- BEGIN-EXTERNAL --> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 862, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/ng2/index.html" }
angular/modules/benchmarks/src/js-web-frameworks/ng2/rows.ts_0_1808
/** * @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, Component, NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; export interface RowData { id: number; label: string; } @Component({ selector: 'js-web-frameworks', template: ` <table class="table table-hover table-striped test-data"> <tbody> @for(item of data; track item.id) { <tr [class.danger]="item.id === selected"> <td class="col-md-1">{{ item.id }}</td> <td class="col-md-4"> <a href="#" (click)="select(item.id); $event.preventDefault()">{{ item.label }}</a> </td> <td class="col-md-1"> <a href="#" (click)="delete(item.id); $event.preventDefault()"> <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> </a> </td> <td class="col-md-6"></td> </tr> } </tbody> </table> `, standalone: false, }) export class JsWebFrameworksComponent { data: Array<RowData> = []; selected: number | null; constructor(private _appRef: ApplicationRef) {} select(itemId: number) { this.selected = itemId; this._appRef.tick(); } delete(itemId: number) { const data = this.data; for (let i = 0, l = data.length; i < l; i++) { if (data[i].id === itemId) { data.splice(i, 1); break; } } this._appRef.tick(); } } @NgModule({ imports: [BrowserModule], declarations: [JsWebFrameworksComponent], bootstrap: [JsWebFrameworksComponent], }) export class JsWebFrameworksModule {}
{ "end_byte": 1808, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/ng2/rows.ts" }
angular/modules/benchmarks/src/js-web-frameworks/ng2/init.ts_0_2509
/** * @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, NgModuleRef} from '@angular/core'; import {bindAction} from '../../util'; import {JsWebFrameworksComponent, JsWebFrameworksModule, RowData} from './rows'; function _random(max: number) { return Math.round(Math.random() * 1000) % max; } function buildData(count: number): Array<RowData> { const data: Array<RowData> = []; for (let i = 0; i < count; i++) { data.push({ id: i, label: ADJECTIVES[_random(ADJECTIVES.length)] + ' ' + COLOURS[_random(COLOURS.length)] + ' ' + NOUNS[_random(NOUNS.length)], }); } return data; } const ADJECTIVES = [ 'pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome', 'plain', 'quaint', 'clean', 'elegant', 'easy', 'angry', 'crazy', 'helpful', 'mushy', 'odd', 'unsightly', 'adorable', 'important', 'inexpensive', 'cheap', 'expensive', 'fancy', ]; const COLOURS = [ 'red', 'yellow', 'blue', 'green', 'pink', 'brown', 'purple', 'brown', 'white', 'black', 'orange', ]; const NOUNS = [ 'table', 'chair', 'house', 'bbq', 'desk', 'car', 'pony', 'cookie', 'sandwich', 'burger', 'pizza', 'mouse', 'keyboard', ]; export function init(moduleRef: NgModuleRef<JsWebFrameworksModule>) { let component: JsWebFrameworksComponent; let appRef: ApplicationRef; function create1K() { component.data = buildData(1 * 1000); appRef.tick(); } function create10K() { component.data = buildData(10 * 1000); appRef.tick(); } function deleteAll() { component.data = []; appRef.tick(); } function update() { for (let i = 0; i < component.data.length; i += 10) { component.data[i].label += ' !!!'; } appRef.tick(); } function swapRows() { const data = component.data; if (data.length > 998) { const a = data[1]; data[1] = data[998]; data[998] = a; } appRef.tick(); } const injector = moduleRef.injector; appRef = injector.get(ApplicationRef); component = appRef.components[0].instance; bindAction('#create1KRows', create1K); bindAction('#create10KRows', create10K); bindAction('#deleteAll', deleteAll); bindAction('#update', update); bindAction('#swap', swapRows); }
{ "end_byte": 2509, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/ng2/init.ts" }
angular/modules/benchmarks/src/js-web-frameworks/ng2/index_aot.ts_0_506
/** * @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 {enableProdMode} from '@angular/core'; import {platformBrowser} from '@angular/platform-browser'; import {init} from './init'; import {JsWebFrameworksModule} from './rows'; enableProdMode(); platformBrowser() .bootstrapModule(JsWebFrameworksModule, { ngZone: 'noop', }) .then(init);
{ "end_byte": 506, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/ng2/index_aot.ts" }
angular/modules/benchmarks/src/js-web-frameworks/ng2/BUILD.bazel_0_1075
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "ng2", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index_aot.ts", deps = [ ":ng2", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/js-web-frameworks:perf_lib"], )
{ "end_byte": 1075, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/js-web-frameworks/ng2/BUILD.bazel" }
angular/modules/benchmarks/src/largetable/largetable.e2e-spec.ts_0_921
/** * @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 { openBrowser, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; describe('largetable benchmark', () => { afterEach(verifyNoBrowserErrors); it(`should render the table`, async () => { openBrowser({ url: '', ignoreBrowserSynchronization: true, params: [ {name: 'cols', value: 5}, {name: 'rows', value: 5}, ], }); await $('#createDom').click(); expect($('#root').getText()).toContain('0/0'); await $('#createDom').click(); expect($('#root').getText()).toContain('A/A'); await $('#destroyDom').click(); expect($('#root').getText() as any).toEqual(''); }); });
{ "end_byte": 921, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/largetable.e2e-spec.ts" }
angular/modules/benchmarks/src/largetable/util.ts_0_1301
/** * @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 {getIntParameter} from '../util'; export class TableCell { constructor( public row: number, public col: number, public value: string, ) {} } let tableCreateCount: number; let maxRow: number; let maxCol: number; let numberData: TableCell[][]; let charData: TableCell[][]; export function initTableUtils() { maxRow = getIntParameter('rows'); maxCol = getIntParameter('cols'); tableCreateCount = 0; numberData = []; charData = []; for (let r = 0; r <= maxRow; r++) { const numberRow: TableCell[] = []; numberData.push(numberRow); const charRow: TableCell[] = []; charData.push(charRow); for (let c = 0; c <= maxCol; c++) { numberRow.push(new TableCell(r, c, `${c}/${r}`)); charRow.push(new TableCell(r, c, `${charValue(c)}/${charValue(r)}`)); } } } function charValue(i: number): string { return String.fromCharCode('A'.charCodeAt(0) + (i % 26)); } export const emptyTable: TableCell[][] = []; export function buildTable(): TableCell[][] { tableCreateCount++; return tableCreateCount % 2 ? numberData : charData; }
{ "end_byte": 1301, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/util.ts" }
angular/modules/benchmarks/src/largetable/BUILD.bazel_0_825
load("//tools:defaults.bzl", "ts_library") package(default_visibility = ["//visibility:public"]) ts_library( name = "util_lib", srcs = ["util.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = ["//modules/benchmarks/src:util_lib"], ) ts_library( name = "perf_tests_lib", testonly = 1, srcs = ["largetable.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], ) ts_library( name = "e2e_tests_lib", testonly = 1, srcs = ["largetable.e2e-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 825, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/BUILD.bazel" }
angular/modules/benchmarks/src/largetable/largetable.perf-spec.ts_0_2310
/** * @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 { runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; interface Worker { id: string; prepare?(): void; work(): void; } const CreateOnlyWorker: Worker = { id: 'createOnly', prepare: () => $('#destroyDom').click(), work: () => $('#createDom').click(), }; const CreateAndDestroyWorker: Worker = { id: 'createDestroy', work: () => { $('#createDom').click(); $('#destroyDom').click(); }, }; const UpdateWorker: Worker = { id: 'update', work: () => $('#createDom').click(), }; // In order to make sure that we don't change the ids of the benchmarks, we need to // determine the current test package name from the Bazel target. This is necessary // because previous to the Bazel conversion, the benchmark test ids contained the test // name. e.g. "largeTable.ng2_switch.createDestroy". We determine the name of the // Bazel package where this test runs from the current test target. The Bazel target // looks like: "//modules/benchmarks/src/largetable/{pkg_name}:{target_name}". const testPackageName = process.env['BAZEL_TARGET']!.split(':')[0].split('/').pop(); describe('largetable benchmark perf', () => { afterEach(verifyNoBrowserErrors); [CreateOnlyWorker, CreateAndDestroyWorker, UpdateWorker].forEach((worker) => { describe(worker.id, () => { it(`should run benchmark for ${testPackageName}`, async () => { await runTableBenchmark({ id: `largeTable.${testPackageName}.${worker.id}`, url: '/', ignoreBrowserSynchronization: true, worker: worker, }); }); }); }); }); function runTableBenchmark(config: { id: string; url: string; ignoreBrowserSynchronization?: boolean; worker: Worker; }) { return runBenchmark({ id: config.id, url: config.url, ignoreBrowserSynchronization: config.ignoreBrowserSynchronization, params: [ {name: 'cols', value: 40}, {name: 'rows', value: 200}, ], prepare: config.worker.prepare, work: config.worker.work, }); }
{ "end_byte": 2310, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/largetable.perf-spec.ts" }
angular/modules/benchmarks/src/largetable/ng2_switch/index.html_0_1053
<!DOCTYPE html> <html lang="en"> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2>Params</h2> <form> Cols: <input type="number" name="cols" placeholder="cols" value="40" /> <br /> Rows: <input type="number" name="rows" placeholder="rows" value="200" /> <br /> <button>Apply</button> </form> <h2>Ng2 with NgSwitch Largetable Benchmark</h2> <p> <button id="destroyDom">destroyDom</button> <button id="createDom">createDom</button> <button id="updateDomProfile">profile updateDom</button> <button id="createDomProfile">profile createDom</button> </p> <div> <largetable id="root">Loading...</largetable> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 1053, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2_switch/index.html" }
angular/modules/benchmarks/src/largetable/ng2_switch/init.ts_0_1101
/** * @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, NgModuleRef} from '@angular/core'; import {bindAction, profile} from '../../util'; import {buildTable, emptyTable, initTableUtils} from '../util'; import {AppModule, TableComponent} from './table'; export function init(moduleRef: NgModuleRef<AppModule>) { let table: TableComponent; let appRef: ApplicationRef; function destroyDom() { table.data = emptyTable; appRef.tick(); } function createDom() { table.data = buildTable(); appRef.tick(); } function noop() {} const injector = moduleRef.injector; appRef = injector.get(ApplicationRef); table = appRef.components[0].instance; initTableUtils(); bindAction('#destroyDom', destroyDom); bindAction('#createDom', createDom); bindAction('#updateDomProfile', profile(createDom, noop, 'update')); bindAction('#createDomProfile', profile(createDom, destroyDom, 'create')); }
{ "end_byte": 1101, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2_switch/init.ts" }
angular/modules/benchmarks/src/largetable/ng2_switch/table.ts_0_1155
/** * @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 {Component, Input, NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {emptyTable, TableCell} from '../util'; @Component({ selector: 'largetable', template: `<table> <tbody> <tr *ngFor="let row of data; trackBy: trackByIndex"> <ng-template ngFor [ngForOf]="row" [ngForTrackBy]="trackByIndex" let-cell ><ng-container [ngSwitch]="cell.row % 2"> <td *ngSwitchCase="0" style="background-color: grey">{{ cell.value }}</td> <td *ngSwitchDefault>{{ cell.value }}</td> </ng-container></ng-template > </tr> </tbody> </table>`, standalone: false, }) export class TableComponent { @Input() data: TableCell[][] = emptyTable; trackByIndex(index: number, item: any) { return index; } } @NgModule({imports: [BrowserModule], bootstrap: [TableComponent], declarations: [TableComponent]}) export class AppModule {}
{ "end_byte": 1155, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2_switch/table.ts" }
angular/modules/benchmarks/src/largetable/ng2_switch/index_aot.ts_0_450
/** * @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 {enableProdMode} from '@angular/core'; import {platformBrowser} from '@angular/platform-browser'; import {init} from './init'; import {AppModule} from './table'; enableProdMode(); platformBrowser().bootstrapModule(AppModule).then(init);
{ "end_byte": 450, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2_switch/index_aot.ts" }
angular/modules/benchmarks/src/largetable/ng2_switch/BUILD.bazel_0_1376
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "ng2_switch", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/largetable:util_lib", "//packages/core", "//packages/platform-browser", "//packages/platform-browser-dynamic", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [":ng2_switch"], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "devserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":devserver", deps = ["//modules/benchmarks/src/largetable:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":devserver", deps = ["//modules/benchmarks/src/largetable:e2e_tests_lib"], )
{ "end_byte": 1376, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2_switch/BUILD.bazel" }
angular/modules/benchmarks/src/largetable/ng2_switch/index.ts_0_472
/** * @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 {enableProdMode} from '@angular/core'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {init} from './init'; import {AppModule} from './table'; enableProdMode(); platformBrowserDynamic().bootstrapModule(AppModule).then(init);
{ "end_byte": 472, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2_switch/index.ts" }
angular/modules/benchmarks/src/largetable/ng2/index.html_0_1039
<!DOCTYPE html> <html lang="en"> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2>Params</h2> <form> Cols: <input type="number" name="cols" placeholder="cols" value="40" /> <br /> Rows: <input type="number" name="rows" placeholder="rows" value="200" /> <br /> <button>Apply</button> </form> <h2>Ng2 Largetable Benchmark</h2> <p> <button id="destroyDom">destroyDom</button> <button id="createDom">createDom</button> <button id="updateDomProfile">profile updateDom</button> <button id="createDomProfile">profile createDom</button> </p> <div> <largetable id="root">Loading...</largetable> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 1039, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2/index.html" }
angular/modules/benchmarks/src/largetable/ng2/init.ts_0_1101
/** * @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, NgModuleRef} from '@angular/core'; import {bindAction, profile} from '../../util'; import {buildTable, emptyTable, initTableUtils} from '../util'; import {AppModule, TableComponent} from './table'; export function init(moduleRef: NgModuleRef<AppModule>) { let table: TableComponent; let appRef: ApplicationRef; function destroyDom() { table.data = emptyTable; appRef.tick(); } function createDom() { table.data = buildTable(); appRef.tick(); } function noop() {} const injector = moduleRef.injector; appRef = injector.get(ApplicationRef); table = appRef.components[0].instance; initTableUtils(); bindAction('#destroyDom', destroyDom); bindAction('#createDom', createDom); bindAction('#updateDomProfile', profile(createDom, noop, 'update')); bindAction('#createDomProfile', profile(createDom, destroyDom, 'create')); }
{ "end_byte": 1101, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2/init.ts" }
angular/modules/benchmarks/src/largetable/ng2/table.ts_0_1371
/** * @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 {Component, Input, NgModule} from '@angular/core'; import {BrowserModule, DomSanitizer, SafeStyle} from '@angular/platform-browser'; import {emptyTable, TableCell} from '../util'; let trustedEmptyColor: SafeStyle; let trustedGreyColor: SafeStyle; @Component({ selector: 'largetable', template: `<table> <tbody> <tr *ngFor="let row of data; trackBy: trackByIndex"> <td *ngFor="let cell of row; trackBy: trackByIndex" [style.backgroundColor]="getColor(cell.row)" > {{ cell.value }} </td> </tr> </tbody> </table>`, standalone: false, }) export class TableComponent { @Input() data: TableCell[][] = emptyTable; trackByIndex(index: number, item: any) { return index; } getColor(row: number) { return row % 2 ? trustedEmptyColor : trustedGreyColor; } } @NgModule({imports: [BrowserModule], bootstrap: [TableComponent], declarations: [TableComponent]}) export class AppModule { constructor(sanitizer: DomSanitizer) { trustedEmptyColor = sanitizer.bypassSecurityTrustStyle('white'); trustedGreyColor = sanitizer.bypassSecurityTrustStyle('grey'); } }
{ "end_byte": 1371, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2/table.ts" }
angular/modules/benchmarks/src/largetable/ng2/index_aot.ts_0_450
/** * @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 {enableProdMode} from '@angular/core'; import {platformBrowser} from '@angular/platform-browser'; import {init} from './init'; import {AppModule} from './table'; enableProdMode(); platformBrowser().bootstrapModule(AppModule).then(init);
{ "end_byte": 450, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2/index_aot.ts" }
angular/modules/benchmarks/src/largetable/ng2/BUILD.bazel_0_1606
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) # Note that this benchmark has been designed for Angular with ViewEngine, but once # ViewEngine is removed, we should should consider removing this one since there # already is a "render3" benchmark. ng_module( name = "ng2", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/largetable:util_lib", "//packages/core", "//packages/platform-browser", "//packages/platform-browser-dynamic", ], ) app_bundle( name = "bundle", entry_point = ":index_aot.ts", deps = [ ":ng2", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/largetable:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":prodserver", deps = ["//modules/benchmarks/src/largetable:e2e_tests_lib"], )
{ "end_byte": 1606, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2/BUILD.bazel" }
angular/modules/benchmarks/src/largetable/ng2/index.ts_0_472
/** * @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 {enableProdMode} from '@angular/core'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {init} from './init'; import {AppModule} from './table'; enableProdMode(); platformBrowserDynamic().bootstrapModule(AppModule).then(init);
{ "end_byte": 472, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/ng2/index.ts" }
angular/modules/benchmarks/src/largetable/baseline/index.html_0_915
<!DOCTYPE html> <html lang="en"> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2>Params</h2> <form> Cols: <input type="number" name="cols" placeholder="cols" value="40" /> <br /> Rows: <input type="number" name="rows" placeholder="rows" value="200" /> <br /> <button>Apply</button> </form> <h2>Baseline Largetable Benchmark</h2> <p> <button id="destroyDom">destroyDom</button> <button id="createDom">createDom</button> <button id="updateDomProfile">profile updateDom</button> <button id="createDomProfile">profile createDom</button> </p> <div> <largetable id="root">Loading...</largetable> </div> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 915, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/baseline/index.html" }
angular/modules/benchmarks/src/largetable/baseline/table.ts_0_1978
/** * @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 {TableCell} from '../util'; export class TableComponent { private _renderCells: any[][]; constructor(private _rootEl: any) {} set data(data: TableCell[][]) { if (data.length === 0) { this._destroy(); } else if (this._renderCells) { this._update(data); } else { this._create(data); } } private _destroy() { while (this._rootEl.lastChild) { this._rootEl.lastChild.remove(); } this._renderCells = null; } private _update(data: TableCell[][]) { for (let r = 0; r < data.length; r++) { const dataRow = data[r]; const renderRow = this._renderCells[r]; for (let c = 0; c < dataRow.length; c++) { const dataCell = dataRow[c]; const renderCell = renderRow[c]; this._updateCell(renderCell, dataCell); } } } private _updateCell(renderCell: any, dataCell: TableCell) { renderCell.textContent = dataCell.value; } private _create(data: TableCell[][]) { const table = document.createElement('table'); this._rootEl.appendChild(table); const tbody = document.createElement('tbody'); table.appendChild(tbody); this._renderCells = []; for (let r = 0; r < data.length; r++) { const dataRow = data[r]; const tr = document.createElement('tr'); tbody.appendChild(tr); const renderRow = []; this._renderCells[r] = renderRow; for (let c = 0; c < dataRow.length; c++) { const dataCell = dataRow[c]; const renderCell = document.createElement('td'); if (r % 2 === 0) { renderCell.style.backgroundColor = 'grey'; } tr.appendChild(renderCell); renderRow[c] = renderCell; this._updateCell(renderCell, dataCell); } } } }
{ "end_byte": 1978, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/baseline/table.ts" }
angular/modules/benchmarks/src/largetable/baseline/BUILD.bazel_0_1196
load("//tools:defaults.bzl", "app_bundle", "http_server", "ts_library") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ts_library( name = "baseline", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//modules/benchmarks/src/largetable:util_lib", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [":baseline"], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "devserver", srcs = ["index.html"], deps = [":app_bundle"], ) benchmark_test( name = "perf", server = ":devserver", deps = ["//modules/benchmarks/src/largetable:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":devserver", deps = ["//modules/benchmarks/src/largetable:e2e_tests_lib"], )
{ "end_byte": 1196, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/baseline/BUILD.bazel" }
angular/modules/benchmarks/src/largetable/baseline/index.ts_0_915
/** * @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 {bindAction, profile} from '../../util'; import {buildTable, emptyTable, initTableUtils} from '../util'; import {TableComponent} from './table'; let table: TableComponent; function destroyDom() { table.data = emptyTable; } function createDom() { table.data = buildTable(); } function noop() {} function init() { const rootEl = document.querySelector('largetable'); rootEl.textContent = ''; table = new TableComponent(rootEl); initTableUtils(); bindAction('#destroyDom', destroyDom); bindAction('#createDom', createDom); bindAction('#updateDomProfile', profile(createDom, noop, 'update')); bindAction('#createDomProfile', profile(createDom, destroyDom, 'create')); } init();
{ "end_byte": 915, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largetable/baseline/index.ts" }
angular/modules/benchmarks/src/largeform/largeform.e2e-spec.ts_0_890
/** * @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 { openBrowser, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$, By, element} from 'protractor'; describe('largeform benchmark', () => { afterEach(verifyNoBrowserErrors); it('should work for ng2', async () => { openBrowser({ url: '/', params: [{name: 'copies', value: 1}], ignoreBrowserSynchronization: true, }); await $('#createDom').click(); expect(await element.all(By.css('input[name=value0]')).get(0).getAttribute('value')).toBe( 'someValue0', ); await $('#destroyDom').click(); expect(await element.all(By.css('input[name=value0]')).count()).toBe(0); }); });
{ "end_byte": 890, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/largeform.e2e-spec.ts" }
angular/modules/benchmarks/src/largeform/README.md_0_212
# Large Form Benchmark Purpose: - Track generated file size for a big form - Track time for creation / destruction of form widgets, as they are more complex (e.g. include event listeners, host bindings, ...)
{ "end_byte": 212, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/README.md" }
angular/modules/benchmarks/src/largeform/BUILD.bazel_0_671
load("//tools:defaults.bzl", "ts_library") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ts_library( name = "perf_tests_lib", testonly = 1, srcs = ["largeform.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], ) ts_library( name = "e2e_tests_lib", testonly = 1, srcs = ["largeform.e2e-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 671, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/BUILD.bazel" }
angular/modules/benchmarks/src/largeform/largeform.perf-spec.ts_0_1315
/** * @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 { runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; interface Worker { id: string; prepare?(): void; work(): void; } const CreateAndDestroyWorker = { id: 'createDestroy', work: () => { $('#createDom').click(); $('#destroyDom').click(); }, }; describe('largeform benchmark spec', () => { afterEach(verifyNoBrowserErrors); [CreateAndDestroyWorker].forEach((worker) => { describe(worker.id, () => { it('should run for ng2', async () => { await runLargeFormBenchmark({url: '/', id: `largeform.ng2.${worker.id}`, worker: worker}); }); }); }); function runLargeFormBenchmark(config: { id: string; url: string; ignoreBrowserSynchronization?: boolean; worker: Worker; }) { return runBenchmark({ id: config.id, url: config.url, params: [{name: 'copies', value: 8}], ignoreBrowserSynchronization: config.ignoreBrowserSynchronization, prepare: config.worker.prepare, work: config.worker.work, }); } });
{ "end_byte": 1315, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/largeform.perf-spec.ts" }
angular/modules/benchmarks/src/largeform/ng2/index.html_0_621
<!DOCTYPE html> <html lang="en"> <body> <h2>Params</h2> <form> Copies: <input type="number" name="copies" placeholder="copies" value="8" /> <br /> <button>Apply</button> </form> <h2>Ng2 Large Form Benchmark</h2> <p> <button id="destroyDom">destroyDom</button> <button id="createDom">createDom</button> <button id="createDomProfile">profile createDom</button> </p> <div> <app id="root">Loading...</app> </div> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 621, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/ng2/index.html" }
angular/modules/benchmarks/src/largeform/ng2/init.ts_0_984
/** * @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, NgModuleRef} from '@angular/core'; import {bindAction, getIntParameter, profile} from '../../util'; import {AppComponent, AppModule} from './app'; const copies = getIntParameter('copies'); export function init(moduleRef: NgModuleRef<AppModule>) { let app: AppComponent; let appRef: ApplicationRef; function destroyDom() { app.setCopies(0); appRef.tick(); } function createDom() { app.setCopies(copies); appRef.tick(); } function noop() {} const injector = moduleRef.injector; appRef = injector.get(ApplicationRef); app = appRef.components[0].instance; bindAction('#destroyDom', destroyDom); bindAction('#createDom', createDom); bindAction('#createDomProfile', profile(createDom, destroyDom, 'create')); }
{ "end_byte": 984, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/ng2/init.ts" }
angular/modules/benchmarks/src/largeform/ng2/app.ts_0_4207
/** * @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 {Component, NgModule} from '@angular/core'; import {FormsModule} from '@angular/forms'; import {BrowserModule} from '@angular/platform-browser'; @Component({ selector: 'app', template: `<form *ngFor="let copy of copies"> <input type="text" [(ngModel)]="values[0]" name="value0" /> <input type="text" [(ngModel)]="values[1]" name="value1" /> <input type="text" [(ngModel)]="values[2]" name="value2" /> <input type="text" [(ngModel)]="values[3]" name="value3" /> <input type="text" [(ngModel)]="values[4]" name="value4" /> <input type="text" [(ngModel)]="values[5]" name="value5" /> <input type="text" [(ngModel)]="values[6]" name="value6" /> <input type="text" [(ngModel)]="values[7]" name="value7" /> <input type="text" [(ngModel)]="values[8]" name="value8" /> <input type="text" [(ngModel)]="values[9]" name="value9" /> <input type="text" [(ngModel)]="values[10]" name="value10" /> <input type="text" [(ngModel)]="values[11]" name="value11" /> <input type="text" [(ngModel)]="values[12]" name="value12" /> <input type="text" [(ngModel)]="values[13]" name="value13" /> <input type="text" [(ngModel)]="values[14]" name="value14" /> <input type="text" [(ngModel)]="values[15]" name="value15" /> <input type="text" [(ngModel)]="values[16]" name="value16" /> <input type="text" [(ngModel)]="values[17]" name="value17" /> <input type="text" [(ngModel)]="values[18]" name="value18" /> <input type="text" [(ngModel)]="values[19]" name="value19" /> <input type="text" [(ngModel)]="values[20]" name="value20" /> <input type="text" [(ngModel)]="values[21]" name="value21" /> <input type="text" [(ngModel)]="values[22]" name="value22" /> <input type="text" [(ngModel)]="values[23]" name="value23" /> <input type="text" [(ngModel)]="values[24]" name="value24" /> <input type="text" [(ngModel)]="values[25]" name="value25" /> <input type="text" [(ngModel)]="values[26]" name="value26" /> <input type="text" [(ngModel)]="values[27]" name="value27" /> <input type="text" [(ngModel)]="values[28]" name="value28" /> <input type="text" [(ngModel)]="values[29]" name="value29" /> <input type="text" [(ngModel)]="values[30]" name="value30" /> <input type="text" [(ngModel)]="values[31]" name="value31" /> <input type="text" [(ngModel)]="values[32]" name="value32" /> <input type="text" [(ngModel)]="values[33]" name="value33" /> <input type="text" [(ngModel)]="values[34]" name="value34" /> <input type="text" [(ngModel)]="values[35]" name="value35" /> <input type="text" [(ngModel)]="values[36]" name="value36" /> <input type="text" [(ngModel)]="values[37]" name="value37" /> <input type="text" [(ngModel)]="values[38]" name="value38" /> <input type="text" [(ngModel)]="values[39]" name="value39" /> <input type="text" [(ngModel)]="values[40]" name="value40" /> <input type="text" [(ngModel)]="values[41]" name="value41" /> <input type="text" [(ngModel)]="values[42]" name="value42" /> <input type="text" [(ngModel)]="values[43]" name="value43" /> <input type="text" [(ngModel)]="values[44]" name="value44" /> <input type="text" [(ngModel)]="values[45]" name="value45" /> <input type="text" [(ngModel)]="values[46]" name="value46" /> <input type="text" [(ngModel)]="values[47]" name="value47" /> <input type="text" [(ngModel)]="values[48]" name="value48" /> <input type="text" [(ngModel)]="values[49]" name="value49" /> </form>`, standalone: false, }) export class AppComponent { copies: number[] = []; values: string[] = []; constructor() { for (let i = 0; i < 50; i++) { this.values[i] = `someValue${i}`; } } setCopies(count: number) { this.copies = []; for (let i = 0; i < count; i++) { this.copies.push(i); } } } @NgModule({ imports: [BrowserModule, FormsModule], bootstrap: [AppComponent], declarations: [AppComponent], }) export class AppModule {}
{ "end_byte": 4207, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/ng2/app.ts" }
angular/modules/benchmarks/src/largeform/ng2/index_aot.ts_0_526
/** * @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 */ // BEGIN-EXTERNAL import 'zone.js/lib/browser/rollup-main'; // END-EXTERNAL import {enableProdMode} from '@angular/core'; import {platformBrowser} from '@angular/platform-browser'; import {AppModule} from './app'; import {init} from './init'; enableProdMode(); platformBrowser().bootstrapModule(AppModule).then(init);
{ "end_byte": 526, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/ng2/index_aot.ts" }
angular/modules/benchmarks/src/largeform/ng2/BUILD.bazel_0_1295
load("//tools:defaults.bzl", "esbuild", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") load("//modules/benchmarks:e2e_test.bzl", "e2e_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) # Note that this benchmark has been designed for Angular with ViewEngine, but once ViewEngine is # removed, we should keep this benchmark and run it with Ivy (potentially rename it to "render3") ng_module( name = "ng2", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//packages/core", "//packages/forms", "//packages/platform-browser", "//packages/platform-browser-dynamic", "//packages/zone.js/lib", ], ) esbuild( name = "app_bundle", entry_point = ":index.ts", deps = [":ng2"], ) http_server( name = "devserver", srcs = ["index.html"], deps = [":app_bundle"], ) benchmark_test( name = "perf", server = ":devserver", deps = ["//modules/benchmarks/src/largeform:perf_tests_lib"], ) e2e_test( name = "e2e", server = ":devserver", deps = ["//modules/benchmarks/src/largeform:e2e_tests_lib"], )
{ "end_byte": 1295, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/ng2/BUILD.bazel" }
angular/modules/benchmarks/src/largeform/ng2/index.ts_0_548
/** * @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 */ // BEGIN-EXTERNAL import 'zone.js/lib/browser/rollup-main'; // END-EXTERNAL import {enableProdMode} from '@angular/core'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {AppModule} from './app'; import {init} from './init'; enableProdMode(); platformBrowserDynamic().bootstrapModule(AppModule).then(init);
{ "end_byte": 548, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/largeform/ng2/index.ts" }
angular/modules/benchmarks/src/styling/styling_perf.spec.ts_0_3738
/** * @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 { openBrowser, runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$, by, element} from 'protractor'; /** List of possible scenarios that should be tested. */ const SCENARIOS = [ {optionIndex: 0, id: 'no_styling_involved'}, {optionIndex: 1, id: 'static_class'}, {optionIndex: 2, id: 'static_class_with_interpolation'}, {optionIndex: 3, id: 'class_binding'}, {optionIndex: 4, id: 'static_class_and_class_binding'}, {optionIndex: 5, id: 'static_class_and_ngclass_binding'}, {optionIndex: 6, id: 'static_class_and_ngstyle_binding_and_style_binding'}, {optionIndex: 7, id: 'static_style'}, {optionIndex: 8, id: 'style_property_bindings'}, {optionIndex: 9, id: 'static_style_and_property_binding'}, {optionIndex: 10, id: 'ng_style_with_units'}, ]; describe('styling benchmark spec', () => { afterEach(verifyNoBrowserErrors); it('should render and interact to update and detect changes', async () => { openBrowser({url: '/', ignoreBrowserSynchronization: true}); create(); const items = element.all(by.css('styling-bindings button')); expect(await items.count()).toBe(2000); expect(await items.first().getAttribute('title')).toBe('bar'); update(); expect(await items.first().getAttribute('title')).toBe('baz'); }); it('should render and run noop change detection', async () => { openBrowser({url: '/', ignoreBrowserSynchronization: true}); create(); const items = element.all(by.css('styling-bindings button')); expect(await items.count()).toBe(2000); expect(await items.first().getAttribute('title')).toBe('bar'); detectChanges(); expect(await items.first().getAttribute('title')).toBe('bar'); }); // Create benchmarks for each possible test scenario. SCENARIOS.forEach(({optionIndex, id}) => { describe(id, () => { it('should run create benchmark', async () => { await runStylingBenchmark(`styling.${id}.create`, { work: () => create(), prepare: () => { selectScenario(optionIndex); destroy(); }, }); }); it('should run update benchmark', async () => { await runStylingBenchmark(`styling.${id}.update`, { work: () => update(), prepare: () => { selectScenario(optionIndex); create(); }, }); }); it('should run detect changes benchmark', async () => { await runStylingBenchmark(`styling.${id}.noop_cd`, { work: () => detectChanges(), prepare: () => { selectScenario(optionIndex); create(); }, }); }); }); }); }); function selectScenario(optionIndex: number) { // Switch to the current scenario by clicking the corresponding option. element.all(by.tagName('option')).get(optionIndex).click(); } function create() { $('#create').click(); } function destroy() { $('#destroy').click(); } function update() { $('#update').click(); } function detectChanges() { $('#detect_changes').click(); } /** * Runs the styling benchmark with the given id and worker. The worker describes * the actions that should run for preparation and measurement. */ function runStylingBenchmark(id: string, worker: {prepare: () => void; work: () => void}) { return runBenchmark({ id, url: '/', params: [], ignoreBrowserSynchronization: true, prepare: worker.prepare, work: worker.work, }); }
{ "end_byte": 3738, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/styling_perf.spec.ts" }
angular/modules/benchmarks/src/styling/BUILD.bazel_0_390
load("//tools:defaults.bzl", "ts_library") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ts_library( name = "tests_lib", testonly = True, srcs = ["styling_perf.spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 390, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/BUILD.bazel" }
angular/modules/benchmarks/src/styling/ng2/index.html_0_2270
<!DOCTYPE html> <html> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <h2>Styling bindings benchmark</h2> <p> <select id="scenario-select"> <!-- *Note*: When adding/removing scenarios, ensure the e2e test is also updated. --> <option value="0">(0) [title]="exp" (no styling involved)</option> <option value="1">(1) class="foo" (static class)</option> <option value="2">(2) class="foo {{exp}}" (class interpolation)</option> <option value="3">(3) [class.foo]="boolExp" binding</option> <option value="4"> (4) class="foo" [class.bar]="boolExp" (mix of static and class. bindings </option> <option value="5"> (5) class="foo" [ngClass]="{bar: boolExp}" (mix of static class and ngClass binding) </option> <option value="6"> (6) class="foo" [ngStyle]="{width: 10px}" [style.background-color]="exp" (Sierpinski's triangle) </option> <option value="7">(7) style="color: red" (static styling)</option> <option value="8"> (8) [style.width.px]="widthExp" [style.color]="exp" (style property bindings) </option> <option value="9"> (9) style="width: 10px" [style.color]="exp" ((mix of static and class property bindings) </option> <option value="10"> (10) [ngStyle]="{width.px: widthExp, color: exp}" (ngStyle with units) </option> </select> <button id="create">create</button> <button id="update">update</button> <button id="detect_changes">detect changes</button> <button id="destroy">destroy</button> <button id="profile_update">profile update</button> <button id="profile_detect_changes">profile detect changes</button> <button id="modify">modify externally</button> </p> <div> <styling-bindings id="root">Loading...</styling-bindings> </div> <!-- BEGIN-EXTERNAL --> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <!-- END-EXTERNAL --> <!-- Needs to be named `app_bundle` for sync into Google. --> <script src="/app_bundle.js"></script> </body> </html>
{ "end_byte": 2270, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/ng2/index.html" }
angular/modules/benchmarks/src/styling/ng2/init.ts_0_2189
/** * @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, NgModuleRef} from '@angular/core'; import {bindAction, profile} from '../../util'; import {StylingModule} from './styling'; export function init(moduleRef: NgModuleRef<StylingModule>) { const injector = moduleRef.injector; const appRef = injector.get(ApplicationRef); const componentRef = appRef.components[0]; const component = componentRef.instance; const componentHostEl = componentRef.location.nativeElement; const select = document.querySelector('#scenario-select')! as HTMLSelectElement; const empty = []; const items = []; function create(tplRefIdx: number) { component.tplRefIdx = tplRefIdx; component.data = items; appRef.tick(); } function destroy() { component.data = empty; appRef.tick(); } function update() { component.exp = component.exp === 'bar' ? 'baz' : 'bar'; appRef.tick(); } function detectChanges() { appRef.tick(); } function modifyExternally() { const buttonEls = componentHostEl.querySelectorAll('button') as HTMLButtonElement[]; buttonEls.forEach((buttonEl: HTMLButtonElement) => { const cl = buttonEl.classList; if (cl.contains('external')) { cl.remove('external'); } else { cl.add('external'); } }); } for (let i = 0; i < 2000; i++) { items.push(i); } bindAction('#create', () => create(select.selectedIndex)); bindAction('#update', update); bindAction('#detect_changes', detectChanges); bindAction('#destroy', destroy); bindAction( '#profile_update', profile( () => { for (let i = 0; i < 10; i++) { update(); } }, () => {}, 'update and detect changes', ), ); bindAction( '#profile_detect_changes', profile( () => { for (let i = 0; i < 10; i++) { detectChanges(); } }, () => {}, 'noop detect changes', ), ); bindAction('#modify', modifyExternally); }
{ "end_byte": 2189, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/ng2/init.ts" }
angular/modules/benchmarks/src/styling/ng2/index_aot.ts_0_460
/** * @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 {enableProdMode} from '@angular/core'; import {platformBrowser} from '@angular/platform-browser'; import {init} from './init'; import {StylingModule} from './styling'; enableProdMode(); platformBrowser().bootstrapModule(StylingModule).then(init);
{ "end_byte": 460, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/ng2/index_aot.ts" }
angular/modules/benchmarks/src/styling/ng2/styling.ts_0_2057
/** * @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 {Component, NgModule, TemplateRef} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; @Component({ selector: 'styling-bindings', template: ` <ng-template #t0><button [title]="exp"></button></ng-template> <ng-template #t1><button class="static"></button></ng-template> <ng-template #t2><button class="foo {{ exp }}"></button></ng-template> <ng-template #t3><button [class.bar]="exp === 'bar'"></button></ng-template> <ng-template #t4><button class="foo" [class.bar]="exp === 'bar'"></button></ng-template> <ng-template #t5><button class="foo" [ngClass]="{bar: exp === 'bar'}"></button></ng-template> <ng-template #t6 ><button class="foo" [ngStyle]="staticStyle" [style.background-color]="exp == 'bar' ? 'yellow' : 'red'" ></button ></ng-template> <ng-template #t7><button style="color: red"></button></ng-template> <ng-template #t8 ><button [style.width.px]="exp === 'bar' ? 10 : 20" [style.color]="exp"></button ></ng-template> <ng-template #t9><button style="width: 10px" [style.color]="exp"></button></ng-template> <ng-template #t10 ><button [ngStyle]="{'width.px': exp === 'bar' ? 10 : 20, color: exp}"></button ></ng-template> <div> <ng-template ngFor [ngForOf]="data" [ngForTemplate]="getTplRef(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10)" ></ng-template> </div> `, standalone: false, }) export class StylingComponent { data: number[] = []; exp: string = 'bar'; tplRefIdx: number = 0; staticStyle = {width: '10px'}; getTplRef(...tplRefs): TemplateRef<any> { return tplRefs[this.tplRefIdx]; } } @NgModule({ imports: [BrowserModule], declarations: [StylingComponent], bootstrap: [StylingComponent], }) export class StylingModule {}
{ "end_byte": 2057, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/ng2/styling.ts" }
angular/modules/benchmarks/src/styling/ng2/BUILD.bazel_0_1116
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "ng2", srcs = glob(["*.ts"]), tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index_aot.ts", deps = [ ":ng2", "@npm//rxjs", ], ) # The script needs to be called `app_bundle` for easier syncing into g3. genrule( name = "app_bundle", srcs = [":bundle.debug.min.js"], outs = ["app_bundle.js"], cmd = "cp $< $@", ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":app_bundle", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/styling:tests_lib"], )
{ "end_byte": 1116, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/styling/ng2/BUILD.bazel" }
angular/modules/benchmarks/src/ng_template_outlet_context/BUILD.bazel_0_391
load("//tools:defaults.bzl", "ts_library") package(default_visibility = ["//visibility:public"]) ts_library( name = "perf_lib", testonly = True, srcs = ["ng_template_outlet_context.perf-spec.ts"], tsconfig = "//modules/benchmarks:tsconfig-e2e.json", deps = [ "@npm//@angular/build-tooling/bazel/benchmark/driver-utilities", "@npm//protractor", ], )
{ "end_byte": 391, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/ng_template_outlet_context/BUILD.bazel" }
angular/modules/benchmarks/src/ng_template_outlet_context/ng_template_outlet_context.perf-spec.ts_0_1701
/** * @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 { runBenchmark, verifyNoBrowserErrors, } from '@angular/build-tooling/bazel/benchmark/driver-utilities'; import {$} from 'protractor'; interface Worker { id: string; prepare?(): void; work(): void; } const SwapFullContext = { id: 'swapFullContext', work: () => { $('#swapOutFull').click(); }, }; const ModifyContextProperty = { id: 'modifyContextProperty', work: () => { $('#modifyProperty').click(); }, }; const ModifyContextDeepProperty = { id: 'modifyContextDeepProperty', work: () => { $('#modifyDeepProperty').click(); }, }; const AddNewContextProperty = { id: 'addNewContextProperty', work: () => { $('#addNewProperty').click(); }, }; const scenarios = [ SwapFullContext, ModifyContextProperty, ModifyContextDeepProperty, AddNewContextProperty, ]; describe('ng_template_outlet_context benchmark spec', () => { afterEach(verifyNoBrowserErrors); scenarios.forEach((worker) => { describe(worker.id, () => { it('should run for ng2', async () => { await runBenchmarkScenario({ url: '/', id: `ngTemplateOutletContext.ng2.${worker.id}`, worker: worker, }); }); }); }); function runBenchmarkScenario(config: {id: string; url: string; worker: Worker}) { return runBenchmark({ id: config.id, url: config.url, ignoreBrowserSynchronization: true, prepare: config.worker.prepare, work: config.worker.work, }); } });
{ "end_byte": 1701, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/ng_template_outlet_context/ng_template_outlet_context.perf-spec.ts" }
angular/modules/benchmarks/src/ng_template_outlet_context/ng2/index.html_0_363
<!DOCTYPE html> <html> <head> <!-- Prevent the browser from requesting any favicon. --> <link rel="icon" href="data:," /> </head> <body> <div> <app-component>Loading...</app-component> </div> <script src="/angular/packages/zone.js/bundles/zone.umd.js"></script> <script src="/bundle.debug.min.js"></script> </body> </html>
{ "end_byte": 363, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/ng_template_outlet_context/ng2/index.html" }
angular/modules/benchmarks/src/ng_template_outlet_context/ng2/BUILD.bazel_0_947
load("//tools:defaults.bzl", "app_bundle", "http_server", "ng_module") load("@npm//@angular/build-tooling/bazel/benchmark/component_benchmark:benchmark_test.bzl", "benchmark_test") package(default_visibility = ["//modules/benchmarks:__subpackages__"]) ng_module( name = "ng2", srcs = glob(["*.ts"]), strict_templates = True, tsconfig = "//modules/benchmarks:tsconfig-build.json", deps = [ "//modules/benchmarks/src:util_lib", "//packages/core", "//packages/platform-browser", ], ) app_bundle( name = "bundle", entry_point = ":index.ts", deps = [ ":ng2", ], ) http_server( name = "prodserver", srcs = ["index.html"], deps = [ ":bundle.debug.min.js", "//packages/zone.js/bundles:zone.umd.js", ], ) benchmark_test( name = "perf", server = ":prodserver", deps = ["//modules/benchmarks/src/ng_template_outlet_context:perf_lib"], )
{ "end_byte": 947, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/ng_template_outlet_context/ng2/BUILD.bazel" }
angular/modules/benchmarks/src/ng_template_outlet_context/ng2/index.ts_0_2262
/** * @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 {NgIf, NgTemplateOutlet} from '@angular/common'; import {Component, enableProdMode, Input} from '@angular/core'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'deep', standalone: true, imports: [NgIf], template: `<deep *ngIf="depth > 1" [depth]="depth - 1" /> Level: {{ depth }}`, }) class Deep { @Input({required: true}) depth: number; } @Component({ selector: 'app-component', standalone: true, imports: [NgTemplateOutlet, Deep], template: ` <button id="swapOutFull" (click)="swapOutFull()">Swap out full context</button> <button id="modifyProperty" (click)="modifyProperty()">Modify property</button> <button id="modifyDeepProperty" (click)="modifyDeepProperty()">Modify deep property</button> <button id="addNewProperty" (click)="addNewProperty()">Add new property</button> <ng-template #templateRef let-implicit let-a="a" let-b="b" let-deep="deep" let-new="new"> <p>Implicit: {{ implicit }}</p> <p>A: {{ a }}</p> <p>B: {{ b }}</p> <p>Deep: {{ deep.next.text }}</p> <p>New: {{ new }}</p> <deep [depth]="20" /> </ng-template> <div> <p>Outlet</p> <ng-template [ngTemplateOutlet]="templateRef" [ngTemplateOutletContext]="context" /> </div> `, }) class AppComponent { context: { $implicit: unknown; a: unknown; b: unknown; deep: {next: {text: unknown}}; new?: unknown; } = { $implicit: 'Default Implicit', a: 'Default A', b: 'Default B', deep: {next: {text: 'Default deep text'}}, }; swapOutFull() { this.context = { $implicit: 'New Implicit new Object', a: 'New A new Object', b: 'New B new Object', deep: {next: {text: 'New Deep text new Object'}}, }; } modifyProperty() { this.context.a = 'Modified a'; } modifyDeepProperty() { this.context.deep.next.text = 'Modified deep a'; } addNewProperty() { this.context.new = 'New property set'; } } enableProdMode(); bootstrapApplication(AppComponent);
{ "end_byte": 2262, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/modules/benchmarks/src/ng_template_outlet_context/ng2/index.ts" }
TypeScript/CODE_OF_CONDUCT.md_0_333
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
{ "end_byte": 333, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/CODE_OF_CONDUCT.md" }
TypeScript/azure-pipelines.release.yml_0_2761
trigger: branches: include: - release-* resources: repositories: - repository: 1esPipelines type: git name: 1ESPipelineTemplates/1ESPipelineTemplates ref: refs/tags/release extends: template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines parameters: pool: name: TypeScript-AzurePipelines-EO image: 1ESPT-Mariner2.0 os: linux sdl: sourceAnalysisPool: name: TypeScript-AzurePipelines-EO image: 1ESPT-Windows2022 os: windows stages: - stage: buildStage displayName: Build Stage jobs: - job: test displayName: Test steps: - checkout: self clean: true fetchDepth: 1 fetchTags: false - task: NodeTool@0 inputs: versionSpec: 20.x displayName: 'Install Node' - script: | npm install -g `node -e 'console.log(JSON.parse(fs.readFileSync("package.json", "utf8")).packageManager)'` npm --version displayName: 'Install packageManager from package.json' - script: npm ci displayName: 'npm ci' - script: 'npm test' displayName: 'npm test' - job: build displayName: Build dependsOn: test steps: - checkout: self clean: true fetchDepth: 1 fetchTags: false - task: NodeTool@0 inputs: versionSpec: 20.x displayName: 'Install Node' - script: | npm install -g `node -e 'console.log(JSON.parse(fs.readFileSync("package.json", "utf8")).packageManager)'` npm --version displayName: 'Install packageManager from package.json' - script: npm ci displayName: 'npm ci' - script: | npx hereby LKG npx hereby clean node ./scripts/addPackageJsonGitHead.mjs package.json npm pack displayName: 'LKG, clean, pack' - task: CopyFiles@2 displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' inputs: SourceFolder: ./ Contents: 'typescript-*.tgz' TargetFolder: '$(Build.ArtifactStagingDirectory)' templateContext: outputs: - output: pipelineArtifact targetPath: '$(Build.ArtifactStagingDirectory)' artifactName: tgz
{ "end_byte": 2761, "start_byte": 0, "url": "https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml" }