| 33 | } |
| 34 | |
| 35 | function debounceAsync(fn) { |
| 36 | 'use strict'; |
| 37 | var waiting = false; |
| 38 | var last = null; |
| 39 | |
| 40 | return function debouceRunner() { |
| 41 | var args = [].slice.call(arguments, 0); |
| 42 | // console.time('tracker'); |
| 43 | |
| 44 | var tracker = function () { |
| 45 | waiting = false; |
| 46 | // console.timeEnd('tracker'); |
| 47 | if (last) { |
| 48 | // console.log('applying the last'); |
| 49 | fn.apply(last.context, last.args); |
| 50 | // console.log('and now clear'); |
| 51 | last = null; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | // put the tracker in place of the callback |
| 56 | args.push(tracker); |
| 57 | |
| 58 | if (!waiting) { |
| 59 | // console.log('running this time...'); |
| 60 | waiting = true; |
| 61 | return fn.apply(this, args); |
| 62 | } else { |
| 63 | // console.log('going to wait...'); |
| 64 | last = { args: args, context: this }; |
| 65 | } |
| 66 | }; |
| 67 | } |
| 68 | |
| 69 | function escapeHTML(html){ |
| 70 | return String(html) |