@rollbar/react
Version:
Effortlessly track and debug errors in your React applications with Rollbar. This package includes advanced error tracking features and a set of React-specific enhancements to help you identify and fix issues more quickly.
98 lines (93 loc) • 3.95 kB
JavaScript
"use client";
;
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var PropTypes = require('prop-types');
var Rollbar = require('rollbar');
var tinyInvariant = require('./external/tiny-invariant/dist/esm/tiny-invariant.js');
var utils = require('./utils.js');
var Context = /*#__PURE__*/React.createContext();
Context.displayName = 'Rollbar';
var RollbarInstance = Symbol('RollbarInstance');
var BaseOptions = Symbol('BaseOptions');
var RollbarCtor = Symbol('RollbarCtor');
function getRollbarFromContext(context) {
var rollbar = context[RollbarInstance];
return rollbar;
}
function getRollbarConstructorFromContext(context) {
var ctor = context[RollbarCtor];
return ctor;
}
var Provider = /*#__PURE__*/function (_Component) {
_rollupPluginBabelHelpers.inherits(Provider, _Component);
function Provider(props) {
var _this;
_rollupPluginBabelHelpers.classCallCheck(this, Provider);
_this = _rollupPluginBabelHelpers.callSuper(this, Provider, [props]);
var _this$props = _this.props,
config = _this$props.config,
_this$props$Rollbar = _this$props.Rollbar,
ctor = _this$props$Rollbar === void 0 ? Rollbar : _this$props$Rollbar,
instance = _this$props.instance;
tinyInvariant.default(!instance || utils.isRollbarInstance(instance), '`instance` must be a configured instance of Rollbar');
var options = typeof config === 'function' ? config() : config;
var rollbar = instance || new ctor(options);
// TODO: use isUncaught to filter if this is 2nd Provider added
// unless customer wants that
_this.state = {
rollbar: rollbar,
options: options
};
return _this;
}
// componentDidUpdate()
_rollupPluginBabelHelpers.createClass(Provider, [{
key: "render",
value: function render() {
var _this$props2 = this.props,
children = _this$props2.children,
_this$props2$Rollbar = _this$props2.Rollbar,
ctor = _this$props2$Rollbar === void 0 ? Rollbar : _this$props2$Rollbar;
var _this$state = this.state,
rollbar = _this$state.rollbar,
options = _this$state.options;
return /*#__PURE__*/React.createElement(Context.Provider, {
value: _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty({}, RollbarInstance, rollbar), BaseOptions, options), RollbarCtor, ctor)
}, children);
}
}]);
return Provider;
}(React.Component);
_rollupPluginBabelHelpers.defineProperty(Provider, "propTypes", {
Rollbar: PropTypes.func,
config: function config(props, propName, componentName) {
if (!props.config && !props.instance) {
return new Error("One of the required props 'config' or 'instance' must be set for ".concat(componentName, "."));
}
if (props.config) {
var configType = _rollupPluginBabelHelpers.typeof(props.config);
if (configType === 'function' || configType === 'object' && !Array.isArray(configType)) {
return;
}
return new Error("".concat(propName, " must be either an Object or a Function"));
}
},
instance: function instance(props, propName, componentName) {
if (!props.config && !props.instance) {
return new Error("One of the required props 'config' or 'instance' must be set for ".concat(componentName, "."));
}
if (props.instance && !utils.isRollbarInstance(props.instance)) {
return new Error("".concat(propName, " must be a configured instance of Rollbar"));
}
},
children: PropTypes.node
});
exports.BaseOptions = BaseOptions;
exports.Context = Context;
exports.Provider = Provider;
exports.RollbarCtor = RollbarCtor;
exports.RollbarInstance = RollbarInstance;
exports.getRollbarConstructorFromContext = getRollbarConstructorFromContext;
exports.getRollbarFromContext = getRollbarFromContext;
//# sourceMappingURL=Provider.js.map