در حال بارگذاری ...

Debouncing vs Throttling0:00

Now that you're a bit more comfortable with forms, let's move on and discuss debouncing and throttling. So you'll remember a few episodes ago we set up real-time search, which is great. But yeah, have a look at this. If I go to my network tab and we run this search again, notice we're making 10 requests for a single word. Way too much. It's just not necessary. So here's how we might fix that. I'm in my UsersComponent, and if I scroll down, yeah, right now we are watching that

Throttle Search Requests0:26

So here's how we might fix that. I'm in my users component, and if I scroll down, yeah, right now we are watching that search input, and when it changes, we immediately make a request. So it sounds like we should say, well, make a request, but don't do it too many times. And we can use Lodash for this. Now I believe out of the box in Laravel, yeah, Lodash is included as a dependency, but otherwise you can install it like this. Okay, so to use it, let's start with, how about throttle. Import throttle from Lodash, and if we want to grab one specific function, we can access it as a file, like this.

Using Lodash Utilities4:32

you'll just about always reach for one of these functions.

ThrottleDebounceNetwork Requests

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟