All files / src/utils panel-status-updater.js

100% Statements 13/13
100% Branches 1/1
100% Functions 5/5
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25  6x   6x 4x     6x 9x     6x 6x   6x 1x     6x   6x 6x 6x    
import promiseFinally from 'promise.prototype.finally';
promiseFinally.shim(); // will only shim if needed
 
export const setPanelLoading = elm => {
    elm.classList.add('is-loading');
};
 
export const setPanelLoaded = elm => {
    elm.classList.remove('is-loading');
};
 
export const panelStatusUpdater = (container, promiseToAwait, timeout = 300) => {
    container.classList.add('panel-updater');
 
    const deferredOverlay = setTimeout(() => {
        setPanelLoading(container);
    }, timeout);
 
    return promiseToAwait
        .finally(data => {
            clearTimeout(deferredOverlay);
            setPanelLoaded(container);
            return data;
        });
};