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