Closed Hasan-git closed 5 years ago
This is probably because window.localStorage is synchronous and the link expects an asynchronous API.
Try using a wrapper like this:
const asyncLocalStorage = {
setItem: function (key, value) {
return Promise.resolve().then(function () {
localStorage.setItem(key, value);
});
},
getItem: function (key) {
return Promise.resolve().then(function () {
return localStorage.getItem(key);
});
}
};
Then use the wrapper as follows:
const offlineLink = new OfflineLink({
storage: asyncLocalStorage
});
Have not tested this myself, we've also not used this link on a browser. We're using it with react-native. Let us know how it works out for you!
Thank you @miguelocarvajal ! I found a workaround , I'm using localforage instead and working as well
npm i localforage
in module
import * as localforage from "localforage";
...
const offlineLink = new OfflineLink({
storage: localforage
});
setting storage to window.localStorage leads to error, note that I'm using angular 7
and getting this error :
this.storage.getItem(...).then is not a function