Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/linting #41

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.min.js
test/browser/coverage
13 changes: 7 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"browser": true,
"mocha": true,
"node": true,
"es6": true,
"es6": true
},
"globals": {
"assert": true
Expand All @@ -15,10 +15,11 @@
"promise"
],
"rules": {
"camelcase": 0,
"no-sequences": 0,
"no-extra-parens": 2,
"no-loop-func": 2,
"require-yield": 2
"camelcase": "off",
"no-sequences": "off",
"no-extra-parens": "error",
"no-loop-func": "error",
"require-yield": "error",
"space-before-blocks": "error"
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ node_modules

run-browserstack-tests.sh

bundle.js
bundle.js

.idea
2 changes: 1 addition & 1 deletion examples/isomorphic/Component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = React.createClass({
propTypes: {
userIdentifier: React.PropTypes.string.isRequired
},
render: function(){
render: function() {
return <div>
<Experiment ref="experiment" name="My Example" userIdentifier={this.props.userIdentifier}>
<Variant name="A">
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"scripts": {
"test": "./node_modules/karma/bin/karma start test/browser/karma.conf.js; mocha --require babel-core/register --require babel-polyfill test/isomorphic/*.jsx",
"build": "./node_modules/.bin/doctoc . --github --title '<h1>Table of Contents</h1>'; ./node_modules/babel-cli/bin/babel.js --presets es2015,stage-1,react --plugins add-module-exports ./src --out-dir ./lib; ./node_modules/webpack/bin/webpack.js --config webpack.standalone.config.js",
"lint": "eslint .",
"lint:fix": "eslint --fix ."
"lint": "eslint --ext js,jsx .",
"lint:fix": "npm run lint -- --fix"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/Experiment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import crc32 from "fbjs/lib/crc32";
let store;

const noopStore = {
getItem: function(){},
setItem: function(){}
getItem: function() {},
setItem: function() {}
};

if (typeof window !== 'undefined' && 'localStorage' in window && window['localStorage'] !== null) {
Expand Down
14 changes: 7 additions & 7 deletions src/debugger.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ if(process.env.NODE_ENV === "production" || !canUseDOM) {
addCSSRule("#pushtell-debugger .pushtell-close, #pushtell-debugger label", "transition: all .25s");
}
function removeStyleSheet() {
if(style !== null){
if(style !== null) {
document.head.removeChild(style);
style = null;
}
}
const Debugger = React.createClass({
displayName: "Pushtell.Debugger",
getInitialState(){
getInitialState() {
return {
experiments: emitter.getActiveExperiments(),
visible: false
Expand All @@ -91,23 +91,23 @@ if(process.env.NODE_ENV === "production" || !canUseDOM) {
visible: !this.state.visible
});
},
updateExperiments(){
updateExperiments() {
this.setState({
experiments: emitter.getActiveExperiments()
});
},
setActiveVariant(experimentName, variantName) {
emitter.setActiveVariant(experimentName, variantName);
},
componentWillMount(){
componentWillMount() {
this.activeSubscription = emitter.addListener("active", this.updateExperiments);
this.inactiveSubscription = emitter.addListener("inactive", this.updateExperiments);
},
componentWillUnmount(){
componentWillUnmount() {
this.activeSubscription.remove();
this.inactiveSubscription.remove();
},
render(){
render() {
var experimentNames = Object.keys(this.state.experiments);
if(this.state.visible) {
return <div className="pushtell-container pushtell-panel">
Expand All @@ -133,7 +133,7 @@ if(process.env.NODE_ENV === "production" || !canUseDOM) {
})}
<div className="pushtell-production-build-note">This panel is hidden on production builds.</div>
</div>;
} else if(experimentNames.length > 0){
} else if(experimentNames.length > 0) {
return <div className="pushtell-container pushtell-handle" onClick={this.toggleVisibility}>
{experimentNames.length} Active Experiment{experimentNames.length > 1 ? "s" : ""}
</div>;
Expand Down
20 changes: 10 additions & 10 deletions src/emitter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const emitter = new EventEmitter();

const PushtellEventEmitter = function() {};

PushtellEventEmitter.prototype.emitWin = function(experimentName){
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){
PushtellEventEmitter.prototype._emitPlay = function(experimentName, variantName) {
if(typeof experimentName !== 'string') {
throw new Error("Required argument 'experimentName' should have type 'string'");
}
Expand All @@ -31,12 +31,12 @@ PushtellEventEmitter.prototype._emitPlay = function(experimentName, variantName)
}
};

PushtellEventEmitter.prototype._resetPlayedExperiments = function(){
PushtellEventEmitter.prototype._resetPlayedExperiments = function() {
values = {};
playedExperiments = {};
}

PushtellEventEmitter.prototype._reset = function(){
PushtellEventEmitter.prototype._reset = function() {
values = {};
experiments = {};
experimentWeights = {};
Expand Down Expand Up @@ -115,7 +115,7 @@ PushtellEventEmitter.prototype.addWinListener = function(experimentName, callbac
});
};

PushtellEventEmitter.prototype.defineVariants = function(experimentName, variantNames, variantWeights){
PushtellEventEmitter.prototype.defineVariants = function(experimentName, variantNames, variantWeights) {
const variantsNamesMap = {};
const variantWeightsMap = {};
variantNames.forEach(variantName => {
Expand Down Expand Up @@ -148,12 +148,12 @@ PushtellEventEmitter.prototype.getSortedVariants = function(experimentName) {
};

PushtellEventEmitter.prototype.getSortedVariantWeights = function(experimentName) {
return this.getSortedVariants(experimentName).map(function(variantName){
return this.getSortedVariants(experimentName).map(function(variantName) {
return experimentWeights[experimentName][variantName];
});
};

PushtellEventEmitter.prototype.getActiveExperiments = function(){
PushtellEventEmitter.prototype.getActiveExperiments = function() {
const response = {};
Object.keys(activeExperiments).forEach(experimentName => {
if(activeExperiments[experimentName] === 0) {
Expand All @@ -167,16 +167,16 @@ PushtellEventEmitter.prototype.getActiveExperiments = function(){
return response;
}

PushtellEventEmitter.prototype.getActiveVariant = function(experimentName){
PushtellEventEmitter.prototype.getActiveVariant = function(experimentName) {
return values[experimentName];
}

PushtellEventEmitter.prototype.setActiveVariant = function(experimentName, variantName, passthrough){
PushtellEventEmitter.prototype.setActiveVariant = function(experimentName, variantName, passthrough) {
values[experimentName] = variantName;
emitter.emit("active-variant", experimentName, variantName, passthrough);
}

PushtellEventEmitter.prototype.addExperimentVariant = function(experimentName, variantName){
PushtellEventEmitter.prototype.addExperimentVariant = function(experimentName, variantName) {
experiments[experimentName] = experiments[experimentName] || {};
experimentWeights[experimentName] = experimentWeights[experimentName] || {};
if(experiments[experimentName][variantName] !== true) {
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/mixpanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import {canUseDOM} from 'fbjs/lib/ExecutionEnvironment';
let playSubscription, winSubscription;

export default {
enable(){
enable() {
if(canUseDOM) {
if(typeof mixpanel === "undefined") {
const error = new Error("React A/B Test Mixpanel Helper: 'mixpanel' global is not defined.");
error.type = "PUSHTELL_HELPER_MISSING_GLOBAL";
throw error;
}
playSubscription = emitter.addPlayListener(function(experimentName, variantName){
playSubscription = emitter.addPlayListener(function(experimentName, variantName) {
mixpanel.track("Experiment Play", {
"Experiment": experimentName,
"Variant": variantName
}, function(){
}, function() {
emitter.emit("mixpanel-play", experimentName, variantName);
});
});
winSubscription = emitter.addWinListener(function(experimentName, variantName){
winSubscription = emitter.addWinListener(function(experimentName, variantName) {
mixpanel.track("Experiment Win", {
"Experiment": experimentName,
"Variant": variantName
}, function(){
}, function() {
emitter.emit("mixpanel-win", experimentName, variantName);
});
});
}
},
disable(){
disable() {
if(canUseDOM) {
if(!playSubscription || !winSubscription) {
const error = new Error("React A/B Test Mixpanel Helper: Helper was not enabled.");
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/segment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ import {canUseDOM} from 'fbjs/lib/ExecutionEnvironment';
let playSubscription, winSubscription;

export default {
enable(){
enable() {
if(canUseDOM) {
if(typeof analytics === "undefined") {
const error = new Error("React A/B Test Segment Helper: 'analytics' global is not defined.");
error.type = "PUSHTELL_HELPER_MISSING_GLOBAL";
throw error;
}
playSubscription = emitter.addPlayListener(function(experimentName, variantName){
playSubscription = emitter.addPlayListener(function(experimentName, variantName) {
analytics.track("Experiment Viewed", {
"experimentName": experimentName,
"variationName": variantName
}, function(){
}, function() {
emitter.emit("segment-play", experimentName, variantName);
});
});
winSubscription = emitter.addWinListener(function(experimentName, variantName){
winSubscription = emitter.addWinListener(function(experimentName, variantName) {
analytics.track("Experiment Won", {
"experimentName": experimentName,
"variationName": variantName
}, function(){
}, function() {
emitter.emit("segment-win", experimentName, variantName);
});
});
}
},
disable(){
disable() {
if(canUseDOM) {
if(!playSubscription || !winSubscription) {
const error = new Error("React A/B Test Segment Helper: Helper was not enabled.");
Expand Down
Loading