Last active
March 24, 2016 02:26
-
-
Save dhrrgn/785ad516304b89448167 to your computer and use it in GitHub Desktop.
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
function asyncMultiGet(keys) { | |
return AsyncStorage.multiGet(keys) | |
.then((err, data) => { | |
if (! err) { | |
return data.reduce(function (carry, val) { | |
carry[val[0]] = val[1]; | |
return carry; | |
}, {}); | |
} | |
// TODO Handle errors | |
}); | |
} | |
// Usage | |
asyncMultiGet(['key1', 'key2']) | |
.then((data) => { | |
// {"key1": "value1", "key2": "value2"} | |
console.log(data); | |
}); | |
// This becomes even easier if you use async/await: | |
let data = await asyncMultiGet(['key1', 'key2']); | |
// {"key1": "value1", "key2": "value2"} | |
console.log(data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment