@dynatrace/react-native-plugin
Version:
This plugin gives you the ability to use the Dynatrace Mobile agent in your react native application.
50 lines (49 loc) • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DynatraceClassComponent = void 0;
const react_1 = require("react");
const ConfigurationHandler_1 = require("../../../lib/core/configuration/ConfigurationHandler");
const ConsoleLogger_1 = require("../../../lib/core/logging/ConsoleLogger");
const Dynatrace_1 = require("../../../lib/core/Dynatrace");
const ComponentUtil_1 = require("./ComponentUtil");
class DynatraceClassComponent extends react_1.Component {
constructor(props) {
super(props);
this.wrappingName = (0, ComponentUtil_1.getNameFromComponent)(props);
this.componentMounted = false;
this.logger = new ConsoleLogger_1.ConsoleLogger(`Component ${this.wrappingName}`);
}
render() {
if (!ConfigurationHandler_1.ConfigurationHandler.isConfigurationAvailable()) {
this.logger.info('React Native plugin has not been started yet! Component will not be reported!');
}
else {
if (ConfigurationHandler_1.ConfigurationHandler.isLifecycleUpdateEnabled() ||
!this.componentMounted) {
const actionPrefix = !this.componentMounted
? 'Render '
: 'Update ';
this.internalAction = Dynatrace_1.Dynatrace.enterAutoAction(actionPrefix + this.wrappingName);
}
}
return this.props.children;
}
componentWillUnmount() {
this.componentMounted = false;
}
componentDidUpdate() {
this.reportFunctionEvent('componentDidUpdate()');
}
componentDidMount() {
this.componentMounted = true;
this.reportFunctionEvent('componentDidMount()');
}
reportFunctionEvent(event) {
if (this.internalAction !== undefined) {
this.internalAction.reportEvent(`${this.wrappingName}.${event}`);
this.internalAction.leaveAction();
this.internalAction = undefined;
}
}
}
exports.DynatraceClassComponent = DynatraceClassComponent;