(options, callback)
| 948 | } |
| 949 | |
| 950 | function 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( |
nothing calls this directly
no test coverage detected
searching dependent graphs…