1

While looking into LWC found below line of code.

window.clearTimeout(this.delayTimeout);

And found the below comments.

// Debouncing this method: Do not update the reactive property as long as this function is being called within a delay of DELAY. This is to avoid a very large number of Apex method calls.

  1. Is this mean that LWC will call the apex class multiple times?
  2. Will this cause performance issue?
  3. If 1st my point is right what LWC call the apex class multiple times?
0

It would have been important to add the context to your question

This examples binds an apex method to the change event of a lightning-input which is fired on every single character change which would call the apex method as many times as the user entered or removed something (so e. g. "example" would call it 7 times). Throtteling / Debouncing is a common technique to prevent events / their respective handlers to be fired a high amount in short time. While you most likely would not notice any major performance issues in this example (more important for events like scrolling, mouse events which are fired hundred of times per s) it just make more sense to have slight delay to get more accurate / recent results and less unnecessary rerenders of your component

0

Answer to your questions is as following:-

Q1. Is this mean that LWC will call the apex class multiple times? - Maybe, this depends upon your implementation. If you provide a functionality wherein there is scope for calling a method repeatedly.

Q2. Will this cause performance issue? - No, this is to ensure that time consuming method is not called repeatedly.

Q3. If 1st my point is right what LWC call the apex class multiple times? - Answer for this is same as first one, it depends upon your implementation.

Debouncing in JavaScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.