dots-viewer: Move away from forEach in js

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8521>
This commit is contained in:
Thibault Saunier 2025-02-19 12:49:31 -03:00 committed by GStreamer Marge Bot
parent ce912c6320
commit b042085ba4

View File

@ -109,13 +109,13 @@ async function createNewDotDiv(pipelines_div, dot_info) {
img.loading = "lazy"; img.loading = "lazy";
img.dot_info = dot_info; img.dot_info = dot_info;
const observer = new IntersectionObserver((entries, observer) => { const observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => { for (const entry of entries) {
if (entry.isIntersecting) { if (entry.isIntersecting) {
console.debug(`Image ${div.id} is visible`); console.debug(`Image ${div.id} is visible`);
generateSvg(img); generateSvg(img);
observer.unobserve(entry.target); observer.unobserve(entry.target);
} }
}); }
}, { }, {
rootMargin: '100px' rootMargin: '100px'
}); });
@ -282,15 +282,16 @@ function updateSearch() {
return scoreB - scoreA; return scoreB - scoreA;
}); });
divs.forEach(div => { for (const div of divs) {
console.debug(`Moving ${div.id} in {div.parentNode}}`); console.debug(`Moving ${div.id} in {div.parentNode}}`);
div.parentNode.appendChild(div); div.parentNode.appendChild(div);
}); }
return; return;
} }
const options = { const options = {
includeScore: true, includeScore: true,
threshold: 0.6, threshold: 0.6,
keys: ['title'] keys: ['title']
@ -305,7 +306,10 @@ function updateSearch() {
const fuse = new Fuse(list, options); const fuse = new Fuse(list, options);
const results = fuse.search(input.value); const results = fuse.search(input.value);
allDivs.forEach(div => div.style.display = 'none'); for (div of allDivs) {
div.style.display = 'none';
}
let divs = results.map(result => { let divs = results.map(result => {
let div = document.getElementById(result.item.id); let div = document.getElementById(result.item.id);
div.style.display = ''; div.style.display = '';
@ -321,9 +325,9 @@ function updateSearch() {
return scoreA - scoreB; // For ascending order. Use (scoreB - scoreA) for descending. return scoreA - scoreB; // For ascending order. Use (scoreB - scoreA) for descending.
}); });
divs.forEach(div => { for (div of divs) {
div.parentNode.appendChild(div); div.parentNode.appendChild(div);
}); }
} }
export function connectSearch() { export function connectSearch() {