idb-keyval
Advanced tools
Comparing version 3.0.3 to 3.0.4
export class Store { | ||
readonly _dbp: Promise<IDBDatabase>; | ||
private _dbp: Promise<IDBDatabase>; | ||
constructor(dbName = 'keyval-store', readonly storeName = 'keyval') { | ||
this._dbp = new Promise((resolve, reject) => { | ||
const openreq = indexedDB.open(dbName, 1); | ||
const connection = (version?: number): Promise<IDBDatabase> => new Promise((resolve, reject) => { | ||
const openreq = indexedDB.open(dbName, version); | ||
openreq.onerror = () => reject(openreq.error); | ||
openreq.onsuccess = () => resolve(openreq.result); | ||
openreq.onsuccess = () => { | ||
// If a later version of this database wants to open, | ||
// close and create a new connection for the new version. | ||
openreq.result.onversionchange = () => { | ||
openreq.result.close(); | ||
this._dbp = connection(); | ||
} | ||
// If this database has been opened before, but never with this | ||
// storeName, the objectStore won't exist yet. In which case, | ||
// force an upgrade by opening a connection with version n+1. | ||
if (!openreq.result.objectStoreNames.contains(storeName)) { | ||
resolve(connection(openreq.result.version + 1)); | ||
} | ||
else { | ||
resolve(openreq.result); | ||
} | ||
} | ||
@@ -15,2 +31,4 @@ // First time setup: create an empty object store | ||
}); | ||
this._dbp = connection(); | ||
} | ||
@@ -66,3 +84,3 @@ | ||
// And openKeyCursor isn't supported by Safari. | ||
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function() { | ||
(store.openKeyCursor || store.openCursor).call(store).onsuccess = function () { | ||
if (!this.result) return; | ||
@@ -69,0 +87,0 @@ keys.push(this.result.key); |
{ | ||
"name": "idb-keyval", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "A super-simple-small keyval store built on top of IndexedDB", | ||
@@ -9,3 +9,5 @@ "main": "./dist/idb-keyval-cjs.js", | ||
"scripts": { | ||
"build": "del dist && rollup -c && uglifyjs --compress --mangle -o dist/idb-keyval-iife.min.js dist/idb-keyval-iife.js" | ||
"build": "del dist && rollup -c && npm run compress-iife && npm run compress-iife && npm run create-compat", | ||
"compress-iife": "uglifyjs --compress --mangle -o dist/idb-keyval-iife.min.js dist/idb-keyval-iife.js", | ||
"create-compat": "babel dist/idb-keyval-iife.js | uglifyjs --compress --mangle > dist/idb-keyval-iife-compat.min.js" | ||
}, | ||
@@ -35,2 +37,4 @@ "repository": { | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-preset-env": "^1.6.1", | ||
"del-cli": "^1.1.0", | ||
@@ -37,0 +41,0 @@ "rollup": "^0.56.5", |
@@ -8,3 +8,3 @@ # IDB-Keyval | ||
[localForage](https://github.com/localForage/localForage) offers similar functionality, but supports older browsers with broken/absent IDB implementations. Because of that, it's 7.4k, whereas idb-keyval is ~550 bytes. Also, it's tree-shaking friendly, so you'll probably end up using fewer than 450 bytes. Pick whichever works best for you! | ||
[localForage](https://github.com/localForage/localForage) offers similar functionality, but supports older browsers with broken/absent IDB implementations. Because of that, it's 7.4k, whereas idb-keyval is < 600 bytes. Also, it's tree-shaking friendly, so you'll probably end up using fewer than 500 bytes. Pick whichever works best for you! | ||
@@ -103,2 +103,4 @@ This is only a keyval store. If you need to do more complex things like iteration & indexing, check out [IDB on NPM](https://www.npmjs.com/package/idb) (a little heavier at 1.7k). The first example in its README is how to recreate this library. | ||
* `dist/idb-keyval-iife.js` can be used in browsers that don't support modules. `idbKeyval` is created as a global. | ||
* `dist/idb-keyval-iife.min.js` As above, but minified. | ||
* `dist/idb-keyval-iife-compat.min.js` As above, but works in older browsers such as IE 10. | ||
@@ -105,0 +107,0 @@ ## Updating from 2.x |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21090
15
329
125
7