Skip to content

Commit

Permalink
refactor: move executeCallback to the main file
Browse files Browse the repository at this point in the history
  • Loading branch information
thgreasi committed Jun 19, 2016
1 parent 7e7ab0c commit d152fa8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
5 changes: 2 additions & 3 deletions lib/getitems-generic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { executeCallback, getItemKeyValue } from './utils';
import { getItemKeyValue } from './utils';

export function getItemsGeneric(keys, callback) {
export function getItemsGeneric(keys/*, callback*/) {
var localforageInstance = this;
var promise = new Promise(function(resolve, reject) {
var itemPromises = [];
Expand All @@ -19,7 +19,6 @@ export function getItemsGeneric(keys, callback) {
resolve(result);
}).catch(reject);
});
executeCallback(promise, callback);
return promise;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/getitems-indexeddb.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { executeCallback } from './utils';
import IDBKeyRange from './idbKeyRange';

export function getItemsIndexedDB(keys, callback) {
export function getItemsIndexedDB(keys/*, callback*/) {
var localforageInstance = this;
function comparer (a,b) {
return a < b ? -1 : a > b ? 1 : 0;
Expand Down Expand Up @@ -66,6 +65,5 @@ export function getItemsIndexedDB(keys, callback) {
};
}).catch(reject);
});
executeCallback(promise, callback);
return promise;
}
5 changes: 2 additions & 3 deletions lib/getitems-websql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getSerializerPromise, executeCallback } from './utils';
import { getSerializerPromise } from './utils';

export function getItemsWebsql(keys, callback) {
export function getItemsWebsql(keys/*, callback*/) {
var localforageInstance = this;
var promise = new Promise(function(resolve, reject) {
localforageInstance.ready().then(function() {
Expand Down Expand Up @@ -42,6 +42,5 @@ export function getItemsWebsql(keys, callback) {
});
}).catch(reject);
});
executeCallback(promise, callback);
return promise;
}
24 changes: 13 additions & 11 deletions lib/localforage-getitems.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ export { getItemsGeneric } from './getitems-generic';
export function localforageGetItems(keys, callback) {
var localforageInstance = this;

var promise;
if (!arguments.length || keys === null) {
var promise = getAllItemsUsingIterate.call(localforageInstance);
executeCallback(promise, callback);
return promise;
}

var currentDriver = localforageInstance.driver();
if (currentDriver === localforageInstance.INDEXEDDB) {
return getItemsIndexedDB.call(localforageInstance, keys, callback);
} else if (currentDriver === localforageInstance.WEBSQL) {
return getItemsWebsql.call(localforageInstance, keys, callback);
promise = getAllItemsUsingIterate.apply(localforageInstance);
} else {
return getItemsGeneric.call(localforageInstance, keys, callback);
var currentDriver = localforageInstance.driver();
if (currentDriver === localforageInstance.INDEXEDDB) {
promise = getItemsIndexedDB.apply(localforageInstance, arguments);
} else if (currentDriver === localforageInstance.WEBSQL) {
promise = getItemsWebsql.apply(localforageInstance, arguments);
} else {
promise = getItemsGeneric.apply(localforageInstance, arguments);
}
}

executeCallback(promise, callback);
return promise;
}


Expand Down
1 change: 1 addition & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function executeCallback(promise, callback) {
callback(error);
});
}
return promise;
}

export function getItemKeyValue(key, callback) {
Expand Down

0 comments on commit d152fa8

Please sign in to comment.