Events


bit Bswup calls the handler js function and pass the event arguments to it for each of its event.

Bswup Handler function
below you can see a sample bswup events handler function in js:
const appEl = document.getElementById('app');
const bswupEl = document.getElementById('bit-bswup');
const progressBar = document.getElementById('bit-bswup-progress-bar');
const reloadButton = document.getElementById('bit-bswup-reload');

function bitBswupHandler(type, data) {
    switch (type)
    {
        case BswupMessage.updateFound: return console.log('an update found.');

        case BswupMessage.stateChanged: return console.log('state has changed to:', data.currentTarget.state);

        case BswupMessage.activate: return console.log('new version activated:', data.version);

        case BswupMessage.downloadStarted:
            appEl.style.display = 'none';
            bswupEl.style.display = 'block';
            return console.log('downloading assets started:', data?.version);

        case BswupMessage.downloadProgress:
            progressBar.style.width = `${percent}%`;
            return console.log('asset downloaded:', data);

        case BswupMessage.downloadFinished:
            if (data.firstInstall) {
                data.reload().then(() => {
                    appEl.style.display = 'block';
                    bswupEl.style.display = 'none';
                });
            } else {
                reloadButton.style.display = 'block';
                reloadButton.onclick = data.reload;
            }
            return console.log('downloading assets finished.');

        case BswupMessage.updateReady:
            reloadButton.style.display = 'block';
            reloadButton.onclick = data.reload;
            return console.log('new update ready.');
    }
}
Bswup Events

All the bit Bswup events are as follows:

updateFound: when a new update for the app is found by the bit Bswup's Service Worker.

stateChanged: when the state of the Service Worker is changed.

activate: when a new version of the Service Worker is activated.

downloadStarted: when download of the new version of the app started.

downloadProgress: the progress of downloading the new version of the app.

downloadFinished: when the download of the new version of the app finished.

updateReady: when the new version of the app is ready to apply.