Data fetching without SWR - axios

When it comes to fetching data i usually use SWR because it's easy-to-use package, but this time i wanted to fetch data using getServerSideProps or getStaticProps, And of course i tried to use SWR inside them. 😎😂
But as you know, you can't use it inside those functions because it depends on useContext hook, if my memory serves me correctly.
Whatever the case, I used Axios - some cases the native fetch function - but now I've got no clue how to handle the loading status of the fetched data or what to do if something went wrong while fetching.
could anyone tell me, how to get these functions using wethier axios() or fetch()?
THANK YOU SO MUCH ❤

Related

Validating data using FirestoreDataConverter

Is it possible to do some kind of data validation when using FirestoreDataConverter<T>?
Looking at the call signature for fromFirestore, it seems like you can only return T. But what if I look at the data and realize that there is invalid data in the database? (I know, I should guard against that in the first place, but bad things happen.)
And it is even more important to guard against errors when using toFirestore. Again, is there a recommended way to do data validation before writing to the database?
I ask because looking at the VueFire documentation , they seem to return null on invalid data. Is that simply an error on their part?
I can see two options. Include some kind of error-state type in the signature (FirestoreDataConverter<T|E>) or throw an error. Is one or the other the 'recommended practice'?
I wish the official docs had more information on how to use FirestoreDataConverter.

What all do we need to change while upgrading from Bing Maps v7 to v8?

I have changed the URL as per the guideline document given. But that's not enough I guess. I am getting some errors related to very widely used constructors such as Microsoft.maps.point.
Uncaught TypeError: Microsoft.Maps.moduleLoaded is not a function
at PointBasedClustering.js:455
scripts.js:1411 Uncaught TypeError: Microsoft.Maps.Point is not a constructor
at scripts.js:1411
at scripts.js:2179
I haven't changed any sequence of files. Only on replacing this particular URL results in all these errors. I searched a round a lot but due to very less community support I was unable to find any discussion about this.
It looks like your code is trying to access the namespace before it is available. Ensure that you only use the Microsoft namespace inside of your map load function. I also recommend calling your map load function by adding the callback parameter t the map script URL and specifying your callback function name there. The V8 control loads asynchronously which allows your page to load faster, but this also means that it is much easier for your code to try and access the Microsoft.Maps namespace before it is available.
Also ensure that you are not just changing the version number in the map script URL as that won't work. V8 uses a completely different URL. Take a look at some of the samples: http://bingmapsv8samples.azurewebsites.net/

tastypie hydrate() not getting called

I am new to tastypie. I have a tastypie model resource where I want to use hydrate() to take serialized data from the client and turn it into a proper format that the data model can use. I have tried hydrate() hydrate_foo() but it seems all the hydrate() functions are not getting called, while dehydrate() will always get called. In my resource model, there're also obj_get(), obj_update(). Are there restrictions/constraints as to how the hydrate() function should be defined in the resource model so that I could use it to manipulate data submitted by the client?
I know this post is pretty old but, since documentation and examples on Tastypie are very limited, I'm adding my small experience here.
Without code it is hard to give a proper answer but I've seen that hydrate methods are only called if we explicitly call in the obj_create function the full_hydrate method as follows:
bundle = self.full_hydrate(bundle)
I thought they were automatically called by Tastypie but it seems not the case.

Issue with duplicate search results and XMLParser array refresh

I use an NSXMLParser to parse ext. API data. I also use a Singleton shared array var to maintain info retrieved from ext API.
This info is dynamic and changesas the user types anything in UISearchBar
Now the thing is as soon as the user types anything, I clear off the existing array contents by using [retrievedArray removeAllObjects];
Thus this refreshed retrievedArray based on the current terms in the search bar.
This works fine if the user types slowly. However I get to see duplicate search results if the user types very fast. This, I am assuming, is because the retrievedArray contents do not get enough time to clear off.
I am still trying to resolve the issue. Please suggest some more fixes.
Could you please provide me the fix.
No, I don't think this is the case, unless you're doing search in a separate thread and clear array in another one. If not, then there is probably error in your search logic.
First of all I think a singleton approach may not be the best way to go for what you are doing. But make sure that you are synchronizing all mutable access to the array. Instead of allowing the singleton to return a NSMutableArray for any object and their mom (super) to use you need to have methods like addObject,removeObject,clear with #synchronize blocks or any kind of lock you decide on. I still see issues with this approach because the code calling addObject, remove and clear will all need to be synchronized as well. Maybe consider on each auto complete request you use a delegate or post a NSNotification containing a timestamp, the characters the user typed to get data, and a NSArray of results. At that time you can see if the response is still valid, discard any invalid responses, and update the user with just the contents of the most recent valid NSArray

How to use Zend Cache with SimpleXML objects?

I'm trying to cache the user timeline of a Twitter feed using Zend_Service_Twitter which returns its results as a SimpleXML object. Unfortunately the regular serialize functions (which Zend Cache uses) don't play nice with SimpleXMl objects. I found this http://www.mail-archive.com/fw-general#lists.zend.com/msg18133.html.
So it looks like I'll need to create some kind of custom frontend for Zend Cache to be able to change the serialize function used. Anybody ever done this already or can point me where to look to start?
Instead of trying to cache the SimpleXML object, I chose to loop through Twitter posts returned and save that data as a string. I then save that string to the cache. Works for me!
Or you can call asXML() function:
$simpleXml = #simplexml_load_file($xml_url);
$cache->save($simpleXml->asXML(), 'name_of_cache');
Definition and Usage
The asXML() function returns the XML document, from a SimpleXMLElement
object, as a string.
This function returns FALSE on failure.