Skip to content

Instantly share code, notes, and snippets.

View GautamPanickar's full-sized avatar
💭
Padam pam pishh!

Gautam Panickar SS GautamPanickar

💭
Padam pam pishh!
View GitHub Profile
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,
/**
* 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');
/**
* 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');
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');
@GautamPanickar
GautamPanickar / package.json
Created July 12, 2020 08:24
Service worker with Google's Workbox for Angular App - package.json scripts
{
"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"
},
}
@GautamPanickar
GautamPanickar / sw-handlers.ts
Last active July 19, 2020 07:48
Service worker with Google's Workbox for Angular App - handler file
export const BG_IMAGES_CACHE = 'bg-images-cache';
export class ServiceWorkerHandler {
private dbPromise: IDBOpenDBRequest;
constructor(dbPromise: IDBOpenDBRequest) {
this.dbPromise = dbPromise;
}
@GautamPanickar
GautamPanickar / service-worker.ts
Last active July 19, 2020 07:44
Service worker with Google's Workbox for Angular App - SW file
import {precacheAndRoute} from 'workbox-precaching';
import {registerRoute} from 'workbox-routing';
import { ServiceWorkerHandler } from './sw-handlers';
declare const self: any;
/**
* ------------------------------------
* Service Worker Listeners
* ------------------------------------
@GautamPanickar
GautamPanickar / tsconfig.js
Last active July 14, 2020 10:16
Service worker with Google's Workbox for Angular App - config files.
{
"compilerOptions": {
"typeRoots" : ["./typings"],
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"lib": [
"esnext",
"webworker"
@GautamPanickar
GautamPanickar / main.ts
Last active July 19, 2020 07:45
Service worker with Google's Workbox for Angular App - main file.
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();
}