react-ab-test
Version:
A/B testing React components and debug tools. Isomorphic with a simple, universal interface. Well documented and lightweight. Tested in popular browsers and Node.js. Includes helpers for Mixpanel and Segment.com.
2,643 lines • 97 kB
JavaScript
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
module.exports = {
Experiment: __webpack_require__(1),
Variant: __webpack_require__(21),
emitter: __webpack_require__(14),
experimentDebugger: __webpack_require__(24),
mixpanelHelper: __webpack_require__(28),
segmentHelper: __webpack_require__(30)
};
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["Experiment"] = __webpack_require__(2);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(4);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _CoreExperiment = __webpack_require__(13);
var _CoreExperiment2 = _interopRequireDefault(_CoreExperiment);
var _emitter = __webpack_require__(14);
var _emitter2 = _interopRequireDefault(_emitter);
var _crc = __webpack_require__(23);
var _crc2 = _interopRequireDefault(_crc);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var store = void 0;
var noopStore = {
getItem: function getItem() {},
setItem: function setItem() {}
};
if (typeof window !== 'undefined' && 'localStorage' in window && window['localStorage'] !== null) {
try {
var key = '__pushtell_react__';
window.localStorage.setItem(key, key);
if (window.localStorage.getItem(key) !== key) {
store = noopStore;
} else {
window.localStorage.removeItem(key);
store = window.localStorage;
}
} catch (e) {
store = noopStore;
}
} else {
store = noopStore;
}
_emitter2.default.addActiveVariantListener(function (experimentName, variantName, skipSave) {
if (skipSave) {
return;
}
store.setItem('PUSHTELL-' + experimentName, variantName);
});
var Experiment = function (_Component) {
_inherits(Experiment, _Component);
function Experiment() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Experiment);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Experiment.__proto__ || Object.getPrototypeOf(Experiment)).call.apply(_ref, [this].concat(args))), _this), _this.win = function () {
_emitter2.default.emitWin(_this.props.name);
}, _this.getLocalStorageValue = function () {
var activeValue = _emitter2.default.getActiveVariant(_this.props.name);
if (typeof activeValue === "string") {
return activeValue;
}
var storedValue = store.getItem('PUSHTELL-' + _this.props.name);
if (typeof storedValue === "string") {
_emitter2.default.setActiveVariant(_this.props.name, storedValue, true);
return storedValue;
}
if (typeof _this.props.defaultVariantName === 'string') {
_emitter2.default.setActiveVariant(_this.props.name, _this.props.defaultVariantName);
return _this.props.defaultVariantName;
}
/*
Choosing a weighted variant:
For C, A, B with weights 2, 4, 8
variants = A, B, C
weights = 4, 8, 2
weightSum = 14
weightedIndex = 9
AAAABBBBBBBBCC
========^
Select B
*/
// Sorted array of the variant names, example: ["A", "B", "C"]
var variants = _emitter2.default.getSortedVariants(_this.props.name);
// Array of the variant weights, also sorted by variant name. For example, if
// variant C had weight 2, variant A had weight 4, and variant B had weight 8
// return [4, 8, 2] to correspond with ["A", "B", "C"]
var weights = _emitter2.default.getSortedVariantWeights(_this.props.name);
// Sum the weights
var weightSum = weights.reduce(function (a, b) {
return a + b;
}, 0);
// A random number between 0 and weightSum
var weightedIndex = typeof _this.props.userIdentifier === 'string' ? Math.abs((0, _crc2.default)(_this.props.userIdentifier) % weightSum) : Math.floor(Math.random() * weightSum);
// Iterate through the sorted weights, and deduct each from the weightedIndex.
// If weightedIndex drops < 0, select the variant. If weightedIndex does not
// drop < 0, default to the last variant in the array that is initially assigned.
var selectedVariant = variants[variants.length - 1];
for (var index = 0; index < weights.length; index++) {
weightedIndex -= weights[index];
if (weightedIndex < 0) {
selectedVariant = variants[index];
break;
}
}
_emitter2.default.setActiveVariant(_this.props.name, selectedVariant);
return selectedVariant;
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Experiment, [{
key: "render",
value: function render() {
return _react2.default.createElement(_CoreExperiment2.default, _extends({}, this.props, { value: this.getLocalStorageValue }));
}
}]);
return Experiment;
}(_react.Component);
Experiment.propTypes = {
name: _propTypes2.default.string.isRequired,
defaultVariantName: _propTypes2.default.string,
userIdentifier: _propTypes2.default.string
};
Experiment.displayName = "Pushtell.Experiment";
exports.default = Experiment;
module.exports = exports['default'];
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = React;
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
if (process.env.NODE_ENV !== 'production') {
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
var isValidElement = function(object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
};
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = __webpack_require__(6)(isValidElement, throwOnDirectAccess);
} else {
// By explicitly using `prop-types` you are opting into new production behavior.
// http://fb.me/prop-types-in-prod
module.exports = __webpack_require__(12)();
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 5 */
/***/ (function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.prependListener = noop;
process.prependOnceListener = noop;
process.listeners = function (name) { return [] }
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var emptyFunction = __webpack_require__(7);
var invariant = __webpack_require__(8);
var warning = __webpack_require__(9);
var ReactPropTypesSecret = __webpack_require__(10);
var checkPropTypes = __webpack_require__(11);
module.exports = function(isValidElement, throwOnDirectAccess) {
/* global Symbol */
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
/**
* Returns the iterator method function contained on the iterable object.
*
* Be sure to invoke the function with the iterable as context:
*
* var iteratorFn = getIteratorFn(myIterable);
* if (iteratorFn) {
* var iterator = iteratorFn.call(myIterable);
* ...
* }
*
* @param {?object} maybeIterable
* @return {?function}
*/
function getIteratorFn(maybeIterable) {
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
if (typeof iteratorFn === 'function') {
return iteratorFn;
}
}
/**
* Collection of methods that allow declaration and validation of props that are
* supplied to React components. Example usage:
*
* var Props = require('ReactPropTypes');
* var MyArticle = React.createClass({
* propTypes: {
* // An optional string prop named "description".
* description: Props.string,
*
* // A required enum prop named "category".
* category: Props.oneOf(['News','Photos']).isRequired,
*
* // A prop named "dialog" that requires an instance of Dialog.
* dialog: Props.instanceOf(Dialog).isRequired
* },
* render: function() { ... }
* });
*
* A more formal specification of how these methods are used:
*
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
* decl := ReactPropTypes.{type}(.isRequired)?
*
* Each and every declaration produces a function with the same signature. This
* allows the creation of custom validation functions. For example:
*
* var MyLink = React.createClass({
* propTypes: {
* // An optional string or URI prop named "href".
* href: function(props, propName, componentName) {
* var propValue = props[propName];
* if (propValue != null && typeof propValue !== 'string' &&
* !(propValue instanceof URI)) {
* return new Error(
* 'Expected a string or an URI for ' + propName + ' in ' +
* componentName
* );
* }
* }
* },
* render: function() {...}
* });
*
* @internal
*/
var ANONYMOUS = '<<anonymous>>';
// Important!
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
var ReactPropTypes = {
array: createPrimitiveTypeChecker('array'),
bool: createPrimitiveTypeChecker('boolean'),
func: createPrimitiveTypeChecker('function'),
number: createPrimitiveTypeChecker('number'),
object: createPrimitiveTypeChecker('object'),
string: createPrimitiveTypeChecker('string'),
symbol: createPrimitiveTypeChecker('symbol'),
any: createAnyTypeChecker(),
arrayOf: createArrayOfTypeChecker,
element: createElementTypeChecker(),
instanceOf: createInstanceTypeChecker,
node: createNodeChecker(),
objectOf: createObjectOfTypeChecker,
oneOf: createEnumTypeChecker,
oneOfType: createUnionTypeChecker,
shape: createShapeTypeChecker
};
/**
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
*/
/*eslint-disable no-self-compare*/
function is(x, y) {
// SameValue algorithm
if (x === y) {
// Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
// Step 6.a: NaN == NaN
return x !== x && y !== y;
}
}
/*eslint-enable no-self-compare*/
/**
* We use an Error-like object for backward compatibility as people may call
* PropTypes directly and inspect their output. However, we don't use real
* Errors anymore. We don't inspect their stack anyway, and creating them
* is prohibitively expensive if they are created too often, such as what
* happens in oneOfType() for any type before the one that matched.
*/
function PropTypeError(message) {
this.message = message;
this.stack = '';
}
// Make `instanceof Error` still work for returned errors.
PropTypeError.prototype = Error.prototype;
function createChainableTypeChecker(validate) {
if (process.env.NODE_ENV !== 'production') {
var manualPropTypeCallCache = {};
var manualPropTypeWarningCount = 0;
}
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (secret !== ReactPropTypesSecret) {
if (throwOnDirectAccess) {
// New behavior only for users of `prop-types` package
invariant(
false,
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use `PropTypes.checkPropTypes()` to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') {
// Old behavior for people using React.PropTypes
var cacheKey = componentName + ':' + propName;
if (
!manualPropTypeCallCache[cacheKey] &&
// Avoid spamming the console because they are often not actionable except for lib authors
manualPropTypeWarningCount < 3
) {
warning(
false,
'You are manually calling a React.PropTypes validation ' +
'function for the `%s` prop on `%s`. This is deprecated ' +
'and will throw in the standalone `prop-types` package. ' +
'You may be seeing this warning due to a third-party PropTypes ' +
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.',
propFullName,
componentName
);
manualPropTypeCallCache[cacheKey] = true;
manualPropTypeWarningCount++;
}
}
}
if (props[propName] == null) {
if (isRequired) {
if (props[propName] === null) {
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
}
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
}
return null;
} else {
return validate(props, propName, componentName, location, propFullName);
}
}
var chainedCheckType = checkType.bind(null, false);
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;
}
function createPrimitiveTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName, secret) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== expectedType) {
// `propValue` being instance of, say, date/regexp, pass the 'object'
// check, but we can offer a more precise error message here rather than
// 'of type `object`'.
var preciseType = getPreciseType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createAnyTypeChecker() {
return createChainableTypeChecker(emptyFunction.thatReturnsNull);
}
function createArrayOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
}
var propValue = props[propName];
if (!Array.isArray(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
}
for (var i = 0; i < propValue.length; i++) {
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function createElementTypeChecker() {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
if (!isValidElement(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createInstanceTypeChecker(expectedClass) {
function validate(props, propName, componentName, location, propFullName) {
if (!(props[propName] instanceof expectedClass)) {
var expectedClassName = expectedClass.name || ANONYMOUS;
var actualClassName = getClassName(props[propName]);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createEnumTypeChecker(expectedValues) {
if (!Array.isArray(expectedValues)) {
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
return emptyFunction.thatReturnsNull;
}
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
for (var i = 0; i < expectedValues.length; i++) {
if (is(propValue, expectedValues[i])) {
return null;
}
}
var valuesString = JSON.stringify(expectedValues);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
}
return createChainableTypeChecker(validate);
}
function createObjectOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
}
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== 'object') {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
}
for (var key in propValue) {
if (propValue.hasOwnProperty(key)) {
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function createUnionTypeChecker(arrayOfTypeCheckers) {
if (!Array.isArray(arrayOfTypeCheckers)) {
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
return emptyFunction.thatReturnsNull;
}
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
if (typeof checker !== 'function') {
warning(
false,
'Invalid argument supplid to oneOfType. Expected an array of check functions, but ' +
'received %s at index %s.',
getPostfixForTypeWarning(checker),
i
);
return emptyFunction.thatReturnsNull;
}
}
function validate(props, propName, componentName, location, propFullName) {
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
var checker = arrayOfTypeCheckers[i];
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
return null;
}
}
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
}
return createChainableTypeChecker(validate);
}
function createNodeChecker() {
function validate(props, propName, componentName, location, propFullName) {
if (!isNode(props[propName])) {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createShapeTypeChecker(shapeTypes) {
function validate(props, propName, componentName, location, propFullName) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== 'object') {
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
}
for (var key in shapeTypes) {
var checker = shapeTypes[key];
if (!checker) {
continue;
}
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
if (error) {
return error;
}
}
return null;
}
return createChainableTypeChecker(validate);
}
function isNode(propValue) {
switch (typeof propValue) {
case 'number':
case 'string':
case 'undefined':
return true;
case 'boolean':
return !propValue;
case 'object':
if (Array.isArray(propValue)) {
return propValue.every(isNode);
}
if (propValue === null || isValidElement(propValue)) {
return true;
}
var iteratorFn = getIteratorFn(propValue);
if (iteratorFn) {
var iterator = iteratorFn.call(propValue);
var step;
if (iteratorFn !== propValue.entries) {
while (!(step = iterator.next()).done) {
if (!isNode(step.value)) {
return false;
}
}
} else {
// Iterator will provide entry [k,v] tuples rather than values.
while (!(step = iterator.next()).done) {
var entry = step.value;
if (entry) {
if (!isNode(entry[1])) {
return false;
}
}
}
}
} else {
return false;
}
return true;
default:
return false;
}
}
function isSymbol(propType, propValue) {
// Native Symbol.
if (propType === 'symbol') {
return true;
}
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
if (propValue['@@toStringTag'] === 'Symbol') {
return true;
}
// Fallback for non-spec compliant Symbols which are polyfilled.
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
return true;
}
return false;
}
// Equivalent of `typeof` but with special handling for array and regexp.
function getPropType(propValue) {
var propType = typeof propValue;
if (Array.isArray(propValue)) {
return 'array';
}
if (propValue instanceof RegExp) {
// Old webkits (at least until Android 4.0) return 'function' rather than
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
// passes PropTypes.object.
return 'object';
}
if (isSymbol(propType, propValue)) {
return 'symbol';
}
return propType;
}
// This handles more types than `getPropType`. Only used for error messages.
// See `createPrimitiveTypeChecker`.
function getPreciseType(propValue) {
if (typeof propValue === 'undefined' || propValue === null) {
return '' + propValue;
}
var propType = getPropType(propValue);
if (propType === 'object') {
if (propValue instanceof Date) {
return 'date';
} else if (propValue instanceof RegExp) {
return 'regexp';
}
}
return propType;
}
// Returns a string that is postfixed to a warning about an invalid type.
// For example, "undefined" or "of type array"
function getPostfixForTypeWarning(value) {
var type = getPreciseType(value);
switch (type) {
case 'array':
case 'object':
return 'an ' + type;
case 'boolean':
case 'date':
case 'regexp':
return 'a ' + type;
default:
return type;
}
}
// Returns class name of the object, if any.
function getClassName(propValue) {
if (!propValue.constructor || !propValue.constructor.name) {
return ANONYMOUS;
}
return propValue.constructor.name;
}
ReactPropTypes.checkPropTypes = checkPropTypes;
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 7 */
/***/ (function(module, exports) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function makeEmptyFunction(arg) {
return function () {
return arg;
};
}
/**
* This function accepts and discards inputs; it has no side effects. This is
* primarily useful idiomatically for overridable function endpoints which
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
*/
var emptyFunction = function emptyFunction() {};
emptyFunction.thatReturns = makeEmptyFunction;
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
emptyFunction.thatReturnsThis = function () {
return this;
};
emptyFunction.thatReturnsArgument = function (arg) {
return arg;
};
module.exports = emptyFunction;
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
/**
* Use invariant() to assert state which your program assumes to be true.
*
* Provide sprintf-style format (only %s is supported) and arguments
* to provide information about what broke and what you were
* expecting.
*
* The invariant message will be stripped in production, but the invariant
* will remain to ensure logic does not differ in production.
*/
var validateFormat = function validateFormat(format) {};
if (process.env.NODE_ENV !== 'production') {
validateFormat = function validateFormat(format) {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
}
};
}
function invariant(condition, format, a, b, c, d, e, f) {
validateFormat(format);
if (!condition) {
var error;
if (format === undefined) {
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(format.replace(/%s/g, function () {
return args[argIndex++];
}));
error.name = 'Invariant Violation';
}
error.framesToPop = 1; // we don't care about invariant's own frame
throw error;
}
}
module.exports = invariant;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var emptyFunction = __webpack_require__(7);
/**
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var warning = emptyFunction;
if (process.env.NODE_ENV !== 'production') {
(function () {
var printWarning = function printWarning(format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.error(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
warning = function warning(condition, format) {
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (format.indexOf('Failed Composite propType: ') === 0) {
return; // Ignore CompositeComponent proptype check.
}
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
})();
}
module.exports = warning;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 10 */
/***/ (function(module, exports) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
module.exports = ReactPropTypesSecret;
/***/ }),
/* 11 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
if (process.env.NODE_ENV !== 'production') {
var invariant = __webpack_require__(8);
var warning = __webpack_require__(9);
var ReactPropTypesSecret = __webpack_require__(10);
var loggedTypeFailures = {};
}
/**
* Assert that the values match with the type specs.
* Error messages are memorized and will only be shown once.
*
* @param {object} typeSpecs Map of name to a ReactPropType
* @param {object} values Runtime values that need to be type-checked
* @param {string} location e.g. "prop", "context", "child context"
* @param {string} componentName Name of the component for error messages.
* @param {?Function} getStack Returns the component stack.
* @private
*/
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
if (process.env.NODE_ENV !== 'production') {
for (var typeSpecName in typeSpecs) {
if (typeSpecs.hasOwnProperty(typeSpecName)) {
var error;
// Prop type validation may throw. In case they do, we don't want to
// fail the render phase where it didn't fail before. So we log it.
// After these have been cleaned up, we'll let them throw.
try {
// This is intentionally an invariant that gets caught. It's the same
// behavior as without this statement except with a better message.
invariant(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'React.PropTypes.', componentName || 'React class', location, typeSpecName);
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
} catch (ex) {
error = ex;
}
warning(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error);
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
// Only monitor this failure once because there tends to be a lot of the
// same error.
loggedTypeFailures[error.message] = true;
var stack = getStack ? getStack() : '';
warning(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : '');
}
}
}
}
}
module.exports = checkPropTypes;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 12 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var emptyFunction = __webpack_require__(7);
var invariant = __webpack_require__(8);
var ReactPropTypesSecret = __webpack_require__(10);
module.exports = function() {
function shim(props, propName, componentName, location, propFullName, secret) {
if (secret === ReactPropTypesSecret) {
// It is still safe when called from React.
return;
}
invariant(
false,
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use PropTypes.checkPropTypes() to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
};
shim.isRequired = shim;
function getShim() {
return shim;
};
// Important!
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`.
var ReactPropTypes = {
array: shim,
bool: shim,
func: shim,
number: shim,
object: shim,
string: shim,
symbol: shim,
any: shim,
arrayOf: getShim,
element: shim,
instanceOf: getShim,
node: shim,
objectOf: getShim,
oneOf: getShim,
oneOfType: getShim,
shape: getShim
};
ReactPropTypes.checkPropTypes = emptyFunction;
ReactPropTypes.PropTypes = ReactPropTypes;
return ReactPropTypes;
};
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
}
}return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
};
}();
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(4);
var _propTypes2 = _interopRequireDefault(_propTypes);
var _warning = __webpack_require__(9);
var _warning2 = _interopRequireDefault(_warning);
var _emitter = __webpack_require__(14);
var _emitter2 = _interopRequireDefault(_emitter);
var _Variant = __webpack_require__(21);
var _Variant2 = _interopRequireDefault(_Variant);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _possibleConstructorReturn(self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}return call && ((typeof call === "undefined" ? "undefined" : _typeof(call)) === "object" || typeof call === "function") ? call : self;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + (typeof superClass === "undefined" ? "undefined" : _typeof(superClass)));
}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
}
var CoreExperiment = function (_Component) {
_inherits(CoreExperiment, _Component);
function CoreExperiment(props) {
_classCallCheck(this, CoreExperiment);
var _this = _possibleConstructorReturn(this, (CoreExperiment.__proto__ || Object.getPrototypeOf(CoreExperiment)).call(this));
_this.win = function () {
_emitter2.default.emitWin(_this.props.name);
};
_this.state = {};
_this.displayName = "Pushtell.CoreExperiment";
var children = {};
_react2.default.Children.forEach(props.children, function (element) {
if (!_react2.default.isValidElement(element) || element.type.displayName !== "Pushtell.Variant") {
var error = new Error("Pushtell Experiment children must be Pushtell Variant components.");
error.type = "PUSHTELL_INVALID_CHILD";
throw error;
}
children[element.props.name] = element;
_emitter2.default.addExperimentVariant(props.name, element.props.name);
});
_emitter2.default.emit("variants-loaded", props.name);
_this.state.variants = children;
return _this;
}
_createClass(CoreExperiment, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value || nextProps.children !== this.props.children) {
var value = typeof nextProps.value === "function" ? nextProps.value() : nextProps.value;
var children = {};
_react2.default.Children.forEach(nextProps.children, function (element) {
children[element.props.name] = element;
});
this.setState({
value: value,
variants: children
});
}
}
}, {
key: 'componentWillMount',
value: function componentWillMount() {
var _this2 = this;
var value = typeof this.props.value === "function" ? this.props.value() : this.props.value;
if (!this.state.variants[value]) {
if ("production" !== process.env.NODE_ENV) {
(0, _warning2.default)(true, 'Experiment “' + this.props.name + '” does not contain variant “' + value + '”');
}
}
_emitter2.default._incrementActiveExperiments(this.props.name);
_emitter2.default.setActiveVariant(this.props.name, value);
_emitter2.default._emitPlay(this.props.name, value);
this.setState({
value: value
});
this.valueSubscription = _emitter2.default.addActiveVariantListener(this.props.name, function (experimentName, variantName) {
_this2.setState({
value: variantName
});
});
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
_emitter2.default._decrementActiveExperiments(this.props.name);
this.valueSubscription.remove();
}
}, {
key: 'render',
value: function render() {
return this.state.variants[this.state.value] || null;
}
}]);
return CoreExperiment;
}(_react.Component);
CoreExperiment.propTypes = {
name: _propTypes2.default.string.isRequired,
value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]).isRequired
};
exports.default = CoreExperiment;
;
module.exports = exports['default'];
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["emitter"] = __webpack_require__(15);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fbemitter = __webpack_require__(16);
var values = {};
var experiments = {};
var experimentWeights = {};
var activeExperiments = {};
var experimentsWithDefinedVariants = {};
var playedExperiments = {};
var emitter = new _fbemitter.EventEmitter();
var PushtellEventEmitter = function PushtellEventEmitter() {};
PushtellEventEmitter.prototype.emitWin = function (experimentName) {
if (typeof experimentName !== 'string') {
throw new Error("Required argument 'experimentName' should have type 'string'");
}
emitter.emit("win", experimentName, values[experimentName]);
};
PushtellEventEmitter.prototype._emitPlay = function (experimentName, variantName) {
if (typeof experimentName !== 'string') {
throw new Error("Required argument 'experimentName' should have type 'string'");
}
if (typeof variantName !== 'string') {
throw new Error("Required argument 'variantName' should have type 'string'");
}
if (!playedExperiments[experimentName]) {
emitter.emit('play', experimentName, variantName);
playedExperiments[experimentName] = true;
}
};
PushtellEventEmitter.prototype._resetPlayedExperiments = function () {
values = {};
playedExperiments = {};
};
PushtellEventEmitter.prototype._reset = function () {
values = {};
experiments = {};
experimentWeights = {};
activeExperiments = {};
experimentsWithDefinedVariants = {};
playedExperiments = {};
};
PushtellEventEmitter.prototype.rewind = function () {
this._reset();
emitter.removeAllListeners();
};
PushtellEventEmitter.prototype._incrementActiveExperiments = function (experimentName) {
activeExperiments[experimentName] = activeExperiments[experimentName] || 0;
activeExperiments[experimentName] += 1;
emitter.emit("active", experimentName);
};
PushtellEventEmitter.prototype._decrementActiveExperiments = function (experimentName) {
activeExperiments[experimentName] -= 1;
emitter.emit("inactive", experimentName);
};
PushtellEventEmitter.prototype.addActiveVariantListener = function (experimentName, callback) {
if (typeof experimentName === "function") {
callback = experimentName;
return emitter.addListener("active-variant", function (_experimentName, variantName, passthrough) {
callback(_experimentName, variantName, passthrough);
});
}
return emitter.addListener("active-variant", function (_experimentName, variantName, passthrough) {
if (_experimentName === experimentName) {
callback(_experimentName, variantName, passthrough);
}
});
};
PushtellEventEmitter.prototype.emit = function () {
return emitter.emit.apply(emitter, arguments);
};
PushtellEventEmitter.prototype.addListener = function (eventName, callback) {
return emitter.addListener(eventName, callback);
};
PushtellEventEmitter.prototype.once = function (eventName, callback) {
return emitter.once(eventName, callback);
};
PushtellEventEmitter.prototype.addPlayListener = function (experimentName, callback) {
if (typeof experimentName === "function") {
callback = experimentName;
return emitter.addListener('play', function (_experimentName, variantName) {
callback(_experimentName, variantName);
});
}
return emitter.addListener('play', function (_experimentName, variantName) {
if (_experimentName === experimentName) {
callback(_experimentName, variantName);
}
});
};
PushtellEventEmitter.prototype.addWinListener = function (experimentName, callback) {
if (typeof experimentName === "function") {
callback = experimentName;
return emitter.addListener('win', function (_experimentName, variantName) {
callback(_experimentName, variantName);
});
}
return emitter.addListener('win', function (_experimentName, variantName) {
if (_experimentName === experimentName) {
callback(_experimentName, variantName);
}
});
};
PushtellEventEmitter.prototype.defineVariants = function (experimentName, variantNames, variantWeights) {
var variantsNamesMap = {};
var variantWeightsMap = {};
variantNames.forEach(function (variantName) {
variantsNamesMap[variantName] = true;
});
if (Array.isArray(variantWeights)) {
if (variantNames.length !== variantWeights.length) {
throw new Error("Required argument 'variantNames' should have the same number of elements as optional argument 'variantWeights'");
}
variantNames.forEach(function (variantName, index) {
if (typeof variantWeights[index] !== 'number') {
throw new Error("Optional argument 'variantWeights' should be an array of numbers.");
}
variantWeightsMap[variantName] = variantWeights[index];
});
} else {
variantNames.forEach(function (variantName, index) {
variantWeightsMap[variantName] = 1;
});
}
experimentWeights[experimentName] = variantWeightsMap;
experiments[experimentName] = variantsNamesMap;
experimentsWithDefinedVariants[experimentName] = true;
};
PushtellEventEmitter.prototype.getSortedVariants = function (experimentName) {
var variantNames = Object.keys(experiments[experimentName]);
variantNames.sort();
return variantNames;
};
PushtellEventEmitter.prototype.getSortedVariantWeights = function (experimentName) {
return this.getSortedVariants(experimentName).map(function (variantName) {
return experimentWeights[experimentName][variantName];
});
};
PushtellEventEmitter.prototype.getActiveExperiments = function () {
var response = {};
Object.keys(activeExperiments).forEach(function (experimentName) {
if (activeExperiments[experimentName] === 0) {
return;
}
response[experimentName] = {};
Object.keys(experiments[experimentName]).forEach(function (variantName) {
response[experimentName][variantName] = values[experimentName] === variantName;
});
});
return response;
};
PushtellEventEmitter.prototype.getActiveVariant = function (experimentName) {
return values[experimentName];
};
PushtellEventEmitter.prototype.setActiveVariant = function (experimentName, variantName, passthrough) {
values[experimentName] = variantName;
emitter.emit("active-variant", experimentName, variantName, passthrough);
};
PushtellEventEmitter.prototype.addExperimentVariant = function (experimentName, variantName) {
experiments[experimentName] = experiments[experimentName] || {};
experimentWeights[experimentName] = experimentWeights[experimentName] || {};
if (experiments[experimentName][variantName] !== true) {
if (experimentsWithDefinedVariants[experimentName]) {
var error = new Error("Experiment “" + experimentName + "” added new variants after variants were defined.");
error.type = "PUSHTELL_INVALID_VARIANT";
throw error;
}
if (values[experimentName]) {
var _error = new Error("Experiment “" + experimentName + "” added new variants after a variant was selected. Declare the variant names using emitter.defineVariants(experimentName, variantNames).");
_error.type = "PUSHTELL_INVALID_VARIANT";
throw _error;
}
experimentWeights[experimentName][variantName] = 1;
}
experiments[experimentName][variantName] = true;
};
exports.default = new PushtellEventEmitter();
;
module.exports = exports['default'];
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var fbemitter = {
EventEmitter: __webpack_require__(17),
EmitterSubscription : __webpack_require__(18)
};
module.exports = fbemitter;
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule BaseEventEmitter
* @typechecks
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var EmitterSubscription = __webpack_require__(18);
var EventSubscriptionVendor = __webpack_require__(20);
var emptyFunction = __webpack_require__(7);
var invariant = __webpack_require__(8);
/**
* @class BaseEventEmitter
* @description
* An EventEmitter is responsible for managing a set of listeners and publishing
* events to them when it is told that such events happened. In addition to the
* data for the given event it also sends a event control object which allows
* the listeners/handlers to prevent the default behavior of the given event.
*
* The emitter is designed to be generic enough to support all the different
* contexts in which one might want to emit events. It is a simple multicast
* mechanism on top of which extra functionality can be composed. For example, a
* more advanced emitter may use an EventHolder and EventFactory.
*/
var BaseEventEmitter = (function () {
/**
* @constructor
*/
function BaseEventEmitter() {
_classCallCheck(this, BaseEventEmitter);
this._subscriber = new EventSubscriptionVendor();
this._currentSubscription = null;
}
/**
* Adds a listener to be invoked when events of the specified type are
* emitted. An optional calling context may be provided. The data arguments
* emitted will be passed to the listener function.
*
* TODO: Annotate the listener arg's type. This is tricky because listeners
* can be invoked with varargs.
*
* @param {string} eventType - Name of the event to listen to
* @param {function} listener - Function to invoke when the specified event is
* emitted
* @param {*} context - Optional context object to use when invoking the
* listener
*/
BaseEventEmitter.prototype.addListener = function addListener(eventType, listener, context) {
return this._subscriber.addSubscription(eventType, new EmitterSubscription(this._subscriber, listener, context));
};
/**
* Similar to addListener, except that the listener is removed after it is
* invoked once.
*
* @param {string} eventType - Name of the event to listen to
* @param {function} listener - Function to invoke only once when the
* specified event is emitted
* @param {*} context - Optional context object to use when invoking the
* listener
*/
BaseEventEmitter.prototype.once = function once(eventType, listener, context) {
var emitter = this;
return this.addListener(eventType, function () {
emitter.removeCurrentListener();
listener.apply(context, arguments);
});
};
/**
* Removes all of the registered listeners, including those registered as
* listener maps.
*
* @param {?string} eventType - Optional name of the event whose registered
* listeners to remove
*/
BaseEventEmitter.prototype.removeAllListeners = function removeAllListeners(eventType) {
this._subscriber.removeAllSubscriptions(eventType);
};
/**
* Provides an API that can be called during an eventing cycle to remove the
* last listener that was invoked. This allows a developer to provide an event
* object that can remove the listener (or listener map) during the
* invocation.
*
* If it is called when not inside of an emitting cycle it will throw.
*
* @throws {Error} When called not during an eventing cycle
*
* @example
* var subscription = emitter.addListenerMap({
* someEvent: function(data, event) {
* console.log(data);
* emitter.removeCurrentListener();
* }
* });
*
* emitter.emit('someEvent', 'abc'); // logs 'abc'
* emitter.emit('someEvent', 'def'); // does not log anything
*/
BaseEventEmitter.prototype.removeCurrentListener = function removeCurrentListener() {
!!!this._currentSubscription ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Not in an emitting cycle; there is no current subscription') : invariant(false) : undefined;
this._subscriber.removeSubscription(this._currentSubscription);
};
/**
* Returns an array of listeners that are currently registered for the given
* event.
*
* @param {string} eventType - Name of the event to query
* @return {array}
*/
BaseEventEmitter.prototype.listeners = function listeners(eventType) /* TODO: Array<EventSubscription> */{
var subscriptions = this._subscriber.getSubscriptionsForType(eventType);
return subscriptions ? subscriptions.filter(emptyFunction.thatReturnsTrue).map(function (subscription) {
return subscription.listener;
}) : [];
};
/**
* Emits an event of the given type with the given data. All handlers of that
* particular type will be notified.
*
* @param {string} eventType - Name of the event to emit
* @param {*} Arbitrary arguments to be passed to each registered listener
*
* @example
* emitter.addListener('someEvent', function(message) {
* console.log(message);
* });
*
* emitter.emit('someEvent', 'abc'); // logs 'abc'
*/
BaseEventEmitter.prototype.emit = function emit(eventType) {
var subscriptions = this._subscriber.getSubscriptionsForType(eventType);
if (subscriptions) {
var keys = Object.keys(subscriptions);
for (var ii = 0; ii < keys.length; ii++) {
var key = keys[ii];
var subscription = subscriptions[key];
// The subscription may have been removed during this event loop.
if (subscription) {
this._currentSubscription = subscription;
this.__emitToSubscription.apply(this, [subscription].concat(Array.prototype.slice.call(arguments)));
}
}
this._currentSubscription = null;
}
};
/**
* Provides a hook to override how the emitter emits an event to a specific
* subscription. This allows you to set up logging and error boundaries
* specific to your environment.
*
* @param {EmitterSubscription} subscription
* @param {string} eventType
* @param {*} Arbitrary arguments to be passed to each registered listener
*/
BaseEventEmitter.prototype.__emitToSubscription = function __emitToSubscription(subscription, eventType) {
var args = Array.prototype.slice.call(arguments, 2);
subscription.listener.apply(subscription.context, args);
};
return BaseEventEmitter;
})();
module.exports = BaseEventEmitter;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule EmitterSubscription
* @typechecks
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var EventSubscription = __webpack_require__(19);
/**
* EmitterSubscription represents a subscription with listener and context data.
*/
var EmitterSubscription = (function (_EventSubscription) {
_inherits(EmitterSubscription, _EventSubscription);
/**
* @param {EventSubscriptionVendor} subscriber - The subscriber that controls
* this subscription
* @param {function} listener - Function to invoke when the specified event is
* emitted
* @param {*} context - Optional context object to use when invoking the
* listener
*/
function EmitterSubscription(subscriber, listener, context) {
_classCallCheck(this, EmitterSubscription);
_EventSubscription.call(this, subscriber);
this.listener = listener;
this.context = context;
}
return EmitterSubscription;
})(EventSubscription);
module.exports = EmitterSubscription;
/***/ }),
/* 19 */
/***/ (function(module, exports) {
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule EventSubscription
* @typechecks
*/
'use strict';
/**
* EventSubscription represents a subscription to a particular event. It can
* remove its own subscription.
*/
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var EventSubscription = (function () {
/**
* @param {EventSubscriptionVendor} subscriber the subscriber that controls
* this subscription.
*/
function EventSubscription(subscriber) {
_classCallCheck(this, EventSubscription);
this.subscriber = subscriber;
}
/**
* Removes this subscription from the subscriber that controls it.
*/
EventSubscription.prototype.remove = function remove() {
if (this.subscriber) {
this.subscriber.removeSubscription(this);
this.subscriber = null;
}
};
return EventSubscription;
})();
module.exports = EventSubscription;
/***/ }),
/* 20 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule EventSubscriptionVendor
* @typechecks
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var invariant = __webpack_require__(8);
/**
* EventSubscriptionVendor stores a set of EventSubscriptions that are
* subscribed to a particular event type.
*/
var EventSubscriptionVendor = (function () {
function EventSubscriptionVendor() {
_classCallCheck(this, EventSubscriptionVendor);
this._subscriptionsForType = {};
this._currentSubscription = null;
}
/**
* Adds a subscription keyed by an event type.
*
* @param {string} eventType
* @param {EventSubscription} subscription
*/
EventSubscriptionVendor.prototype.addSubscription = function addSubscription(eventType, subscription) {
!(subscription.subscriber === this) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'The subscriber of the subscription is incorrectly set.') : invariant(false) : undefined;
if (!this._subscriptionsForType[eventType]) {
this._subscriptionsForType[eventType] = [];
}
var key = this._subscriptionsForType[eventType].length;
this._subscriptionsForType[eventType].push(subscription);
subscription.eventType = eventType;
subscription.key = key;
return subscription;
};
/**
* Removes a bulk set of the subscriptions.
*
* @param {?string} eventType - Optional name of the event type whose
* registered supscriptions to remove, if null remove all subscriptions.
*/
EventSubscriptionVendor.prototype.removeAllSubscriptions = function removeAllSubscriptions(eventType) {
if (eventType === undefined) {
this._subscriptionsForType = {};
} else {
delete this._subscriptionsForType[eventType];
}
};
/**
* Removes a specific subscription. Instead of calling this function, call
* `subscription.remove()` directly.
*
* @param {object} subscription
*/
EventSubscriptionVendor.prototype.removeSubscription = function removeSubscription(subscription) {
var eventType = subscription.eventType;
var key = subscription.key;
var subscriptionsForType = this._subscriptionsForType[eventType];
if (subscriptionsForType) {
delete subscriptionsForType[key];
}
};
/**
* Returns the array of subscriptions that are currently registered for the
* given event type.
*
* Note: This array can be potentially sparse as subscriptions are deleted
* from it when they are removed.
*
* TODO: This returns a nullable array. wat?
*
* @param {string} eventType
* @return {?array}
*/
EventSubscriptionVendor.prototype.getSubscriptionsForType = function getSubscriptionsForType(eventType) {
return this._subscriptionsForType[eventType];
};
return EventSubscriptionVendor;
})();
module.exports = EventSubscriptionVendor;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 21 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["Variant"] = __webpack_require__(22);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 22 */
/***/ (function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _propTypes = __webpack_require__(4);
var _propTypes2 = _interopRequireDefault(_propTypes);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var Variant = function (_Component) {
_inherits(Variant, _Component);
function Variant() {
_classCallCheck(this, Variant);
return _possibleConstructorReturn(this, (Variant.__proto__ || Object.getPrototypeOf(Variant)).apply(this, arguments));
}
_createClass(Variant, [{
key: 'render',
value: function render() {
if (_react2.default.isValidElement(this.props.children)) {
return this.props.children;
} else {
return _react2.default.createElement(
'span',
null,
this.props.children
);
}
}
}]);
return Variant;
}(_react.Component);
Variant.propTypes = {
name: _propTypes2.default.string.isRequired
};
Variant.displayName = "Pushtell.Variant";
exports.default = Variant;
;
module.exports = exports['default'];
/***/ }),
/* 23 */
/***/ (function(module, exports) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
function crc32(str) {
/* jslint bitwise: true */
var crc = -1;
for (var i = 0, len = str.length; i < len; i++) {
crc = crc >>> 8 ^ table[(crc ^ str.charCodeAt(i)) & 0xFF];
}
return ~crc;
}
var table = [0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D];
if (global.Int32Array !== undefined) {
table = new Int32Array(table);
}
module.exports = crc32;
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 24 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["experimentDebugger"] = __webpack_require__(25);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 25 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {'use strict';
var _react = __webpack_require__(3);
var _react2 = _interopRequireDefault(_react);
var _reactDom = __webpack_require__(26);
var _reactDom2 = _interopRequireDefault(_reactDom);
var _emitter = __webpack_require__(14);
var _emitter2 = _interopRequireDefault(_emitter);
var _ExecutionEnvironment = __webpack_require__(27);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (process.env.NODE_ENV === "production" || !_ExecutionEnvironment.canUseDOM) {
module.exports = {
enable: function enable() {},
disable: function disable() {}
};
} else {
var attachStyleSheet = function attachStyleSheet() {
style = document.createElement("style");
style.appendChild(document.createTextNode(""));
document.head.appendChild(style);
function addCSSRule(selector, rules) {
if ("insertRule" in style.sheet) {
style.sheet.insertRule(selector + "{" + rules + "}", 0);
} else if ("addRule" in style.sheet) {
style.sheet.addRule(selector, rules, 0);
}
}
addCSSRule("#pushtell-debugger", "z-index: 25000");
addCSSRule("#pushtell-debugger", "position: fixed");
addCSSRule("#pushtell-debugger", "transform: translateX(-50%)");
addCSSRule("#pushtell-debugger", "bottom: 0");
addCSSRule("#pushtell-debugger", "left: 50%");
addCSSRule("#pushtell-debugger ul", "margin: 0");
addCSSRule("#pushtell-debugger ul", "padding: 0 0 0 20px");
addCSSRule("#pushtell-debugger li", "margin: 0");
addCSSRule("#pushtell-debugger li", "padding: 0");
addCSSRule("#pushtell-debugger li", "font-size: 14px");
addCSSRule("#pushtell-debugger li", "line-height: 14px");
addCSSRule("#pushtell-debugger input", "float: left");
addCSSRule("#pushtell-debugger input", "margin: 0 10px 0 0");
addCSSRule("#pushtell-debugger input", "padding: 0");
addCSSRule("#pushtell-debugger input", "cursor: pointer");
addCSSRule("#pushtell-debugger label", "color: #999999");
addCSSRule("#pushtell-debugger label", "margin: 0 0 10px 0");
addCSSRule("#pushtell-debugger label", "cursor: pointer");
addCSSRule("#pushtell-debugger label", "font-weight: normal");
addCSSRule("#pushtell-debugger label.active", "color: #000000");
addCSSRule("#pushtell-debugger .pushtell-experiment-name", "font-size: 16px");
addCSSRule("#pushtell-debugger .pushtell-experiment-name", "color: #000000");
addCSSRule("#pushtell-debugger .pushtell-experiment-name", "margin: 0 0 10px 0");
addCSSRule("#pushtell-debugger .pushtell-production-build-note", "font-size: 10px");
addCSSRule("#pushtell-debugger .pushtell-production-build-note", "color: #999999");
addCSSRule("#pushtell-debugger .pushtell-production-build-note", "text-align: center");
addCSSRule("#pushtell-debugger .pushtell-production-build-note", "margin: 10px -40px 0 -10px");
addCSSRule("#pushtell-debugger .pushtell-production-build-note", "border-top: 1px solid #b3b3b3");
addCSSRule("#pushtell-debugger .pushtell-production-build-note", "padding: 10px 10px 5px 10px");
addCSSRule("#pushtell-debugger .pushtell-handle", "cursor: pointer");
addCSSRule("#pushtell-debugger .pushtell-handle", "padding: 5px 10px 5px 10px");
addCSSRule("#pushtell-debugger .pushtell-panel", "padding: 15px 40px 5px 10px");
addCSSRule("#pushtell-debugger .pushtell-container", "font-size: 11px");
addCSSRule("#pushtell-debugger .pushtell-container", "background-color: #ebebeb");
addCSSRule("#pushtell-debugger .pushtell-container", "color: #000000");
addCSSRule("#pushtell-debugger .pushtell-container", "box-shadow: 0px 0 5px rgba(0, 0, 0, 0.1)");
addCSSRule("#pushtell-debugger .pushtell-container", "border-top: 1px solid #b3b3b3");
addCSSRule("#pushtell-debugger .pushtell-container", "border-left: 1px solid #b3b3b3");
addCSSRule("#pushtell-debugger .pushtell-container", "border-right: 1px solid #b3b3b3");
addCSSRule("#pushtell-debugger .pushtell-container", "border-top-left-radius: 2px");
addCSSRule("#pushtell-debugger .pushtell-container", "border-top-right-radius: 2px");
addCSSRule("#pushtell-debugger .pushtell-close", "cursor: pointer");
addCSSRule("#pushtell-debugger .pushtell-close", "font-size: 16px");
addCSSRule("#pushtell-debugger .pushtell-close", "font-weight: bold");
addCSSRule("#pushtell-debugger .pushtell-close", "color: #CC0000");
addCSSRule("#pushtell-debugger .pushtell-close", "position: absolute");
addCSSRule("#pushtell-debugger .pushtell-close", "top: 0px");
addCSSRule("#pushtell-debugger .pushtell-close", "right: 7px");
addCSSRule("#pushtell-debugger .pushtell-close:hover", "color: #FF0000");
addCSSRule("#pushtell-debugger .pushtell-close, #pushtell-debugger label", "transition: all .25s");
};
var removeStyleSheet = function removeStyleSheet() {
if (style !== null) {
document.head.removeChild(style);
style = null;
}
};
var style = null;
var Debugger = _react2.default.createClass({
displayName: "Pushtell.Debugger",
getInitialState: function getInitialState() {
return {
experiments: _emitter2.default.getActiveExperiments(),
visible: false
};
},
toggleVisibility: function toggleVisibility() {
this.setState({
visible: !this.state.visible
});
},
updateExperiments: function updateExperiments() {
this.setState({
experiments: _emitter2.default.getActiveExperiments()
});
},
setActiveVariant: function setActiveVariant(experimentName, variantName) {
_emitter2.default.setActiveVariant(experimentName, variantName);
},
componentWillMount: function componentWillMount() {
this.activeSubscription = _emitter2.default.addListener("active", this.updateExperiments);
this.inactiveSubscription = _emitter2.default.addListener("inactive", this.updateExperiments);
},
componentWillUnmount: function componentWillUnmount() {
this.activeSubscription.remove();
this.inactiveSubscription.remove();
},
render: function render() {
var _this = this;
var experimentNames = Object.keys(this.state.experiments);
if (this.state.visible) {
return _react2.default.createElement(
'div',
{ className: 'pushtell-container pushtell-panel' },
_react2.default.createElement(
'div',
{ className: 'pushtell-close', onClick: this.toggleVisibility },
'\xD7'
),
experimentNames.map(function (experimentName) {
var variantNames = Object.keys(_this.state.experiments[experimentName]);
if (variantNames.length === 0) {
return;
}
return _react2.default.createElement(
'div',
{ className: 'pushtell-experiment', key: experimentName },
_react2.default.createElement(
'div',
{ className: 'pushtell-experiment-name' },
experimentName
),
_react2.default.createElement(
'ul',
null,
variantNames.map(function (variantName) {
return _react2.default.createElement(
'li',
{ key: variantName },
_react2.default.createElement(
'label',
{ className: _this.state.experiments[experimentName][variantName] ? "active" : null, onClick: _this.setActiveVariant.bind(_this, experimentName, variantName) },
_react2.default.createElement('input', { type: 'radio', name: experimentName, value: variantName, defaultChecked: _this.state.experiments[experimentName][variantName] }),
variantName
)
);
})
)
);
}),
_react2.default.createElement(
'div',
{ className: 'pushtell-production-build-note' },
'This panel is hidden on production builds.'
)
);
} else if (experimentNames.length > 0) {
return _react2.default.createElement(
'div',
{ className: 'pushtell-container pushtell-handle', onClick: this.toggleVisibility },
experimentNames.length,
' Active Experiment',
experimentNames.length > 1 ? "s" : ""
);
} else {
return null;
}
}
});
module.exports = {
enable: function enable() {
attachStyleSheet();
var body = document.getElementsByTagName('body')[0];
var container = document.createElement('div');
container.id = 'pushtell-debugger';
body.appendChild(container);
_reactDom2.default.render(_react2.default.createElement(Debugger, null), container);
},
disable: function disable() {
removeStyleSheet();
var body = document.getElementsByTagName('body')[0];
var container = document.getElementById('pushtell-debugger');
if (container) {
_reactDom2.default.unmountComponentAtNode(container);
body.removeChild(container);
}
}
};
}
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ }),
/* 26 */
/***/ (function(module, exports) {
module.exports = ReactDOM;
/***/ }),
/* 27 */
/***/ (function(module, exports) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
'use strict';
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
/**
* Simple, lightweight module assisting with the detection and context of
* Worker. Helps avoid circular dependencies and allows code to reason about
* whether or not they are in a Worker, even if they never include the main
* `ReactWorker` dependency.
*/
var ExecutionEnvironment = {
canUseDOM: canUseDOM,
canUseWorkers: typeof Worker !== 'undefined',
canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
canUseViewport: canUseDOM && !!window.screen,
isInWorker: !canUseDOM // For now, this is true - might change in the future.
};
module.exports = ExecutionEnvironment;
/***/ }),
/* 28 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["mixpanelHelper"] = __webpack_require__(29);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 29 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _emitter = __webpack_require__(14);
var _emitter2 = _interopRequireDefault(_emitter);
var _ExecutionEnvironment = __webpack_require__(27);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var playSubscription = void 0,
winSubscription = void 0;
exports.default = {
enable: function enable() {
if (_ExecutionEnvironment.canUseDOM) {
if (typeof mixpanel === "undefined") {
var error = new Error("React A/B Test Mixpanel Helper: 'mixpanel' global is not defined.");
error.type = "PUSHTELL_HELPER_MISSING_GLOBAL";
throw error;
}
playSubscription = _emitter2.default.addPlayListener(function (experimentName, variantName) {
mixpanel.track("Experiment Play", {
"Experiment": experimentName,
"Variant": variantName
}, function () {
_emitter2.default.emit("mixpanel-play", experimentName, variantName);
});
});
winSubscription = _emitter2.default.addWinListener(function (experimentName, variantName) {
mixpanel.track("Experiment Win", {
"Experiment": experimentName,
"Variant": variantName
}, function () {
_emitter2.default.emit("mixpanel-win", experimentName, variantName);
});
});
}
},
disable: function disable() {
if (_ExecutionEnvironment.canUseDOM) {
if (!playSubscription || !winSubscription) {
var error = new Error("React A/B Test Mixpanel Helper: Helper was not enabled.");
error.type = "PUSHTELL_HELPER_INVALID_DISABLE";
throw error;
}
playSubscription.remove();
winSubscription.remove();
}
}
};
module.exports = exports['default'];
/***/ }),
/* 30 */
/***/ (function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(global) {"use strict";
module.exports = global["segmentHelper"] = __webpack_require__(31);
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
/***/ }),
/* 31 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _emitter = __webpack_require__(14);
var _emitter2 = _interopRequireDefault(_emitter);
var _ExecutionEnvironment = __webpack_require__(27);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var playSubscription = void 0,
winSubscription = void 0;
exports.default = {
enable: function enable() {
if (_ExecutionEnvironment.canUseDOM) {
if (typeof analytics === "undefined") {
var error = new Error("React A/B Test Segment Helper: 'analytics' global is not defined.");
error.type = "PUSHTELL_HELPER_MISSING_GLOBAL";
throw error;
}
playSubscription = _emitter2.default.addPlayListener(function (experimentName, variantName) {
analytics.track("Experiment Viewed", {
"experimentName": experimentName,
"variationName": variantName
}, function () {
_emitter2.default.emit("segment-play", experimentName, variantName);
});
});
winSubscription = _emitter2.default.addWinListener(function (experimentName, variantName) {
analytics.track("Experiment Won", {
"experimentName": experimentName,
"variationName": variantName
}, function () {
_emitter2.default.emit("segment-win", experimentName, variantName);
});
});
}
},
disable: function disable() {
if (_ExecutionEnvironment.canUseDOM) {
if (!playSubscription || !winSubscription) {
var error = new Error("React A/B Test Segment Helper: Helper was not enabled.");
error.type = "PUSHTELL_HELPER_INVALID_DISABLE";
throw error;
}
playSubscription.remove();
winSubscription.remove();
}
}
};
module.exports = exports['default'];
/***/ })
/******/ ]);