Skip to content

Instantly share code, notes, and snippets.

@ankitamasand
Last active August 17, 2018 21:43
Show Gist options
  • Save ankitamasand/1ff6c67a63c0f2d62a5c82c7d8dcb3e3 to your computer and use it in GitHub Desktop.
Save ankitamasand/1ff6c67a63c0f2d62a5c82c7d8dcb3e3 to your computer and use it in GitHub Desktop.
function getProductData (productId) {
let productCount = 0
indexedDB.open('store', 1).then ( (db) => {
let transaction = db.transaction(['products'])
let productData = transaction.ObjectStore('products').get(productId).then (item => productCount = item.count)
})
return productCount
}
self.addEventListener('fetch', (event) => {
event.waitUnitil(
if (event.request.url.includes('/product') {
let productId = event.data.productId
let productCount = getProductData(productId)
indexedDB.open('store', 1, (db) => {
let productStore = db.createObjectStore('products', { keyPath: 'id' })
productStore.put({ id: productId, count: ++productCount })
})
}
)
})
@webxl
Copy link

webxl commented Aug 17, 2018

Line 12 is invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment