@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.
39 lines (35 loc) • 1.7 kB
JavaScript
;
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var Rollbar = require('rollbar');
var tinyInvariant = require('./external/tiny-invariant/dist/esm/tiny-invariant.js');
function historyContext(rollbar) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
formatter = _ref.formatter,
filter = _ref.filter;
tinyInvariant.default(rollbar instanceof Rollbar, 'historyContext must have an instance of Rollbar');
tinyInvariant.default(formatter == null || typeof formatter === 'function', "formatter option must be a function, received ".concat(_rollupPluginBabelHelpers.typeof(formatter), " instead"));
tinyInvariant.default(filter == null || typeof filter === 'function', "filter option must be a function, received ".concat(_rollupPluginBabelHelpers.typeof(filter), " instead"));
// v4 of history.listen callback signature is (location, action)
// v5 of history.listen callback signature is ({ location, action })
// this implementation translates it to work for both
return function (v4location, v4action) {
var action = v4location.action,
location = v4location.location;
if (v4action) {
action = v4action;
location = v4location;
}
if (filter && !filter(location, action)) {
return;
}
var context = formatter ? formatter(location, action) : location.pathname;
tinyInvariant.default(typeof context === 'string', 'formatter must return a string value to set the context');
rollbar.configure({
payload: {
context: context
}
});
};
}
exports.historyContext = historyContext;
//# sourceMappingURL=historyContext.js.map