react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / test / ReactPerf.js
81152 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @providesModule ReactPerf9* @typechecks static-only10*/1112"use strict";1314/**15* ReactPerf is a general AOP system designed to measure performance. This16* module only has the hooks: see ReactDefaultPerf for the analysis tool.17*/18var ReactPerf = {19/**20* Boolean to enable/disable measurement. Set to false by default to prevent21* accidental logging and perf loss.22*/23enableMeasure: false,2425/**26* Holds onto the measure function in use. By default, don't measure27* anything, but we'll override this if we inject a measure function.28*/29storedMeasure: _noMeasure,3031/**32* Use this to wrap methods you want to measure. Zero overhead in production.33*34* @param {string} objName35* @param {string} fnName36* @param {function} func37* @return {function}38*/39measure: function(objName, fnName, func) {40if (__DEV__) {41var measuredFunc = null;42var wrapper = function() {43if (ReactPerf.enableMeasure) {44if (!measuredFunc) {45measuredFunc = ReactPerf.storedMeasure(objName, fnName, func);46}47return measuredFunc.apply(this, arguments);48}49return func.apply(this, arguments);50};51wrapper.displayName = objName + '_' + fnName;52return wrapper;53}54return func;55},5657injection: {58/**59* @param {function} measure60*/61injectMeasure: function(measure) {62ReactPerf.storedMeasure = measure;63}64}65};6667/**68* Simply passes through the measured function, without measuring it.69*70* @param {string} objName71* @param {string} fnName72* @param {function} func73* @return {function}74*/75function _noMeasure(objName, fnName, func) {76return func;77}7879module.exports = ReactPerf;808182