Skip to content

Instantly share code, notes, and snippets.

@joshduck
Created February 24, 2016 21:58
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshduck/0c35f70cdd3abf88770c to your computer and use it in GitHub Desktop.
Save joshduck/0c35f70cdd3abf88770c to your computer and use it in GitHub Desktop.
ReactPerf to Web Tracing Framework
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;
@joshduck
Copy link
Author

WTF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment