-
-
Save ankitamasand/1ff6c67a63c0f2d62a5c82c7d8dcb3e3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) | |
}) | |
} | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 12 is invalid.