Skip to content

Instantly share code, notes, and snippets.

@ayberkanilatsiz
Last active August 3, 2017 13:52
Show Gist options
  • Save ayberkanilatsiz/a1d48be4264c4746961664d83b2d96cb to your computer and use it in GitHub Desktop.
Save ayberkanilatsiz/a1d48be4264c4746961664d83b2d96cb to your computer and use it in GitHub Desktop.
setItemWithKey(key,obj){
return new Promise((resolve,reject)=>{
// count object example
// obj = {
// action : 1 || 0,
// time,
// }
this.getItems().then((data)=>{
if(obj.action === 1){
data[key].count++;
}else{
data[key].count--;
}
data[key].counts.push(obj);
AsyncStorage.setItem('count', JSON.stringify(data), (err,result) => {
if(err){
reject({err:'something went wrong!'});
}else{
resolve(true);
}
});
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment