(React)
| 58 | |
| 59 | // takes in react component, triggers all other logic, is exported out |
| 60 | var whyDidYouUpdate = function whyDidYouUpdate(React) { |
| 61 | |
| 62 | // event listener for load page |
| 63 | window.addEventListener('load', () => { |
| 64 | // calculation for total time taken to render the webpage |
| 65 | const startLoadTime = window.performance.timing.loadEventStart |
| 66 | const endLoadTime = window.performance.timing.domLoading |
| 67 | const deltaTime = startLoadTime - endLoadTime; |
| 68 | |
| 69 | window.data.time = deltaTime + 'ms'; |
| 70 | }); |
| 71 | |
| 72 | /** |
| 73 | * function handler for click, dbclick, and drag |
| 74 | */ |
| 75 | function handleMouseEvents(e) { |
| 76 | let localName = e.target.localName; |
| 77 | let innerText = ''; |
| 78 | |
| 79 | // description string for click elements |
| 80 | function setInnerText(type, targetInfo) { |
| 81 | innerText = type +': ' + targetInfo; |
| 82 | } |
| 83 | // if clicked element is '<button>', check innerText, then id, then className for descriptor |
| 84 | if (localName === 'button') { |
| 85 | if (e.target.innerText) { |
| 86 | setInnerText('text', e.target.innerText); |
| 87 | } else if (e.target.id) { |
| 88 | setInnerText('id', e.target.target.id); |
| 89 | } else if (e.target.className){ |
| 90 | setInnerText('className', e.target.className); |
| 91 | } |
| 92 | } |
| 93 | // if clicked element is '<img>', check alt text, then className for descriptor |
| 94 | else if (localName === 'img') { |
| 95 | if (e.target.alt) { |
| 96 | setInnerText('alt', e.target.alt); |
| 97 | } else if (e.target.className) { |
| 98 | setInnerText('className', e.target.className); |
| 99 | } |
| 100 | } |
| 101 | // if clicked element is '<div>', check id, then className for descriptor |
| 102 | else if (localName === 'div') { |
| 103 | if (e.target.id) { |
| 104 | setInnerText('id', e.target.id); |
| 105 | } else if (e.target.className){ |
| 106 | setInnerText('className', e.target.className); |
| 107 | } |
| 108 | } |
| 109 | else { |
| 110 | innerText = 'unknown'; |
| 111 | } |
| 112 | let currentEventName = localName +' ('+innerText+')'; |
| 113 | |
| 114 | let obj = { |
| 115 | type: e.type, |
| 116 | name: currentEventName, |
| 117 | components: [] |
nothing calls this directly
no test coverage detected