MCPcopy
hub / github.com/localForage/localForage / dropInstance

Function dropInstance

src/drivers/indexeddb.js:950–1100  ·  view source on GitHub ↗
(options, callback)

Source from the content-addressed store, hash-verified

948}
949
950function dropInstance(options, callback) {
951 callback = getCallback.apply(this, arguments);
952
953 var currentConfig = this.config();
954 options = (typeof options !== 'function' && options) || {};
955 if (!options.name) {
956 options.name = options.name || currentConfig.name;
957 options.storeName = options.storeName || currentConfig.storeName;
958 }
959
960 var self = this;
961 var promise;
962 if (!options.name) {
963 promise = Promise.reject('Invalid arguments');
964 } else {
965 const isCurrentDb =
966 options.name === currentConfig.name && self._dbInfo.db;
967
968 const dbPromise = isCurrentDb
969 ? Promise.resolve(self._dbInfo.db)
970 : _getOriginalConnection(options).then(db => {
971 const dbContext = dbContexts[options.name];
972 const forages = dbContext.forages;
973 dbContext.db = db;
974 for (var i = 0; i < forages.length; i++) {
975 forages[i]._dbInfo.db = db;
976 }
977 return db;
978 });
979
980 if (!options.storeName) {
981 promise = dbPromise.then(db => {
982 _deferReadiness(options);
983
984 const dbContext = dbContexts[options.name];
985 const forages = dbContext.forages;
986
987 db.close();
988 for (var i = 0; i < forages.length; i++) {
989 const forage = forages[i];
990 forage._dbInfo.db = null;
991 }
992
993 const dropDBPromise = new Promise((resolve, reject) => {
994 var req = idb.deleteDatabase(options.name);
995
996 req.onerror = () => {
997 const db = req.result;
998 if (db) {
999 db.close();
1000 }
1001 reject(req.error);
1002 };
1003
1004 req.onblocked = () => {
1005 // Closing all open connections in onversionchange handler should prevent this situation, but if
1006 // we do get here, it just means the request remains pending - eventually it will succeed or error
1007 console.warn(

Callers

nothing calls this directly

Calls 6

_getOriginalConnectionFunction · 0.85
_deferReadinessFunction · 0.85
_advanceReadinessFunction · 0.85
_rejectReadinessFunction · 0.85
configMethod · 0.65
executeCallbackFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…