UNPKG

react-raven

Version:

A simple React component for Sentry integration.

60 lines (44 loc) 2.12 kB
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } import React from 'react'; import PropTypes from 'prop-types'; import RavenJS from 'raven-js'; import debounce from 'lodash/debounce'; var Raven = function (_React$Component) { _inherits(Raven, _React$Component); function Raven(props) { _classCallCheck(this, Raven); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.install = debounce(_this.install.bind(_this)); return _this; } Raven.prototype.componentDidMount = function componentDidMount() { this.isComponentMounted = true; this.install(); }; Raven.prototype.componentWillUnmount = function componentWillUnmount() { this.isComponentMounted = false; if (RavenJS._isRavenInstalled) { RavenJS.uninstall(); } }; Raven.prototype.install = function install() { if (!this.isComponentMounted || RavenJS._isRavenInstalled) { return; } RavenJS.config(this.props.dsn, this.props.config).install(); }; Raven.prototype.render = function render() { return null; }; return Raven; }(React.Component); export default Raven; Raven.defaultProps = { config: {} }; Raven.propTypes = { dsn: PropTypes.string.isRequired, config: PropTypes.object };