UNPKG

@atlaskit/analytics-next

Version:

React components, HOCs and hooks to assist with tracking user activity with React components

62 lines (61 loc) 3.11 kB
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { default as AnalyticsReactContext } from '@atlaskit/analytics-next-stable-react-context'; var ContextTypes = { getAtlaskitAnalyticsContext: PropTypes.func, getAtlaskitAnalyticsEventHandlers: PropTypes.func }; var noop = function noop() { return []; }; // eslint-disable-next-line @repo/internal/react/no-class-components var AnalyticsContext = /*#__PURE__*/function (_Component) { function AnalyticsContext(props) { var _this; _classCallCheck(this, AnalyticsContext); _this = _callSuper(this, AnalyticsContext, [props]); _defineProperty(_this, "getChildContext", function () { return { getAtlaskitAnalyticsContext: _this.getAnalyticsContext }; }); _defineProperty(_this, "getAnalyticsContext", function () { var data = _this.props.data; var _this$context$getAtla = _this.context.getAtlaskitAnalyticsContext, getAtlaskitAnalyticsContext = _this$context$getAtla === void 0 ? noop : _this$context$getAtla; return [].concat(_toConsumableArray(getAtlaskitAnalyticsContext()), [data]); }); _defineProperty(_this, "getAnalyticsEventHandlers", function () { var _this$context$getAtla2 = _this.context.getAtlaskitAnalyticsEventHandlers, getAtlaskitAnalyticsEventHandlers = _this$context$getAtla2 === void 0 ? noop : _this$context$getAtla2; return getAtlaskitAnalyticsEventHandlers(); }); _this.contextValue = { getAtlaskitAnalyticsContext: _this.getAnalyticsContext, getAtlaskitAnalyticsEventHandlers: _this.getAnalyticsEventHandlers }; return _this; } _inherits(AnalyticsContext, _Component); return _createClass(AnalyticsContext, [{ key: "render", value: function render() { var children = this.props.children; return /*#__PURE__*/React.createElement(AnalyticsReactContext.Provider, { value: this.contextValue }, children); } }]); }(Component); _defineProperty(AnalyticsContext, "contextTypes", ContextTypes); _defineProperty(AnalyticsContext, "childContextTypes", ContextTypes); export default AnalyticsContext;