GenSpectrum / dashboard-components

https://genspectrum.github.io/dashboard-components/
GNU Affero General Public License v3.0
2 stars 0 forks source link

Mutations over time: Add delay for proportion filter #421

Closed JonasKellerer closed 4 months ago

JonasKellerer commented 4 months ago

Currently, when users change the proportion, then the filtering step is directly initiated. Find a way to decouple this, so when the user changes the proportion filter, the changed values are shown, but the filtering is only performed after a small time period.

A part of the solution could be

function debounce(func: (proportion: number) => void, delayInMs: number) {
    let timeoutId: number | undefined;
    return (proportion: number) => {
        if (timeoutId) {
            clearTimeout(timeoutId);
        }
        timeoutId = window.setTimeout(() => {
            func(proportion);
        }, delayInMs);
    };
}