Created
July 14, 2017 19:55
-
-
Save 1fabiopereira/cba8e8ac3b3acb81d3f719b22530c630 to your computer and use it in GitHub Desktop.
Simple Asyncstorage wrapper react-native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {AsyncStorage} from "react-native"; | |
class Storage { | |
constructor (name) { | |
this.name = `@${name.toUpperCase()}`; | |
} | |
add (key, value) { | |
if (typeof value !== "object") { | |
throw new Error(`Value is not a object: ${String(valeu)}`); | |
} | |
return AsyncStorage.getItem(`${this.name}:${key}`, JSON.stringify(value)); | |
} | |
multiAdd () { | |
return null; | |
} | |
get (key) { | |
return AsyncStorage.getItem(`@${this.name}:${key}`); | |
} | |
multiGet () { | |
return null; | |
} | |
getKeys () { | |
return null; | |
} | |
getAllKeys () { | |
return null; | |
} | |
remove (key) { | |
return AsyncStorage.remove(`${this.name}:${key}`); | |
} | |
multiRemove () { | |
return null; | |
} | |
merge (key, value) { | |
if (typeof value !== "object") { | |
throw new Error(`Value is not a object: ${String(valeu)}`); | |
} | |
return AsyncStorage.mergeItem( | |
`@${this.name}:${key}`, | |
JSON.stringify(value) | |
); | |
} | |
multiMerge () { | |
return null; | |
} | |
drop () { | |
return null; | |
} | |
dropAll () { | |
return null; | |
} | |
} | |
export default Storage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment