Created
February 24, 2016 21:58
ReactPerf to Web Tracing Framework
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 ReactPerf = require('ReactPerf'); | |
const TRACE_DOM = false; | |
function reactPerfTrace(objName: string, fnName: string, func: any): any { | |
return function(component) { | |
let label; | |
if (objName === 'ReactCompositeComponent') { | |
var instName = this.getName() || 'Unknown'; | |
label = fnName === 'mountComponent' || fnName === 'updateComponent' ? instName : `${instName}.${fnName}`; | |
} else if (TRACE_DOM) { | |
label = `${objName}.${fnName}`; | |
} else { | |
return func.apply(this, arguments); | |
} | |
let trace = window && window.wtf && window.wtf.trace; | |
let scope = trace && trace.enterScope(label.replace(/[^a-z0-9\.\_]/gi, '__')); | |
let ret = func.apply(this, arguments); | |
scope && trace.leaveScope(scope); | |
return ret; | |
}; | |
} | |
ReactPerf.injection.injectMeasure(reactPerfTrace); | |
ReactPerf.enableMeasure = true; |
Author
joshduck
commented
Feb 24, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment