Skip to content

Instantly share code, notes, and snippets.

@eppfel
Last active January 26, 2016 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eppfel/de8b5b614682232e518b to your computer and use it in GitHub Desktop.
Save eppfel/de8b5b614682232e518b to your computer and use it in GitHub Desktop.
var interactionsCollection = [];
localforage.getItem('Interactions').then(function (interactionKeys) {
interactionKeys.forEach(function(key) {
localforage.getItem(key).then(function (data) { interactionsCollection.push(data)})})
});
var allInteractions = [];
var keyc = 0;
localforage.keys(function(keys) {
keys.forEach(function (key){
keyc++;
if (-1 < key.search(/^Interaction\/.+/)) {
localforage.getItem(key).then(function (value) {allInteractions.push(value);});
}
});
});
//This has to be executed afterwards, because the operations are asynchronous, but not yet combined
var missing = allInteractions.filter(function (interaction) {
return !interactionsCollection.some(function (colInteraction){
return colInteraction.id == interaction.id;
});
});
//Obsolete: Compare and update
// function doctor() {
localforage.getItem('Interactions').then(function (interactionsCollection) {
localforage.keys(function(storageKeys) {
var tmpCollection = interactionsCollection;
storageKeys.forEach(function (key) {
if (key.search(/^Interaction\/.+/) > -1 ) {
var i = tmpCollection.indexOf(key);
if (i > -1) {
tmpCollection.splice(i,1);
}
else {
interactionsCollection.push(key);
}
}
});
localforage.setItem('Interactions',interactionsCollection);
});
});
// }
//*******************************//
// Careful deletes all Rose data //
//*******************************//
localforage.clear();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment