UNPKG

redux-ab-test

Version:

A/B testing React components with Redux and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for React, Redux, and Segment.io

124 lines (92 loc) 3.52 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _createClass2 = require('babel-runtime/helpers/createClass'); var _createClass3 = _interopRequireDefault(_createClass2); var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); var _inherits2 = require('babel-runtime/helpers/inherits'); var _inherits3 = _interopRequireDefault(_inherits2); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactRedux = require('react-redux'); var _logger = require('./logger'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } var Variation = function (_React$Component) { (0, _inherits3['default'])(Variation, _React$Component); function Variation() { (0, _classCallCheck3['default'])(this, Variation); return (0, _possibleConstructorReturn3['default'])(this, (Variation.__proto__ || (0, _getPrototypeOf2['default'])(Variation)).apply(this, arguments)); } (0, _createClass3['default'])(Variation, [{ key: 'render', value: function () { function render() { var _props = this.props, name = _props.name, children = _props.children; (0, _logger.logger)(__filename + ': Rendering Variation name=\'' + name + '\''); if (!_react2['default'].isValidElement(children)) { return _react2['default'].createElement( 'span', null, children ); } return children; } return render; }() // // Component Lifecycle // }, { key: 'componentWillMount', value: function () { function componentWillMount() { var name = this.props.name; (0, _logger.logger)(__filename + ': componentWillMount: Variation name=\'' + name + '\''); } return componentWillMount; }() }, { key: 'componentDidMount', value: function () { function componentDidMount() { var name = this.props.name; (0, _logger.logger)(__filename + ': componentDidMount: Variation name=\'' + name + '\''); } return componentDidMount; }() }, { key: 'componentWillUnmount', value: function () { function componentWillUnmount() { var name = this.props.name; (0, _logger.logger)(__filename + ': componentWillUnmount: Variation name=\'' + name + '\''); } return componentWillUnmount; }() }]); return Variation; }(_react2['default'].Component); Variation.propTypes = { // Name of your variation name: _react2['default'].PropTypes.string.isRequired, // React element to render: children: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.element, _react2['default'].PropTypes.string]).isRequired }; var mapStateToProps = function () { function mapStateToProps(_ref) { var reduxAbTest = _ref.reduxAbTest; return { reduxAbTest: reduxAbTest }; } return mapStateToProps; }(); exports['default'] = (0, _reactRedux.connect)(mapStateToProps, null)(Variation); module.exports = exports['default'];