idb-kv-store
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -1,1 +0,1 @@ | ||
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.IdbKvStore=e()}})(function(){var e,t,r;return function e(t,r,n){function s(i,a){if(!r[i]){if(!t[i]){var u=typeof require=="function"&&require;if(!a&&u)return u(i,!0);if(o)return o(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[i]={exports:{}};t[i][0].call(c.exports,function(e){var r=t[i][1][e];return s(r?r:e)},c,c.exports,e,t,r,n)}return r[i].exports}var o=typeof require=="function"&&require;for(var i=0;i<n.length;i++)s(n[i]);return s}({1:[function(e,t,r){function n(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}t.exports=n;n.EventEmitter=n;n.prototype._events=undefined;n.prototype._maxListeners=undefined;n.defaultMaxListeners=10;n.prototype.setMaxListeners=function(e){if(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");this._maxListeners=e;return this};n.prototype.emit=function(e){var t,r,n,o,u,l;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||i(this._events.error)&&!this._events.error.length){t=arguments[1];if(t instanceof Error){throw t}else{var c=new Error('Uncaught, unspecified "error" event. ('+t+")");c.context=t;throw c}}}r=this._events[e];if(a(r))return false;if(s(r)){switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1);r.apply(this,o)}}else if(i(r)){o=Array.prototype.slice.call(arguments,1);l=r.slice();n=l.length;for(u=0;u<n;u++)l[u].apply(this,o)}return true};n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",e,s(t.listener)?t.listener:t);if(!this._events[e])this._events[e]=t;else if(i(this._events[e]))this._events[e].push(t);else this._events[e]=[this._events[e],t];if(i(this._events[e])&&!this._events[e].warned){if(!a(this._maxListeners)){r=this._maxListeners}else{r=n.defaultMaxListeners}if(r&&r>0&&this._events[e].length>r){this._events[e].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[e].length);if(typeof console.trace==="function"){console.trace()}}}return this};n.prototype.on=n.prototype.addListener;n.prototype.once=function(e,t){if(!s(t))throw TypeError("listener must be a function");var r=false;function n(){this.removeListener(e,n);if(!r){r=true;t.apply(this,arguments)}}n.listener=t;this.on(e,n);return this};n.prototype.removeListener=function(e,t){var r,n,o,a;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;r=this._events[e];o=r.length;n=-1;if(r===t||s(r.listener)&&r.listener===t){delete this._events[e];if(this._events.removeListener)this.emit("removeListener",e,t)}else if(i(r)){for(a=o;a-- >0;){if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}}if(n<0)return this;if(r.length===1){r.length=0;delete this._events[e]}else{r.splice(n,1)}if(this._events.removeListener)this.emit("removeListener",e,t)}return this};n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[e])delete this._events[e];return this}if(arguments.length===0){for(t in this._events){if(t==="removeListener")continue;this.removeAllListeners(t)}this.removeAllListeners("removeListener");this._events={};return this}r=this._events[e];if(s(r)){this.removeListener(e,r)}else if(r){while(r.length)this.removeListener(e,r[r.length-1])}delete this._events[e];return this};n.prototype.listeners=function(e){var t;if(!this._events||!this._events[e])t=[];else if(s(this._events[e]))t=[this._events[e]];else t=this._events[e].slice();return t};n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(s(t))return 1;else if(t)return t.length}return 0};n.listenerCount=function(e,t){return e.listenerCount(t)};function s(e){return typeof e==="function"}function o(e){return typeof e==="number"}function i(e){return typeof e==="object"&&e!==null}function a(e){return e===void 0}},{}],2:[function(e,t,r){if(typeof Object.create==="function"){t.exports=function e(t,r){t.super_=r;t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:false,writable:true,configurable:true}})}}else{t.exports=function e(t,r){t.super_=r;var n=function(){};n.prototype=r.prototype;t.prototype=new n;t.prototype.constructor=t}}},{}],"/":[function(e,t,r){t.exports=a;var n=e("events").EventEmitter;var s=e("inherits");var o=typeof window==="undefined"?self:window;var i=o.indexedDB||o.mozIndexedDB||o.webkitIndexedDB||o.msIndexedDB;a.INDEXEDDB_SUPPORT=i!=null;a.BROADCAST_SUPPORT=o.BroadcastChannel!=null;s(a,n);function a(e,t,r){var s=this;if(typeof e!=="string")throw new Error("A name must be supplied of type string");if(!i)throw new Error("IndexedDB not supported");if(typeof t==="function")return new a(e,null,t);if(!(this instanceof a))return new a(e,t,r);if(!t)t={};n.call(s);s._name=e;s._db=null;s._closed=false;s._queue=[];s._Channel=t.channel||o.BroadcastChannel;s._channel=null;var u=i.open(e);u.onerror=l;u.onsuccess=c;u.onupgradeneeded=f;s.on("newListener",v);function l(e){s.close();s._handleError(e,r)}function c(e){if(s._closed){e.target.result.close()}else{s._db=e.target.result;s._db.onclose=h;s._drainQueue();if(r)r(null);s.emit("open")}}function f(e){if(s._closed)return;var t=e.target.result;t.createObjectStore("kv",{autoIncrement:true})}function h(){s.close()}function v(e){if(e!=="add"&&e!=="set"&&e!=="remove")return;if(!s._Channel)return s.emit("error",new Error("No BroadcastChannel support"));s._channel=new s._Channel(s._name);s._channel.onmessage=d;s.removeListener("newListener",v)}function d(e){if(e.data.method==="add")s.emit("add",e.data);else if(e.data.method==="set")s.emit("set",e.data);else if(e.data.method==="remove")s.emit("remove",e.data)}}a.prototype.get=function(e,t){var r=this;if(r._closed)throw new Error("Database is closed");var n=u(t);if(!r._db){r._queue.push([r.get,e,n.cb])}else if(Array.isArray(e)){var s=[];var o=false;var i=0;e.forEach(function(t,a){r.get(e[a],function(t,r){if(o)return;if(t){o=true;n.cb(t)}s[a]=r;i++;if(i===e.length)n.cb(null,s)})})}else{var a=r._db.transaction("kv","readonly");var l=a.objectStore("kv").get(e);l.onsuccess=function(e){n.cb(null,e.target.result)};a.onerror=function(e){r._handleError(e,n.cb)}}return n.promise};a.prototype.set=function(e,t,r){var n=this;if(n._closed)throw new Error("Database is closed");var s=u(r);if(!n._db){n._queue.push([n.set,e,t,s.cb])}else{var o=n._db.transaction("kv","readwrite");var i=o.objectStore("kv").put(t,e);i.onsuccess=function(){if(n._channel){n._channel.postMessage({method:"set",key:e,value:t})}s.cb(null)};o.onerror=function(e){n._handleError(e,s.cb)}}return s.promise};a.prototype.json=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.json,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").openCursor();var o={};s.onsuccess=function(e){var t=e.target.result;if(t){o[t.key]=t.value;t.continue()}else{r.cb(null,o)}};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.keys=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.keys,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").openCursor();var o=[];s.onsuccess=function(e){var t=e.target.result;if(t){o.push(t.key);t.continue()}else{r.cb(null,o)}};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.values=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.values,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").openCursor();var o=[];s.onsuccess=function(e){var t=e.target.result;if(t){o.push(t.value);t.continue()}else{r.cb(null,o)}};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.remove=function(e,t){var r=this;if(r._closed)throw new Error("Database is closed");var n=u(t);if(!r._db){r._queue.push([r.remove,e,n.cb])}else{var s=r._db.transaction("kv","readwrite");var o=s.objectStore("kv").delete(e);o.onsuccess=function(t){if(r._channel){r._channel.postMessage({method:"remove",key:e})}n.cb(null)};s.onerror=function(e){r._handleError(e,n.cb)}}return n.promise};a.prototype.clear=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.clear,r.cb])}else{var n=t._db.transaction("kv","readwrite");var s=n.objectStore("kv").clear();s.onsuccess=function(e){r.cb(null)};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.count=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.count,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").count();s.onsuccess=function(e){r.cb(null,e.target.result)};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.add=function(e,t,r){var n=this;if(n._closed)throw new Error("Database is closed");if(typeof t==="function"||arguments.length===1)return n.add(undefined,e,t);var s=u(r);if(!n._db){n._queue.push([n.add,e,t,s.cb])}else{var o=n._db.transaction("kv","readwrite");var i=e==null?o.objectStore("kv").add(t):o.objectStore("kv").add(t,e);i.onsuccess=function(r){if(n._channel){n._channel.postMessage({method:"add",key:e,value:t})}s.cb(null)};o.onerror=function(e){n._handleError(e,s.cb)}}return s.promise};a.prototype.close=function(){if(this._closed)return;this._closed=true;if(this._db)this._db.close();if(this._channel)this._channel.close();this._db=null;this._channel=null;this._queue=null;this.emit("close");this.removeAllListeners()};a.prototype._drainQueue=function(){var e=this;for(var t=0;t<e._queue.length;t++){var r=e._queue[t];var n=r.splice(1);r[0].apply(e,n)}e._queue=null};a.prototype._handleError=function(e,t){var r=e.target.error;e.preventDefault();if(t){t(r)}else{this.emit("error",r)}};function u(e){var t={cb:e};if(typeof Promise==="function"&&e==null){t.promise=new Promise(function(e,r){t.cb=function(t,n){if(t)return r(t);else return e(n)}})}if(!t.cb)t.cb=function e(){};return t}},{events:1,inherits:2}]},{},[])("/")}); | ||
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.IdbKvStore=e()}})(function(){var e,t,r;return function e(t,r,n){function s(i,a){if(!r[i]){if(!t[i]){var u=typeof require=="function"&&require;if(!a&&u)return u(i,!0);if(o)return o(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var c=r[i]={exports:{}};t[i][0].call(c.exports,function(e){var r=t[i][1][e];return s(r?r:e)},c,c.exports,e,t,r,n)}return r[i].exports}var o=typeof require=="function"&&require;for(var i=0;i<n.length;i++)s(n[i]);return s}({1:[function(e,t,r){function n(){this._events=this._events||{};this._maxListeners=this._maxListeners||undefined}t.exports=n;n.EventEmitter=n;n.prototype._events=undefined;n.prototype._maxListeners=undefined;n.defaultMaxListeners=10;n.prototype.setMaxListeners=function(e){if(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");this._maxListeners=e;return this};n.prototype.emit=function(e){var t,r,n,o,u,l;if(!this._events)this._events={};if(e==="error"){if(!this._events.error||i(this._events.error)&&!this._events.error.length){t=arguments[1];if(t instanceof Error){throw t}else{var c=new Error('Uncaught, unspecified "error" event. ('+t+")");c.context=t;throw c}}}r=this._events[e];if(a(r))return false;if(s(r)){switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1);r.apply(this,o)}}else if(i(r)){o=Array.prototype.slice.call(arguments,1);l=r.slice();n=l.length;for(u=0;u<n;u++)l[u].apply(this,o)}return true};n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");if(!this._events)this._events={};if(this._events.newListener)this.emit("newListener",e,s(t.listener)?t.listener:t);if(!this._events[e])this._events[e]=t;else if(i(this._events[e]))this._events[e].push(t);else this._events[e]=[this._events[e],t];if(i(this._events[e])&&!this._events[e].warned){if(!a(this._maxListeners)){r=this._maxListeners}else{r=n.defaultMaxListeners}if(r&&r>0&&this._events[e].length>r){this._events[e].warned=true;console.error("(node) warning: possible EventEmitter memory "+"leak detected. %d listeners added. "+"Use emitter.setMaxListeners() to increase limit.",this._events[e].length);if(typeof console.trace==="function"){console.trace()}}}return this};n.prototype.on=n.prototype.addListener;n.prototype.once=function(e,t){if(!s(t))throw TypeError("listener must be a function");var r=false;function n(){this.removeListener(e,n);if(!r){r=true;t.apply(this,arguments)}}n.listener=t;this.on(e,n);return this};n.prototype.removeListener=function(e,t){var r,n,o,a;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;r=this._events[e];o=r.length;n=-1;if(r===t||s(r.listener)&&r.listener===t){delete this._events[e];if(this._events.removeListener)this.emit("removeListener",e,t)}else if(i(r)){for(a=o;a-- >0;){if(r[a]===t||r[a].listener&&r[a].listener===t){n=a;break}}if(n<0)return this;if(r.length===1){r.length=0;delete this._events[e]}else{r.splice(n,1)}if(this._events.removeListener)this.emit("removeListener",e,t)}return this};n.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener){if(arguments.length===0)this._events={};else if(this._events[e])delete this._events[e];return this}if(arguments.length===0){for(t in this._events){if(t==="removeListener")continue;this.removeAllListeners(t)}this.removeAllListeners("removeListener");this._events={};return this}r=this._events[e];if(s(r)){this.removeListener(e,r)}else if(r){while(r.length)this.removeListener(e,r[r.length-1])}delete this._events[e];return this};n.prototype.listeners=function(e){var t;if(!this._events||!this._events[e])t=[];else if(s(this._events[e]))t=[this._events[e]];else t=this._events[e].slice();return t};n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(s(t))return 1;else if(t)return t.length}return 0};n.listenerCount=function(e,t){return e.listenerCount(t)};function s(e){return typeof e==="function"}function o(e){return typeof e==="number"}function i(e){return typeof e==="object"&&e!==null}function a(e){return e===void 0}},{}],2:[function(e,t,r){if(typeof Object.create==="function"){t.exports=function e(t,r){t.super_=r;t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:false,writable:true,configurable:true}})}}else{t.exports=function e(t,r){t.super_=r;var n=function(){};n.prototype=r.prototype;t.prototype=new n;t.prototype.constructor=t}}},{}],"/":[function(e,t,r){t.exports=a;var n=e("events").EventEmitter;var s=e("inherits");var o=typeof window==="undefined"?self:window;var i=o.indexedDB||o.mozIndexedDB||o.webkitIndexedDB||o.msIndexedDB;a.INDEXEDDB_SUPPORT=i!=null;a.BROADCAST_SUPPORT=o.BroadcastChannel!=null;s(a,n);function a(e,t,r){var s=this;if(typeof e!=="string")throw new Error("A name must be supplied of type string");if(!i)throw new Error("IndexedDB not supported");if(typeof t==="function")return new a(e,null,t);if(!(this instanceof a))return new a(e,t,r);if(!t)t={};n.call(s);s._db=null;s._closed=false;s._queue=[];s._channel=null;var u=t.channel||o.BroadcastChannel;if(u){s._channel=new u(e);s._channel.onmessage=p}var l=i.open(e);l.onerror=c;l.onsuccess=f;l.onupgradeneeded=h;s.on("newListener",d);function c(e){s.close();s._handleError(e,r)}function f(e){if(s._closed){e.target.result.close()}else{s._db=e.target.result;s._db.onclose=v;s._drainQueue();if(r)r(null);s.emit("open")}}function h(e){if(s._closed)return;var t=e.target.result;t.createObjectStore("kv",{autoIncrement:true})}function v(){s.close()}function d(e){if(e!=="add"&&e!=="set"&&e!=="remove")return;if(!s._channel)return s.emit("error",new Error("No BroadcastChannel support"))}function p(e){if(e.data.method==="add")s.emit("add",e.data);else if(e.data.method==="set")s.emit("set",e.data);else if(e.data.method==="remove")s.emit("remove",e.data)}}a.prototype.get=function(e,t){var r=this;if(r._closed)throw new Error("Database is closed");var n=u(t);if(!r._db){r._queue.push([r.get,e,n.cb])}else if(Array.isArray(e)){var s=[];var o=false;var i=0;e.forEach(function(t,a){r.get(e[a],function(t,r){if(o)return;if(t){o=true;n.cb(t)}s[a]=r;i++;if(i===e.length)n.cb(null,s)})})}else{var a=r._db.transaction("kv","readonly");var l=a.objectStore("kv").get(e);l.onsuccess=function(e){n.cb(null,e.target.result)};a.onerror=function(e){r._handleError(e,n.cb)}}return n.promise};a.prototype.set=function(e,t,r){var n=this;if(n._closed)throw new Error("Database is closed");var s=u(r);if(!n._db){n._queue.push([n.set,e,t,s.cb])}else{var o=n._db.transaction("kv","readwrite");var i=o.objectStore("kv").put(t,e);i.onsuccess=function(){if(n._channel){n._channel.postMessage({method:"set",key:e,value:t})}s.cb(null)};o.onerror=function(e){n._handleError(e,s.cb)}}return s.promise};a.prototype.json=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.json,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").openCursor();var o={};s.onsuccess=function(e){var t=e.target.result;if(t){o[t.key]=t.value;t.continue()}else{r.cb(null,o)}};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.keys=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.keys,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").openCursor();var o=[];s.onsuccess=function(e){var t=e.target.result;if(t){o.push(t.key);t.continue()}else{r.cb(null,o)}};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.values=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.values,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").openCursor();var o=[];s.onsuccess=function(e){var t=e.target.result;if(t){o.push(t.value);t.continue()}else{r.cb(null,o)}};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.remove=function(e,t){var r=this;if(r._closed)throw new Error("Database is closed");var n=u(t);if(!r._db){r._queue.push([r.remove,e,n.cb])}else{var s=r._db.transaction("kv","readwrite");var o=s.objectStore("kv").delete(e);o.onsuccess=function(t){if(r._channel){r._channel.postMessage({method:"remove",key:e})}n.cb(null)};s.onerror=function(e){r._handleError(e,n.cb)}}return n.promise};a.prototype.clear=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.clear,r.cb])}else{var n=t._db.transaction("kv","readwrite");var s=n.objectStore("kv").clear();s.onsuccess=function(e){r.cb(null)};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.count=function(e){var t=this;if(t._closed)throw new Error("Database is closed");var r=u(e);if(!t._db){t._queue.push([t.count,r.cb])}else{var n=t._db.transaction("kv","readonly");var s=n.objectStore("kv").count();s.onsuccess=function(e){r.cb(null,e.target.result)};n.onerror=function(e){t._handleError(e,r.cb)}}return r.promise};a.prototype.add=function(e,t,r){var n=this;if(n._closed)throw new Error("Database is closed");if(typeof t==="function"||arguments.length===1)return n.add(undefined,e,t);var s=u(r);if(!n._db){n._queue.push([n.add,e,t,s.cb])}else{var o=n._db.transaction("kv","readwrite");var i=e==null?o.objectStore("kv").add(t):o.objectStore("kv").add(t,e);i.onsuccess=function(r){if(n._channel){n._channel.postMessage({method:"add",key:e,value:t})}s.cb(null)};o.onerror=function(e){n._handleError(e,s.cb)}}return s.promise};a.prototype.close=function(){if(this._closed)return;this._closed=true;if(this._db)this._db.close();if(this._channel)this._channel.close();this._db=null;this._channel=null;this._queue=null;this.emit("close");this.removeAllListeners()};a.prototype._drainQueue=function(){var e=this;for(var t=0;t<e._queue.length;t++){var r=e._queue[t];var n=r.splice(1);r[0].apply(e,n)}e._queue=null};a.prototype._handleError=function(e,t){var r=e.target.error;e.preventDefault();if(t){t(r)}else{this.emit("error",r)}};function u(e){var t={cb:e};if(typeof Promise==="function"&&e==null){t.promise=new Promise(function(e,r){t.cb=function(t,n){if(t)return r(t);else return e(n)}})}if(!t.cb)t.cb=function e(){};return t}},{events:1,inherits:2}]},{},[])("/")}); |
13
index.js
@@ -23,9 +23,13 @@ module.exports = IdbKvStore | ||
self._name = name | ||
self._db = null | ||
self._closed = false | ||
self._queue = [] | ||
self._Channel = opts.channel || global.BroadcastChannel | ||
self._channel = null | ||
var Channel = opts.channel || global.BroadcastChannel | ||
if (Channel) { | ||
self._channel = new Channel(name) | ||
self._channel.onmessage = onChange | ||
} | ||
var request = IDB.open(name) | ||
@@ -67,6 +71,3 @@ request.onerror = onerror | ||
if (event !== 'add' && event !== 'set' && event !== 'remove') return | ||
if (!self._Channel) return self.emit('error', new Error('No BroadcastChannel support')) | ||
self._channel = new self._Channel(self._name) | ||
self._channel.onmessage = onChange | ||
self.removeListener('newListener', onNewListener) | ||
if (!self._channel) return self.emit('error', new Error('No BroadcastChannel support')) | ||
} | ||
@@ -73,0 +74,0 @@ |
{ | ||
"name": "idb-kv-store", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Persistent key-value store for web browsers backed by IndexedDB", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
21
test.js
@@ -376,2 +376,23 @@ var IdbKvStore = require('.') | ||
test('broadcast event event with no listener', function (t) { | ||
t.timeoutAfter(3000) | ||
if (!IdbKvStore.BROADCAST_SUPPORT) return t.end() | ||
var name = '' + (Math.round(9e16 * Math.random())) | ||
var storeA = IdbKvStore(name) | ||
var storeB = IdbKvStore(name) | ||
storeB.on('add', onAdd) | ||
storeA.add('foo', 'bar') | ||
function onAdd (change) { | ||
t.deepEqual({ | ||
method: 'add', | ||
key: 'foo', | ||
value: 'bar' | ||
}, change) | ||
t.end() | ||
} | ||
}) | ||
function createStore (cb) { | ||
@@ -378,0 +399,0 @@ var name = '' + (Math.round(9e16 * Math.random())) |
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
42181
800