raf-throttle
raf-throttle copied to clipboard
proper testcase for preserving 1st context fails
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:
- Make no assumptions regarding context (like
lodash.throttle
). This is the smartest choice. - Treat context as an argument and invoke the callback with the most recent context (if we want those dances around context).
Thanks for opening this PR. Do you mind to implement the second behavior you mentioned in this PR as well?