raf-throttle icon indicating copy to clipboard operation
raf-throttle copied to clipboard

proper testcase for preserving 1st context fails

Open me-andre opened this issue 5 years ago • 1 comments

If we make "preserves the context of the first call" testcase just slightly more complex, we clearly see it doesn't actually preserve the context of the 1st call as promised. What it does is preserving the context of the 1st call after the last animation frame. When animation frames happen and how often is the last thing a developer wants to care about, so current behavior is close to unpredictable and thus unreliable. I personally see 2 solutions to this problem:

  1. Make no assumptions regarding context (like lodash.throttle). This is the smartest choice.
  2. Treat context as an argument and invoke the callback with the most recent context (if we want those dances around context).

me-andre avatar Mar 31 '19 09:03 me-andre

Thanks for opening this PR. Do you mind to implement the second behavior you mentioned in this PR as well?

wuct avatar Mar 31 '19 15:03 wuct