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

56 lines (44 loc) 1.86 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports['default'] = generateWinActions; var _immutable = require('immutable'); var _immutable2 = _interopRequireDefault(_immutable); var _getKey = require('./get-key'); var _getKey2 = _interopRequireDefault(_getKey); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } // If the action is one of the ones we listen for, then generate `wins` if that experiment has been played function generateWinActions(props) { var reduxAbTest = props.reduxAbTest, win = props.win, actionType = props.actionType, actionPayload = props.actionPayload; var win_action_types = reduxAbTest.get('win_action_types'); if (!win_action_types.has(actionType)) { return _immutable2['default'].List([]); } var experimentKeys = win_action_types.get(actionType); var reduceToActions = function () { function reduceToActions(list, experimentKey) { if (!reduxAbTest.get('active').has(experimentKey)) { return list; } var experiment = reduxAbTest.get('experiments').find(function (experiment) { return experimentKey === (0, _getKey2['default'])(experiment); }); var variationKey = reduxAbTest.get('active').get(experimentKey); var variation = experiment.get('variations').find(function (variation) { return variationKey === (0, _getKey2['default'])(variation); }); if (!variation) { return list; } return list.push(win({ experiment: experiment, variation: variation, actionType: actionType, actionPayload: actionPayload })); } return reduceToActions; }(); var actionsQueue = experimentKeys.reduce(reduceToActions, _immutable2['default'].List([])); return actionsQueue; } module.exports = exports['default'];