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
var connection = indexedDB.open('testdb', 1); | |
connection.onupgradeneeded = (e) => { | |
var db = e.target.result; | |
var routineStore = db.createObjectStore('contacts'); | |
routineStore.onerror = (evt) => { | |
console.log('Contacts store could not be created.'); | |
}; | |
}; | |
var contact = { | |
active: true, |
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
/** | |
* Here all objects are added into store in a single transaction. | |
*/ | |
connection.onsuccess = (e) => { | |
var db = e.target.result; | |
let startedTime = Date.now(); | |
console.log(`Started on - ${startedTime}`); | |
var transaction = db.transaction('contacts', 'readwrite'); | |
var store = transaction.objectStore('contacts'); |
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
/** | |
* Here also, all objects are added in a single transaction, with the difference being, before addition, | |
* the object is checked for equality. If same object exists, then update is performed, otherwise addition is proceeded. | |
*/ | |
connection.onsuccess = (e) => { | |
var db = e.target.result; | |
let startedTime = Date.now(); | |
console.log(`Started on - ${startedTime}`); | |
var transaction = db.transaction('contacts', 'readwrite'); | |
var store = transaction.objectStore('contacts'); |
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
connection.onsuccess = (e) => { | |
var db = e.target.result; | |
let startedTime = Date.now(); | |
console.log(`Started on - ${startedTime}`); | |
const trans = db.transaction('contacts', 'readwrite'); | |
const store = trans.objectStore('contacts'); | |
store.clear(); | |
let addedContacts = 0; | |
for (let i = 0; i < totalLength; i++ ) { | |
const transaction = db.transaction('contacts', 'readwrite'); |
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
{ | |
"name": "swtest", | |
"version": "0.0.0", | |
"scripts": { | |
"ng": "ng", | |
"build-prod": "ng build --prod", | |
"postbuild-prod": "npm run sw-prod-webpack", | |
"sw-prod-webpack": "rimraf ./dist/swtest/service-worker.js && webpack --config ./src/sw/webpack.sw.config.js --progress --colors && workbox injectManifest ./src/sw/workbox-config.js && http-server dist/swtest -p 4200" | |
}, | |
} |
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
export const BG_IMAGES_CACHE = 'bg-images-cache'; | |
export class ServiceWorkerHandler { | |
private dbPromise: IDBOpenDBRequest; | |
constructor(dbPromise: IDBOpenDBRequest) { | |
this.dbPromise = dbPromise; | |
} |
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
import {precacheAndRoute} from 'workbox-precaching'; | |
import {registerRoute} from 'workbox-routing'; | |
import { ServiceWorkerHandler } from './sw-handlers'; | |
declare const self: any; | |
/** | |
* ------------------------------------ | |
* Service Worker Listeners | |
* ------------------------------------ |
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
{ | |
"compilerOptions": { | |
"typeRoots" : ["./typings"], | |
"module": "esnext", | |
"moduleResolution": "node", | |
"importHelpers": true, | |
"target": "es2015", | |
"lib": [ | |
"esnext", | |
"webworker" |
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
import { enableProdMode } from '@angular/core'; | |
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; | |
import { AppModule } from './app/app.module'; | |
import { environment } from './environments/environment'; | |
import {Workbox} from 'workbox-window'; | |
if (environment.production) { | |
enableProdMode(); | |
} |