-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14474 from primefaces/deferred-demo
Improve DataTable demo performance
- Loading branch information
Showing
53 changed files
with
1,536 additions
and
1,368 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.demo-section-loading { | ||
display: grid; | ||
place-items: center; | ||
padding: 2rem; | ||
border-radius: 10px; | ||
margin-bottom: 1rem; | ||
font-size: 2rem; | ||
height: 350px; | ||
background: var(--maskbg); | ||
} |
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,54 @@ | ||
import { CommonModule, isPlatformBrowser } from '@angular/common'; | ||
import { Component, ElementRef, EventEmitter, Inject, Input, OnInit, Output, PLATFORM_ID } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'p-deferred-demo', | ||
standalone: true, | ||
imports: [CommonModule], | ||
template: ` | ||
@if(!visible){ | ||
<div class="demo-section-loading">Loading...</div> | ||
} @else { | ||
<ng-content></ng-content> | ||
} | ||
`, | ||
styleUrl: './deferreddemo.scss' | ||
}) | ||
export class DeferredDemo implements OnInit { | ||
visible: boolean = false; | ||
|
||
observer = null; | ||
|
||
timeout = null; | ||
|
||
@Input() options: any; | ||
|
||
@Output() load: EventEmitter<boolean> = new EventEmitter<boolean>(); | ||
|
||
constructor(public el: ElementRef, @Inject(PLATFORM_ID) private platformId: any) {} | ||
|
||
ngOnInit() { | ||
if (isPlatformBrowser(this.platformId)) { | ||
this.observer = new IntersectionObserver(([entry]) => { | ||
clearTimeout(this.timeout); | ||
|
||
if (entry.isIntersecting) { | ||
this.timeout = setTimeout(() => { | ||
this.visible = true; | ||
this.observer.unobserve(this.el.nativeElement); | ||
this.load.emit(); | ||
}, 350); | ||
} | ||
}, this.options); | ||
|
||
this.observer.observe(this.el.nativeElement); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
if (!this.visible && this.el.nativeElement) { | ||
this.observer?.unobserve(this.el.nativeElement); | ||
} | ||
clearTimeout(this.timeout); | ||
} | ||
} |
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.