You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pages/app.js

47 lines
873 B
JavaScript

import { Project } from "./components/project.js"
customElements.define('m-project', Project)
3 years ago
class Setup {
constructor() {
this.loaded = false
}
async run() {
navigator.serviceWorker
.addEventListener('controllerchange', () => {
if (this.registration.active) {
this.loadIfReady()
}
})
await this.register()
this.loadIfReady()
}
3 years ago
async register() {
try {
this.registration =
await navigator.serviceWorker.register(
'/sw.js',
{scope: '/'}
)
} catch (err) {
console.error(
'error registering service worker', err
)
3 years ago
}
}
loadIfReady() {
if (
!this.loaded && this.registration.active
) {
document.body.appendChild(
document.createElement('m-project')
)
this.loaded = true
}
}
3 years ago
}
new Setup().run()