I have a promise chain where I get the content from local DB, update it with the latest fetched from API. This cycle is run whenever user eg opens a content. It works well. Except when the user is opening the app through a deep link. Eg, I go to the company website, I have the deep link option in the safari, I open it. It successfully fetches the content opened from the website, goes into the promise lifecycle where it tries to load and update the content but it just hangs. All input data is correct and it doesn't make sense why it hangs at all.
PouchDB is using adapter pouchdb-adapter-react-native-sqlite with react-native-sqlite-2
createDBIndex()
.then(() => {
console.groupCollapsed('Updating existing content');
console.log(toUpdateArray);
console.log('Fetching articles and indexes');
return Promise.all(toUpdateArray.map(({ _id }) => DB.articles.get(_id)));
})
.then(dbArticles => {
console.log('Resolving finders-keepers');
console.log(dbArticles);
const updatedContent = dbArticles.map(dbItem => {
const toUpdate = toUpdateArray.find(item => item._id === dbItem._id);
return {
...dbItem,
...toUpdate,
expire: moment().add(1, 'd').format()
};
});
return DB.articles.bulkDocs(updatedContent).then(() => updatedContent);
})
.then(updatedDBArray => {
console.log('update result', updatedDBArray);
console.groupEnd();
return updatedDBArray;
})
The last console.log it gives is Fetching articles and indexes and the whole app freeze. tried to print the PouchDB get function result or error but nothing. It doesn't get resolved or rejected.
What I can share is that recently people have problems using PouchDB in a React Native environment which is using AsynchStorage as its backing storage. Take a look at this question and that question and also this issue.
Related
I'm trying to implement the code example in this repo:
https://github.com/autodesk-platform-services/aps-simple-viewer-dotnet
While launching in debugging mode, I get an error in the AuthController.cs says:
Could not list models. See the console for more details
I didn't make any significant changes to the original code, I only changed the env vars (client id, secret etc..)
The error is on the below function:
async function setupModelSelection(viewer, selectedUrn) {
const dropdown = document.getElementById('models');
dropdown.innerHTML = '';
try {
const resp = await fetch('/api/models');
if (!resp.ok) {
throw new Error(await resp.text());
}
const models = await resp.json();
dropdown.innerHTML = models.map(model => `<option value=${model.urn} ${model.urn === selectedUrn ? 'selected' : ''}>${model.name}</option>`).join('\n');
dropdown.onchange = () => onModelSelected(viewer, dropdown.value);
if (dropdown.value) {
onModelSelected(viewer, dropdown.value);
}
} catch (err) {
alert('Could not list models. See the console for more details.');
console.error(err);
}
}
I get an access token so my client id and secret are probably correct, I also added the app to the cloud hub, what could be the problem, why the app can't find the projects in the hub?
I can only repeat what AlexAR said - the given sample is not for accessing files from user hubs like ACC/BIM 360 Docs - for that follow this: https://tutorials.autodesk.io/tutorials/hubs-browser/
To address the specific error. One way I can reproduce that is if I set the APS_BUCKET variable to something simple that has likely been used by someone else already, e.g. "mybucket", and so I'll get an error when trying to access the files in it, since it's not my bucket. Bucket names need to be globally unique. If you don't want to come up with a unique name yourself, then just do not declare the APS_BUCKET environment variable and the sample will generate a bucket name for you based on the client id of your app.
I am trying to make a web app which shows real time subscribercount of a youtube channel.But it just shows me a constant number.The number of subscribers are not updated in next call of API.
I have written this function to get subs.I have tried with ID as well still no updates.Help me out.
Javascript
function getsubscribers(username, element) {
let url = `https://www.googleapis.com/youtube/v3/channels?key=${KEY}&forUsername=${username}& part=statistics`;
fetch(url)
.then((res) => res.json())
.then((data) => {
element.innerText = data.items[0].statistics.subscriberCount;
});
}
YouTube analytics has the same issue.
This is because the YouTube API is not a realtime api, the data seams to be updated once a day.
I am trying to figure out what is causing this issue. When I open the app, I go to the first screen. The screen contains data that is fetching from json data. Then when I switch to another screen and back to the first screen the same data is still there. I'll explain why it should be different. I am fetching data from mysql database using a random query (RAND()) It should be different every time I go back to the first screen.
When I uninstall and reinstall the app, I see the newly fetched data, but the problem still proceeds if I repeat the steps.
This works on Android, but not on iOS:
componentDidUpdate(prevProps, prevState) {
if (!prevState.user_image) {
fetch('https://www.exmaple.com/React/user.php')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
user_image: responseJson
}, function() {
const {userLikes, user_image} = this.state;
this.setState({
combinedArray: userLikes.map(likes => Object.assign(likes, user_image.find(images => images.id == likes.id)))
});
});
})
.catch((error) => {
//console.error(error);
});
}
}
I don't know if Xcode have some kind of fetch data caching. Basically what is happening is (In web development terms) CSS caching, but with fetched data. If that makes sense.
Also I am using a react-native-react-navigation Tab Navigation...maybe that's the problem and it's saving fetched data?
It turns out I was right! It was because the fetch is caching. I had to insert no caching headers in the fetch.
I am working on offline support in my PWA app. I am using workbox for that. This is my current code:
const addToFormPlugin = new workbox.backgroundSync.Plugin('addToForm');
workbox.routing.registerRoute(
RegExp('MY_PATH'),
workbox.strategies.networkOnly({
plugins: [addToFormPlugin]
}),
'POST'
);
The code seems to works fine on my computer. However, once I run the app on the phone it takes ages to upload requests stored in IndexedDB. I know that it happens on the SYNC but it seems to take at least 5 minutes. This is not exactly what I need. I wonder if there is an option to access the IndexDB and send all the requests "manually" on click. Another way would be to check if the device is online. Here is how requests are stored:
If you need to force this, the cleanest approach would be to use the workbox.backgroundSync.Queue class (instead of workbox.backgroundSync.Plugin) directly.
The Plugin class takes care of setting up a fetchDidFail callback for you, so if you use the Queue class, you need to do that yourself:
const queue = new workbox.backgroundSync.Queue('addToForm');
workbox.routing.registerRoute(
RegExp('MY_PATH'),
workbox.strategies.networkOnly({
plugins: [{
fetchDidFail: async ({request}) => {
await queue.addRequest(request);
},
}],
}),
'POST'
);
You could then call queue.replayRequests() to trigger the replay, e.g., as a result of a message event:
self.addEventListener('message', (event) => {
if (event.data === 'replayRequests') {
queue.replayRequests();
}
});
But... that all being said, I think your best bet is just to let the browser "do its thing" and figure out when the right time is to replay the queued requests. That will end up being more battery-friendly for mobile devices.
If you're unhappy with the interval that the browser waits before firing a sync event, then the best course of action could be to open a bug against the browser—whether it's Chrome (as appears in your screenshot) or another browser.
I want to use the new fetch API instead of the old XMLHttpReuest in my extension, but seems like fetch is not available in the extension's context.
I even tried to use the fetch API that is attached to the hidden window, but got an error.
var fetch = Cc['#mozilla.org/appshell/appShellService;1']
.getService(Ci.nsIAppShellService).hiddenDOMWindow
.fetch;
Here is the error message: TypeError: 'fetch' called on an object that does not implement interface Window.
So is there anyway to take advantage of this new API in an extension?
this works for me - assuming the new jpm add-on SDK
const { Cu } = require("chrome");
Cu.importGlobalProperties(["fetch"]);
now you use it just like you would in a web page
fetch('http://cross.origin.works.too/huzzah.html')
.then(response => response.json())
.then( //.... etc