* Schedules invocation of the original function. * * @returns {void}
()
| 779 | * @returns {void} |
| 780 | */ |
| 781 | function proxy() { |
| 782 | var timeStamp = Date.now(); |
| 783 | if (leadingCall) { |
| 784 | // Reject immediately following calls. |
| 785 | if (timeStamp - lastCallTime < trailingTimeout) { |
| 786 | return; |
| 787 | } |
| 788 | // Schedule new call to be in invoked when the pending one is resolved. |
| 789 | // This is important for "transitions" which never actually start |
| 790 | // immediately so there is a chance that we might miss one if change |
| 791 | // happens amids the pending invocation. |
| 792 | trailingCall = true; |
| 793 | } |
| 794 | else { |
| 795 | leadingCall = true; |
| 796 | trailingCall = false; |
| 797 | setTimeout(timeoutCallback, delay); |
| 798 | } |
| 799 | lastCallTime = timeStamp; |
| 800 | } |
| 801 | return proxy; |
| 802 | } |
| 803 |