Skip to content

Commit bc655ae

Browse files
committed
refactor: use async await
1 parent bbe1417 commit bc655ae

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/installSW.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import { log } from './utils.js'
22

3-
export function installSW(swLocation) {
3+
export async function installSW(swLocation) {
44
if (navigator && window && 'serviceWorker' in navigator) {
5-
window.addEventListener('load', function() {
6-
navigator.serviceWorker.register(`${swLocation}pokeapi-js-wrapper-sw.js`, { scope: './' })
7-
.catch(error => {
8-
log('SW installation failed with the following error:')
9-
log(error)
10-
})
11-
})
5+
try {
6+
const r = await navigator.serviceWorker.register(`${swLocation}pokeapi-js-wrapper-sw.js`, { scope: './' })
7+
} catch (error) {
8+
log('SW installation failed with the following error:')
9+
log(error)
10+
}
1211
}
1312
}

test/example-sw.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title>SW test</title>
55
<script type="module">
66
import {Pokedex} from '../src/index.js'
7-
const P = await Pokedex.init({ cacheImages: true, swLocation: '/pokeapi-js-wrapper/test/' });
7+
const P = await Pokedex.init({ cacheImages: true, swLocation: './' });
88
</script>
99
</head>
1010

0 commit comments

Comments
 (0)