Now, our application works really well for what I would want is to make sure that all the data comes
back at the same time, because if you pay a close attention to our application, you'll notice that
once we search for a new user, well, first we'll get the user data.
Then we get three posts and only then we get the followers.
On this video, I'll showcase Cortland, who is the founder of the Indie Hackers.
The best podcast probably out there.
Well, the indie hackers and the syntax probably go hand-in-hand as far as the best podcasts out there.
And if you have never listened to any hackers, it's about how to make business online without venture
capital and all that.
How should you bootstrap your business yourself?
Awesome.
Awesome podcast.
Then we have Marcy, who is working at Gadsby, who's doing an amazing job at Gadsby and is all things
accessibility.
And then of course, we also have Kyle, who is the founder of the awesome static site generator.
Or we can already probably say the framework by the name of Gadsby.
And if we notice that E files search for causing fall, you'll see that first.
I'm gonna get the user info, then I'm going to get my repost.
See that change?
And only then I have the followers.
And technically you can say, well, what's the big deal?
But wouldn't it be nicer if we would change all of them at the same time?
Now, again, this is technically optional.
If you're happy with the way the app works right now, you don't have to do that.
You don't have to change your code or on how or I will refactor it and we'll use Promis all settled
on one last thing that I would want to mention before we start typing away.
That, of course.
If you're looking at repos, technically, we could have got the repos from the user.
So instead of looking for the logging and then constructing my repos, you are where I said the route
you are old and users logging and then the reports per page.
I could have just went with my posts.
You are all that is in the user data that I'm getting back.
And then only attach this per page.
Haha, I just wanted to showcase that.
Of course there's multiple ways how we can construct that repo.
That was my preference.
As always.
You want to change this around, you just want to get that property.
The Repos, your órale and then attach the per page like we're doing with followers.
You can definitely do that on my case.
I'm going to delete these two suckers.
And now let's find out a way how we could wait for everything to come back.
And only then, once I have all the data, then I'm gonna set loading to false.
All right.
He was crawling away.
And then, of course, once I do that, then I'll display all the data at once again.
It is optional.
If you don't want to do that, you don't have to.
But in my case, I will.
And you could simply say, alright, we could just attach a weight.
Correct.
I could say a weight or here than a weight or here.
And yet technically it is correct.
But don't you think that the problem is going to be that now is gonna take way longer?
Because now we'll have to wait for a repost to come back and only then we're fetching the powers.
So I would still want to set my requests or I should probably say send my requests at the same time,
meaning I don't want to hold off sending a request while I'm still waiting for response.
However, I would want to wait when both of them come back.
So what we can do that?
Well, we have a promise all settled and we can just attach a weight in front of it.
How is that going to look like?
Well, we could go with a weight and then promise and then all settled.
So this is just gonna fire when all of them settled.
So all the promises that we pass in here when they're settled.
Yes.
Danimal fired this one.
And the way we parse the men is by setting up the array.
And then either we could assign it to some kind of variable.
That's definitely option.
Or you can pass them directly.
She's gonna be my coach.
So what I want you to take is everything, starting with an axe years up until the closing parenthesis.
So don't grab them.
Not technically you can, but we'll avoid that.
So remove this.
Pass it in.
So that's our first one.
And then the second one.
The same way where tech actually goes all the way to the dot remove and line after the comma added in
here.
And now, of course, we can remove the repos and the followers.
Sol, delete that one and then the wady promise.
All set.
All the works is we have dot then.
So now this one we change to all settled.
And this one is going to run only when both of them are settled in here.
Of course, we would want to set up some kind of functionality.
And I'll just simply start with results more here than I'm gonna console log.
My results.
So I'm gonna go with log and and we'll just take a look at these results.
Let's say that.
So now that should be our functionality.
I'm going to navigate back.
We're going to look for martially, this one.
Let's copy and paste a copy paste search.
And now notice non loading, loading, loading.
And only then once I get the data, then I fire this one.
OK.
Now, of course, I didn't change the followers in repose.
Those are still mine because, of course, we removed that functionality.
But you noticed how we were waiting for it.
And only then once we got the data, then we changed this around.
So let's do inspect and you'll see in the console the photos, the results, the ones that I'm constant
logging in that then I have the array.
So what is in the array?
Well, in the array, each of them is represented as a value, meaning as a object.
And then in there we have the status, which just says that the promise has been fulfilled, meaning
everything is correct.
And then we have, of course, the value for the data that we're getting back.
So in here.
Notice we have value object.
And then in there we have the data during that data.
Of course, this is where we're getting the repos and this is where we're getting the followers.
Now, let's also test that out right away.
What happens if.
For example, I don't know, for some weird reason, we have the wrong you are all.
What if we're not getting the data and the way I can turn us around?
I don't know.
I'm going to say reposes this is this.
So I'm going to add a bunch of rebozo here.
And now let's look for Courtland.
So we're going to take his GED, Abuzer.
We're just going to copy and paste.
So it's copy paste.
And now, of course, notice I'm still getting back.
Meyera.
Yeah, I waited for them to be settled, but now the first one is rejected.
OK.
So where they can put two and two together where I would want to check.
If everything is correct, if the promise has been fulfilled and then if that is the case, then I'm
only going to get the value that I'm going to get this array or whatever date I have in there.
And I already know that the first one that I passed in is the Repos.
Correct.
So the first one will represent the Repos and the second one will represent the followers.
And remember when we were working with you state when we used array the structuring, since of course
this is what's happening with results.
We're getting back the array of two items.
Well, we can just the structure is correct so we can go with concert and then repos.
That's the first one.
Paul, a word.
Now, of course, I'm going to fix this.
I'm going to say, yep.
Get me three powers that is coming from results.
And now simply say following thing where I'm gonna get the status.
So I'll have some kind of variable that is equal to fulfilled, fulfilled like show.
And if that is the case, if the repo status and the follower status are fulfilled, then of course
I would want to set the repos and followers.
Now, just to emphasize that if you look at the results, what you're getting back, you'll see.
Now, of course, at the moment you don't see anything.
But if we go back to his boss, we will see that we're getting Bagheera.
And then in that array, of course, we're going to have the status.
So in those objects, in that array to array that I'm getting back in those objects, I am having a
status property.
So I'm going to be looking for that status property.
So I'm getting back the array.
I have two items in that, Ray.
I'm going to grab the first one.
That is my repos, because that's the promise that I placed first.
And then I had followers and I just want to check with their property is fulfilled.
If that is the case.
Yeah, get me the value.
Now, where was the value?
It was in value property and then data.
So let's head back and.
Will remove the console log.
We don't need that one anymore, and we'll simply say if repos status is equal to a status variable
that I have.
So, Zengel, I'm just saying the strings.
So there is no typo or anything like that.
We're gonna go with set Rebholz.
I'm looking for reposed value and then data.
Now I need to do the same thing for my followers.
So let me copy and paste in here.
We're gonna change primary.
So let we select both of them.
And we're gonna just change them around to a followers.
And once I change the followers, of course, out, I also want to change what I'm setting up.
So instead of set repos, I'm going with set followers.
So now let's save it and we're going to navigate back to our application.
And let's try Marché one more time.
So we're gonna grab her GitHub username, copy and paste.
We will search.
And then, of course.
Now, what you can say is that we're only displaying the data when we get everything back.
So that's really cool.
Again, you don't technically have to do that, but in my opinion, it's a little bit better where we
only update once we have all the data instead of showing the user info first than showing the repos
and only then once the followers come back.
Then, of course, we display to followers again.
Just to recap the way we did that, we used Promis all settled.
Then we passed in two Axios requests.
And of course, like I just mentioned.
If you want, you can change this around to as you are also just the structured of response data and
just add that per page because it's just going to make it a little bit more interesting where you have
more repos and that all settled is just going to return one dot then.
So we have one dot then when we get all the promises back.
So once they have been settled.
So once the promises have been settled, then of course we decide to do something with them.
Now, while, like all settled the curs, essentially it doesn't throw the error e there's something
wrong with one of them.
So essentially there are other options out there as far as promises.
But what I really like about all settled option is the fact that even though one of them could have
the error like we had with a repost, it still waits for all of them to be settled and only then we
can decide what we're doing.
If, for example, it's all failed.
Awesome.
We're doing something.
If it's not, then of course we're doing something else.
So now, of course, we have our out functionality in place so we can start focusing on the authentication.
But before we move on to our next video, of course, we can change up, catch and just console out
there, because again, we have that then.
So that also means that we have Dakich.
So we're going to hold console log and then we're looking for the console.
Log it.
Now everything is set up for us to start working on the authentication.