Closed NoNameProvided closed 7 years ago
I'm not familiar with promises in native JS. Is this native JS? If so, please make u pull request and I'l be happy to merge it.
Thanks
Here is an implementation with callbacks:
getCallbackifiedLocalStorage() {
return {
setItem: function setItem(key, value, success, error) {
try {
window.localStorage.setItem(key, this.encodePayload(value));
succes();
} catch (error) {
error(error);
}
},
getItem: function getItem(key, success, error) {
try {
var result = window.localStorage.getItem(key);
success(this.decodePayload(result));
} catch (error) {
error(error);
}
},
remove: function remove(key, success, error) {
try {
window.localStorage.removeItem(key);
success();
} catch (error) {
error(error);
}
},
clear: function clear(success, error) {
try {
window.localStorage.clear();
success();
} catch (error) {
error(error);
}
},
encodePayload: function encodePayload(payload) {
try {
payload = JSON.stringify(payload);
} catch(error) { }
return payload.toString();
},
decodePayload: function decodePayload(payload) {
try {
payload = JSON.parse(payload);
} catch(error) { }
return payload;
}
}
If so, please make a pull request and I'l be happy to merge it.
Okay, I will test it and make one
Hmm, just did a quick look on the source code and it seems it already has local storage as a fallback. So I guess the Ionic Native wrapper messes up something, I will give it a proper look later (probably on the weekend)
@NoNameProvided @GillesC Sorry, for the late reply.
What I had done was there is a delegate that falls back to localstorage
based on the storageSupportAnalyse
function's response to StorageHandle
at line 27.
If even localstorage isn't available we fail gracefully with a console.log (my comment :) at the code). No detailed error message with trace that's all.
Let us reopen, if there is something we can work on here though. I'm closing for now. Thanks!
Now if cordova is not available the plugin throws the
plugin_not_installed
error.Since this plugin has a small API, it would be easy to add a proper web fallback for browsers:
Note: This implementation is Promise based as I use Ionic-Native, but its pretty straight forward to make rewrite it into callbacks.