mobile fetch data from other sources

mobile fetch data from other sources

  

How to protect this request triggering when offline? Now when offline it displays "Request failed with an error"

Hi,

You could make use of the Private\NetworkStatusChanged under MobilePatterns to detect whether the user is offline. Here's a discussion about the usage.


Yes i know that plugin but where to put it because the action triggers automatically

You probably cannot call that from a Data Fetch Action, as those are automatically triggered and are always server-side.

You'd want to call it only if you are online... but what would be the behaviour when you are not online?

The behaviour being offline is exactly what i describe, i get an error saying "request with an error", i think you should protect that.

If the user is offline the action shouldn't do anything.

Ok, so if it's offline that action should return an empty list? because if you are calling it it is because you are using its output somewhere on the screen right?

I'd say you can implement an OnRender handler that checks if you are online, and if so calls the server action and stores the outcome in a local property that is used on screen.

The disadvantage of this approach is that the request is only triggered after the page has been displayed, but at the same time, it is going to be synchronous so you don't really want to wait for its outcome before rendering the screen (if this is not a concern, you can always have it on the OnReady handler).

Or maybe you can call some javascript that calls the server action asynchronously, but I haven't really tried that before, not sure how simple/easy/possible that is.

yes i can fix the issue by calling onrender or other event but the question here is , should or not the fetch from other sources be protected to not do the request when the app is offline

Because if the app is to be used offline the developer cannot use this function anytime

Filipe Lourenço wrote:

Yes i know that plugin but where to put it because the action triggers automatically

You should be able to store the result of that plugin to local storage. I don't think you will be needing anything from the DOM so you can do it OnInitialize. 


In this case i am retrieving a site property from the server so in the on inithialize will do the app run slower. I prefer to use the on ready