-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(toolkit/observable): optimize position detection in `fromBoundin…
…gClientRect$` There is no native browser API for observing an element's position. The new implementation uses the Intersection Observer API to detect position changes, significantly improving performance compared to the previous approach, which required monitoring numerous DOM elements for resizing, scrolling, and DOM changes.
- Loading branch information
1 parent
83c4b3c
commit 9eea1a3
Showing
39 changed files
with
1,720 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import {Routes} from '@angular/router'; | ||
|
||
export default [ | ||
{ | ||
path: 'sci-viewport', | ||
loadChildren: () => import('./sci-viewport/routes'), | ||
}, | ||
] satisfies Routes; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
.../src/app/toolkit/observable/bounding-client-rect/bounding-client-rect-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="testee e2e-testee" #testee></div> | ||
|
||
<aside> | ||
<section class="e2e-properties"> | ||
<header>Properties:</header> | ||
<span>x:</span><input [(ngModel)]="properties.x" class="e2e-x"> | ||
<span>y:</span><input [(ngModel)]="properties.y" class="e2e-y"> | ||
<span>width:</span><input [(ngModel)]="properties.width" class="e2e-width"> | ||
<span>height:</span><input [(ngModel)]="properties.height" class="e2e-height"> | ||
<button (click)="applyProperties()" class="apply e2e-apply">Apply</button> | ||
</section> | ||
|
||
<section class="e2e-testee-bounding-box"> | ||
<header>Testee Bounding Box:</header> | ||
<span>x:</span><span class="e2e-x">{{testeeBoundingBox.x()}}</span> | ||
<span>y:</span><span class="e2e-y">{{testeeBoundingBox.y()}}</span> | ||
<span>width:</span><span class="e2e-width">{{testeeBoundingBox.width()}}</span> | ||
<span>height:</span><span class="e2e-height">{{testeeBoundingBox.height()}}</span> | ||
</section> | ||
</aside> |
30 changes: 30 additions & 0 deletions
30
.../src/app/toolkit/observable/bounding-client-rect/bounding-client-rect-page.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
:host { | ||
> div.testee { | ||
position: absolute; | ||
background-color: blue; | ||
} | ||
|
||
> aside { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 2em; | ||
padding: 1em; | ||
|
||
> section { | ||
display: grid; | ||
grid-template-columns: auto 1fr; | ||
gap: .25em 1em; | ||
|
||
> header { | ||
font-weight: bold; | ||
} | ||
|
||
> header, > button.apply { | ||
grid-column: 1/-1; | ||
} | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...pp/src/app/toolkit/observable/bounding-client-rect/bounding-client-rect-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import {Component, DestroyRef, ElementRef, inject, OnInit, signal, viewChild} from '@angular/core'; | ||
import {FormsModule} from '@angular/forms'; | ||
import {fromBoundingClientRect$} from '@scion/toolkit/observable'; | ||
import {takeUntilDestroyed} from '@angular/core/rxjs-interop'; | ||
|
||
@Component({ | ||
selector: 'e2e-bounding-client-rect-page', | ||
templateUrl: './bounding-client-rect-page.component.html', | ||
styleUrl: './bounding-client-rect-page.component.scss', | ||
standalone: true, | ||
imports: [ | ||
FormsModule, | ||
], | ||
}) | ||
export class BoundingClientRectPageComponent implements OnInit { | ||
|
||
private _testee = viewChild.required<ElementRef<HTMLElement>>('testee'); | ||
private _destroyRef = inject(DestroyRef); | ||
|
||
protected properties = { | ||
x: signal<string>('0px'), | ||
y: signal<string>('0px'), | ||
width: signal<string>('100px'), | ||
height: signal<string>('100px'), | ||
}; | ||
|
||
protected testeeBoundingBox = { | ||
x: signal<number | undefined>(undefined), | ||
y: signal<number | undefined>(undefined), | ||
width: signal<number | undefined>(undefined), | ||
height: signal<number | undefined>(undefined), | ||
}; | ||
|
||
public ngOnInit(): void { | ||
this.applyProperties(); | ||
|
||
fromBoundingClientRect$(this._testee().nativeElement) | ||
.pipe(takeUntilDestroyed(this._destroyRef)) | ||
.subscribe(domRect => { | ||
this.testeeBoundingBox.x.set(domRect.x); | ||
this.testeeBoundingBox.y.set(domRect.y); | ||
this.testeeBoundingBox.width.set(domRect.width); | ||
this.testeeBoundingBox.height.set(domRect.height); | ||
}); | ||
} | ||
|
||
public applyProperties(): void { | ||
this._testee().nativeElement.style.left = this.properties.x(); | ||
this._testee().nativeElement.style.top = this.properties.y(); | ||
this._testee().nativeElement.style.width = this.properties.width(); | ||
this._testee().nativeElement.style.height = this.properties.height(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/components-testing-app/src/app/toolkit/observable/routes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import {Routes} from '@angular/router'; | ||
import {BoundingClientRectPageComponent} from './bounding-client-rect/bounding-client-rect-page.component'; | ||
|
||
export default [ | ||
{path: 'bounding-client-rect', component: BoundingClientRectPageComponent}, | ||
] satisfies Routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (c) 2018-2024 Swiss Federal Railways | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
|
||
import {Routes} from '@angular/router'; | ||
|
||
export default [ | ||
{ | ||
path: 'observable', loadChildren: () => import('./observable/routes'), | ||
}, | ||
] satisfies Routes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.