Skip to content

Commit 42b9467

Browse files
committed
Allowed IDBDelete to be used without establishing a connection
1 parent fb38784 commit 42b9467

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

dist/SpringRoll-Container-umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SavedData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ export class SavedData {
138138
* @param {*} callback The callback to be run on success or error. One value will be passed into this function
139139
*/
140140
IDBDeleteDB(dbName, options = null, callback = {}) {
141-
const request = options ? indexedDB.deleteDatabase(dbName, options): indexedDB.deleteDatabase(dbName);
141+
const request = options != null ? indexedDB.deleteDatabase(dbName, options): indexedDB.deleteDatabase(dbName);
142142

143-
request.onsuccess = () => {
144-
callback({result: 'Success: Database Deleted', success: true});
143+
request.onsuccess = (e) => {
144+
callback({result: 'Success: Database Deleted, returned: ' + e.result, success: true});
145145
};
146146
request.onerror = () => {
147147
callback({result: request.error.toString(), success: false});

src/SavedDataHandler.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,13 @@ export class SavedDataHandler {
140140
IDBClose(callback) {
141141
this.savedData.IDBClose(callback);
142142
}
143+
/**
144+
* Closes the connection to the database
145+
* @param {function} callback The method to call on success or failure. A single value will be passed in
146+
*/
147+
IDBDeleteDB(dbName, options, callback) {
148+
const sd = new SavedData(dbName);
149+
sd.IDBDeleteDB(dbName, options, callback);
150+
}
143151

144152
}

src/plugins/UserDataPlugin.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class UserDataPlugin extends BasePlugin {
2727
this.onIDBClose = this.onIDBClose.bind(this);
2828
this.IDBReadAll = this.onIDBReadAll.bind(this);
2929
this.onIDBGetVersion = this.onIDBGetVersion.bind(this);
30+
this.onIDBDeleteDB = this.onIDBDeleteDB.bind(this);
3031

3132
this.savedDataHandler = null;
3233
}
@@ -49,6 +50,7 @@ export class UserDataPlugin extends BasePlugin {
4950
this.client.on('IDBUpdate', this.onIDBUpdate);
5051
this.client.on('IDBClose', this.onIDBClose);
5152
this.client.on('IDBGetVersion', this.onIDBGetVersion);
53+
this.client.on('IDBDeleteDB', this.onIDBDeleteDB);
5254

5355
}
5456

@@ -157,8 +159,6 @@ export class UserDataPlugin extends BasePlugin {
157159
* @param type - The type of request being sent
158160
*/
159161
onIDBReadAll({ type, data: {storeName, count} }) {
160-
console.log('got to plugin');
161-
162162
this.savedDataHandler.IDBReadAll(storeName, count, value => this.client.send(type, value));
163163
}
164164

@@ -179,4 +179,14 @@ export class UserDataPlugin extends BasePlugin {
179179
onIDBClose({type}) {
180180
this.savedDataHandler.IDBClose(value => this.client.send(type, value));
181181
}
182+
/**
183+
* Close the connection with the database
184+
* @param type - The type of request being sent
185+
*/
186+
onIDBDeleteDB({type, data: {dbName, options }}) {
187+
const sdh = new SavedDataHandler();
188+
189+
190+
sdh.IDBDeleteDB(dbName, options, value => this.client.send(type, value));
191+
}
182192
}

0 commit comments

Comments
 (0)