choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
128 lines (108 loc) • 3.58 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import { PureComponent } from 'react';
import TableContext from './TableContext';
import { DataSetStatus } from '../data-set/enum';
var Profiler =
/*#__PURE__*/
function (_PureComponent) {
_inherits(Profiler, _PureComponent);
var _super = _createSuper(Profiler);
function Profiler(props, context) {
var _this;
_classCallCheck(this, Profiler);
_this = _super.call(this, props, context);
var tableStore = context.tableStore,
dataSet = context.dataSet;
if (tableStore.performanceEnabled) {
if (dataSet.status === DataSetStatus.ready && dataSet.length) {
tableStore.performanceOn = true;
tableStore.timing.renderStart = Date.now();
}
}
return _this;
}
_createClass(Profiler, [{
key: "componentWillUpdate",
value: function componentWillUpdate() {
var tableStore = this.context.tableStore;
if (tableStore.performanceEnabled && tableStore.performanceOn) {
tableStore.timing.renderStart = Date.now();
}
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
this.handlePerformance();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate() {
this.handlePerformance();
}
}, {
key: "handlePerformance",
value: function handlePerformance() {
var _this$context = this.context,
code = _this$context.code,
tableStore = _this$context.tableStore,
dataSet = _this$context.dataSet;
if (tableStore.performanceEnabled && tableStore.performanceOn) {
var timing = tableStore.timing;
var performance = dataSet.performance;
var onPerformance = tableStore.getConfig('onPerformance');
timing.renderEnd = Date.now();
onPerformance('Table', {
name: code,
url: performance.url,
size: dataSet.length,
timing: _objectSpread({}, performance.timing, {}, timing)
});
tableStore.performanceOn = false;
}
}
}, {
key: "render",
value: function render() {
var children = this.props.children;
return children;
}
}], [{
key: "contextType",
get: function get() {
return TableContext;
}
}]);
return Profiler;
}(PureComponent);
export { Profiler as default };
Profiler.displayName = 'Profiler';
//# sourceMappingURL=Profiler.js.map