question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

recalculate debounce leading vs trailing

See original GitHub issue

I’m using simplebar with AngularJS. I need to call recalculate after a certain angular scope event (after which I’m fairly certain the scroll content is ready and in the DOM). The issue is that recalculate is debounced with { leading: true, trailing: false }, so when I call it the call is simply discarded (as various other things trigger recalculate).I even tried timing out for more than the debounce timeout (currently 100ms) and for some reason this is not working as intended.

I found myself having to manually invoke the original recalculate like so:

simplebarInstance.__proto__.recalculate.apply(simplebarInstance);

to force a recalculate at the exact point at which I know it should work.

I’m not sure about the rationale behind choosing that recalculate fire only on the leading edge. Can it be configured with { leading: true, trailing: true } instead?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Grsmtocommented, Feb 4, 2018

Hi @mnzaki , I guess it’s hard to replicate this issue in an isolated scope as it’s quite specific to your use case. I don’t think calling recalculate on trailing debounce could be an issue so I could probably get that in! Thanks for this report, I’m glad you found a workaround for your problem. I’ll see if I can implement this.

0reactions
neocommented, Mar 16, 2018

it would be very much appreciated if you could publish a patch release soon 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Debouncing and Throttling Explained Through Examples
The Debounce technique allow us to “group” multiple sequential calls in a single one. Imagine you are in an elevator. The doors begin...
Read more >
Throttle & Debounce behavior (lodash) | by Elena Sharovar
Debounce with {leading: true, trailing: false} will result in these values being processed. So, as you see, using different settings you can get...
Read more >
Leading=true in debounce not performing as expected
Therefore you might need to use { leading: true, trailing: false } to get what you want, because trailing is true by default....
Read more >
Throttle and debounce visualized
Similarly to debounce , Lodash implementation of throttle supports a leading and a trailing parameters, allowing to set whether we want to ...
Read more >
Add leading and trailing parameters to debounce and throttle
It is sometimes helpful to specify whether a debounced stream should invoke on the leading or trailing edge of the timeout.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found