Created
March 26, 2019 14:49
-
-
Save nickydonna/c044b1170d5f5d52775e7b32523a7628 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const hasMark = window.performance && !!window.performance.mark; | |
| const Performance = () => { | |
| const defaultMark = {}; | |
| const getTiming = () => { | |
| const timing = performance && performance.timing ? performance.timing.toJSON() : {}; | |
| const defaultTiming = {ipsyPageStart: __PAGE_START__, ipsyPageEnd: __PAGE_END__}; | |
| return {...timing, ...defaultTiming}; | |
| }; | |
| const getNavigationTiming = (): NavigationTimingType | void => { | |
| return new Promise(resolve => { | |
| document.readyState === 'complete' | |
| ? resolve(getTiming()) | |
| : window.addEventListener('load', () => resolve(getTiming())); | |
| }); | |
| }; | |
| const basePerf = { | |
| getNavigationTiming, | |
| START_CHANGE_PAGE, | |
| } | |
| if (!hasMark) { | |
| return { | |
| getMarkFullRenderPage: () => ({fullRender: defaultMark}), | |
| getMarkPartialRenderPage: () => ({partialRender: defaultMark}), | |
| ...basePerf, | |
| } | |
| } | |
| // More Code | |
| const getPartialRender = () => { /* ... */} | |
| const getMarkPartialRenderPage = () => { /* ... */} | |
| return { | |
| getPartialRender, | |
| getMarkPartialRenderPage, | |
| ...basePerf, | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment