Skip to content

Commit f682654

Browse files
committed
Merge in ES6 classes. Bump to 2.0.0
1 parent f3bf2fd commit f682654

File tree

6 files changed

+385
-235
lines changed

6 files changed

+385
-235
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ Please [★ on GitHub](https://github.com/pushtell/react-ab-test)!
6969
- [Usage](#usage-2)
7070
- [`segmentHelper.enable()`](#segmenthelperenable)
7171
- [`segmentHelper.disable()`](#segmenthelperdisable)
72-
- [Tests](#tests)
72+
- [How to contribute](#how-to-contribute)
73+
- [Requisites](#requisites)
7374
- [Browser Coverage](#browser-coverage)
7475
- [Running Tests](#running-tests)
7576

lib/Experiment.js

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
Object.defineProperty(exports, "__esModule", {
4-
value: true
4+
value: true
55
});
66

77
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; };
@@ -39,97 +39,97 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
3939
var store = void 0;
4040

4141
var noopStore = {
42-
getItem: function getItem() {},
43-
setItem: function setItem() {}
42+
getItem: function getItem() {},
43+
setItem: function setItem() {}
4444
};
4545

4646
if (typeof window !== 'undefined' && 'localStorage' in window && window['localStorage'] !== null) {
47-
try {
48-
var key = '__pushtell_react__';
49-
window.localStorage.setItem(key, key);
50-
if (window.localStorage.getItem(key) !== key) {
51-
store = noopStore;
52-
} else {
53-
window.localStorage.removeItem(key);
54-
store = window.localStorage;
55-
}
56-
} catch (e) {
57-
store = noopStore;
47+
try {
48+
var key = '__pushtell_react__';
49+
window.localStorage.setItem(key, key);
50+
if (window.localStorage.getItem(key) !== key) {
51+
store = noopStore;
52+
} else {
53+
window.localStorage.removeItem(key);
54+
store = window.localStorage;
5855
}
59-
} else {
56+
} catch (e) {
6057
store = noopStore;
58+
}
59+
} else {
60+
store = noopStore;
6161
}
6262

6363
_emitter2.default.addActiveVariantListener(function (experimentName, variantName, skipSave) {
64-
if (skipSave) {
65-
return;
66-
}
67-
store.setItem('PUSHTELL-' + experimentName, variantName);
64+
if (skipSave) {
65+
return;
66+
}
67+
store.setItem('PUSHTELL-' + experimentName, variantName);
6868
});
6969

7070
var Experiment = function (_Component) {
71-
_inherits(Experiment, _Component);
71+
_inherits(Experiment, _Component);
7272

73-
function Experiment() {
74-
var _ref;
73+
function Experiment() {
74+
var _ref;
7575

76-
var _temp, _this, _ret;
76+
var _temp, _this, _ret;
7777

78-
_classCallCheck(this, Experiment);
78+
_classCallCheck(this, Experiment);
7979

80-
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
81-
args[_key] = arguments[_key];
82-
}
83-
84-
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Experiment.__proto__ || Object.getPrototypeOf(Experiment)).call.apply(_ref, [this].concat(args))), _this), _this.win = function () {
85-
_emitter2.default.emitWin(_this.props.name);
86-
}, _this.getLocalStorageValue = function () {
87-
var activeValue = _emitter2.default.getActiveVariant(_this.props.name);
88-
if (typeof activeValue === "string") {
89-
return activeValue;
90-
}
91-
var storedValue = store.getItem('PUSHTELL-' + _this.props.name);
92-
if (typeof storedValue === "string") {
93-
_emitter2.default.setActiveVariant(_this.props.name, storedValue, true);
94-
return storedValue;
95-
}
96-
if (typeof _this.props.defaultVariantName === 'string') {
97-
_emitter2.default.setActiveVariant(_this.props.name, _this.props.defaultVariantName);
98-
return _this.props.defaultVariantName;
99-
}
100-
var variants = _emitter2.default.getSortedVariants(_this.props.name);
101-
var weights = _emitter2.default.getSortedVariantWeights(_this.props.name);
102-
var weightSum = weights.reduce(function (a, b) {
103-
return a + b;
104-
}, 0);
105-
var weightedIndex = typeof _this.props.userIdentifier === 'string' ? Math.abs((0, _crc2.default)(_this.props.userIdentifier) % weightSum) : Math.floor(Math.random() * weightSum);
106-
var randomValue = variants[variants.length - 1];
107-
for (var index = 0; index < weights.length; index++) {
108-
weightedIndex -= weights[index];
109-
if (weightedIndex < 0) {
110-
randomValue = variants[index];
111-
break;
112-
}
113-
}
114-
_emitter2.default.setActiveVariant(_this.props.name, randomValue);
115-
return randomValue;
116-
}, _temp), _possibleConstructorReturn(_this, _ret);
80+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
81+
args[_key] = arguments[_key];
11782
}
11883

119-
_createClass(Experiment, [{
120-
key: "render",
121-
value: function render() {
122-
return _react2.default.createElement(_CoreExperiment2.default, _extends({}, this.props, { value: this.getLocalStorageValue }));
84+
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Experiment.__proto__ || Object.getPrototypeOf(Experiment)).call.apply(_ref, [this].concat(args))), _this), _this.win = function () {
85+
_emitter2.default.emitWin(_this.props.name);
86+
}, _this.getLocalStorageValue = function () {
87+
var activeValue = _emitter2.default.getActiveVariant(_this.props.name);
88+
if (typeof activeValue === "string") {
89+
return activeValue;
90+
}
91+
var storedValue = store.getItem('PUSHTELL-' + _this.props.name);
92+
if (typeof storedValue === "string") {
93+
_emitter2.default.setActiveVariant(_this.props.name, storedValue, true);
94+
return storedValue;
95+
}
96+
if (typeof _this.props.defaultVariantName === 'string') {
97+
_emitter2.default.setActiveVariant(_this.props.name, _this.props.defaultVariantName);
98+
return _this.props.defaultVariantName;
99+
}
100+
var variants = _emitter2.default.getSortedVariants(_this.props.name);
101+
var weights = _emitter2.default.getSortedVariantWeights(_this.props.name);
102+
var weightSum = weights.reduce(function (a, b) {
103+
return a + b;
104+
}, 0);
105+
var weightedIndex = typeof _this.props.userIdentifier === 'string' ? Math.abs((0, _crc2.default)(_this.props.userIdentifier) % weightSum) : Math.floor(Math.random() * weightSum);
106+
var randomValue = variants[variants.length - 1];
107+
for (var index = 0; index < weights.length; index++) {
108+
weightedIndex -= weights[index];
109+
if (weightedIndex < 0) {
110+
randomValue = variants[index];
111+
break;
123112
}
124-
}]);
113+
}
114+
_emitter2.default.setActiveVariant(_this.props.name, randomValue);
115+
return randomValue;
116+
}, _temp), _possibleConstructorReturn(_this, _ret);
117+
}
118+
119+
_createClass(Experiment, [{
120+
key: "render",
121+
value: function render() {
122+
return _react2.default.createElement(_CoreExperiment2.default, _extends({}, this.props, { value: this.getLocalStorageValue }));
123+
}
124+
}]);
125125

126-
return Experiment;
126+
return Experiment;
127127
}(_react.Component);
128128

129129
Experiment.propTypes = {
130-
name: _propTypes2.default.string.isRequired,
131-
defaultVariantName: _propTypes2.default.string,
132-
userIdentifier: _propTypes2.default.string
130+
name: _propTypes2.default.string.isRequired,
131+
defaultVariantName: _propTypes2.default.string,
132+
userIdentifier: _propTypes2.default.string
133133
};
134134
Experiment.displayName = "Pushtell.Experiment";
135135
exports.default = Experiment;

lib/Variant.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
Object.defineProperty(exports, "__esModule", {
4-
value: true
4+
value: true
55
});
66

77
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; }; }();
@@ -23,34 +23,34 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
2323
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; }
2424

2525
var Variant = function (_Component) {
26-
_inherits(Variant, _Component);
27-
28-
function Variant() {
29-
_classCallCheck(this, Variant);
30-
31-
return _possibleConstructorReturn(this, (Variant.__proto__ || Object.getPrototypeOf(Variant)).apply(this, arguments));
26+
_inherits(Variant, _Component);
27+
28+
function Variant() {
29+
_classCallCheck(this, Variant);
30+
31+
return _possibleConstructorReturn(this, (Variant.__proto__ || Object.getPrototypeOf(Variant)).apply(this, arguments));
32+
}
33+
34+
_createClass(Variant, [{
35+
key: 'render',
36+
value: function render() {
37+
if (_react2.default.isValidElement(this.props.children)) {
38+
return this.props.children;
39+
} else {
40+
return _react2.default.createElement(
41+
'span',
42+
null,
43+
this.props.children
44+
);
45+
}
3246
}
47+
}]);
3348

34-
_createClass(Variant, [{
35-
key: 'render',
36-
value: function render() {
37-
if (_react2.default.isValidElement(this.props.children)) {
38-
return this.props.children;
39-
} else {
40-
return _react2.default.createElement(
41-
'span',
42-
null,
43-
this.props.children
44-
);
45-
}
46-
}
47-
}]);
48-
49-
return Variant;
49+
return Variant;
5050
}(_react.Component);
5151

5252
Variant.propTypes = {
53-
name: _propTypes2.default.string.isRequired
53+
name: _propTypes2.default.string.isRequired
5454
};
5555
Variant.displayName = "Pushtell.Variant";
5656
exports.default = Variant;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"A/B test"
1212
],
1313
"main": "index.js",
14-
"version": "1.9.0",
14+
"version": "2.0.0",
1515
"description": "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.",
1616
"directories": {
1717
"test": "test"

0 commit comments

Comments
 (0)