Skip to content

Commit b6fe8ce

Browse files
committed
Merge pull request #15 from HubSpot/experiment-class-naming
Experiment class naming
2 parents 23bbb00 + 3ab1598 commit b6fe8ce

File tree

8 files changed

+24
-29
lines changed

8 files changed

+24
-29
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ npm install react-experiments
1111

1212
# Usage
1313

14-
react-experiments was built to work with [PlanOut.js](https://www.github.com/HubSpot/PlanOut.js) and most of its constructs are inspired by the structure of PlanOut.js. This library will work out of the box if you pass it an instantiated PlanOut Namespace or Experiment class, but if you want to use your own methods of assigning experiment parameters and logging exposure then you can extend the base [experiment class](https://github.com/HubSpot/react-experiments/blob/master/src/experimentClass.js) and pass that as the experiment class prop.
14+
react-experiments was built to work with [PlanOut.js](https://www.github.com/HubSpot/PlanOut.js) and most of its constructs are inspired by the structure of PlanOut.js. This library will work out of the box if you pass it an instantiated PlanOut Namespace or Experiment class, but if you want to use your own methods of assigning experiment parameters and logging exposure then you can extend the base [experiment class](https://github.com/HubSpot/react-experiments/blob/master/src/Experiment.js) and pass that as the experiment class prop.
1515

1616

1717
## Implementing a simple experiment
1818

1919
This library serves as a way to declaratively implement UI experiments that are defined via PlanOut. The standard usage of this library is as follows:
2020

21-
1) Define experiment via PlanOut script / API. The PlanOut parameters that you set should map to the props on which you want to run an experiment. Let's use the [sample PlanOut.js experiment](https://github.com/HubSpot/PlanOut.js/blob/master/examples/sample_planout_es5.js#L41) as an example, which is effectively:
21+
1) Define experiment via PlanOut script / API. The PlanOut parameters that you set should map to the props on which you want to run an experiment. Let's use the [sample PlanOut.js experiment](https://github.com/HubSpot/PlanOut.js/blob/master/examples/sample_planout_es5.js#L41) as an example, which is effectively:
2222

2323
```
2424
signupText = uniformChoice(choices=['Signup', 'Join now'])
@@ -69,7 +69,7 @@ let Parent = React.createClass({
6969

7070
The implementation of all the components provided by this library are wrappers around a base ```Parametrize``` component. The ```Parametrize``` component allows for parametrizing a given component with experiment parameters. The following are the props that the ```Parametrize``` component takes:
7171

72-
**experiment**: This is an instance of a PlanOut.js experiment / namespace class or the base experimentClass. [REQUIRED]
72+
**experiment**: This is an instance of a PlanOut.js experiment/namespace class or the base Experiment class. [REQUIRED]
7373

7474

7575
**params**: This is the list of experiment parameters that you want to use to parametrize the component. They should correspond to the parameter names defined in your PlanOut script / experiment definition. [REQUIRED]
@@ -78,7 +78,7 @@ The implementation of all the components provided by this library are wrappers a
7878

7979
### Higher-order Parametrization Components
8080

81-
There are two primary higher-order components to use for parametrization.
81+
There are two primary higher-order components to use for parametrization.
8282

8383
**parametrize**: The ```parametrize``` function takes an instantiated experiment class, either an experiment name or a list of params, and a React component. It takes the given component and sets the deterministically and randomly assigned experiment parameters of the experiment class as props.
8484

@@ -152,7 +152,7 @@ The ABTest component above branches off the value of ```this.props.experiment.ge
152152
153153
The ABTest component takes the following as props:
154154
155-
**experiment** - an instantiated PlanOut namespace or experiment class or a custom experimentClass. [REQUIRED]
155+
**experiment** - an instantiated PlanOut namespace/experiment class or a custom Experiment class. [REQUIRED]
156156
157157
**on** - the parameter name to "branch" off [REQUIRED]
158158

__tests__/testExperimentClass.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ReactExperiments from '../dist/react-experiments';
44
let logs = [];
55
const paramKey = 'foo';
66
const paramVal = 'bar';
7-
class experiment extends ReactExperiments.experimentClass {
7+
class Experiment extends ReactExperiments.Experiment {
88
get(param) {
99
if (param === paramKey) {
1010
return paramVal;
@@ -24,7 +24,7 @@ class experiment extends ReactExperiments.experimentClass {
2424
}
2525
}
2626

27-
const expClass = new experiment();
27+
const exp = new Experiment();
2828
const TestUtils = React.addons.TestUtils;
2929
describe('Test experiment', () => {
3030
beforeEach(() => {
@@ -47,7 +47,7 @@ describe('Test experiment', () => {
4747
});
4848

4949
const parametrized = TestUtils.renderIntoDocument(
50-
<ReactExperiments.Parametrize experiment={expClass} params={[paramKey]}>
50+
<ReactExperiments.Parametrize experiment={exp} params={[paramKey]}>
5151
<Comp />
5252
</ReactExperiments.Parametrize>
5353
);
@@ -57,4 +57,4 @@ describe('Test experiment', () => {
5757
).length).toBe(1);
5858
expect(logs.length).toEqual(1);
5959
});
60-
});
60+
});

build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node node_modules/webpack/bin/webpack --config build/webpack.config.js
22
node node_modules/webpack/bin/webpack --config build/webpack.config.minified.js
3-
npm test

build/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Variations from '../src/variationComponents';
2-
import experimentClass from '../src/experimentClass';
2+
import Experiment from '../src/Experiment';
33
import ABTest from '../src/abtest';
44
import Parametrize from '../src/parametrize';
55
import withExperimentParams from '../src/withExperimentParams';
@@ -9,7 +9,7 @@ export default {
99
ABTest: ABTest,
1010
When: Variations.When,
1111
Default: Variations.Default,
12-
experimentClass: experimentClass,
12+
Experiment: Experiment,
1313
Parametrize: Parametrize,
1414
withExperimentParams: withExperimentParams,
1515
parametrize: parametrize

dist/react-experiments.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ return /******/ (function(modules) { // webpackBootstrap
6262

6363
var Variations = _interopRequireWildcard(__webpack_require__(1));
6464

65-
var experimentClass = _interopRequire(__webpack_require__(3));
65+
var Experiment = _interopRequire(__webpack_require__(3));
6666

6767
var ABTest = _interopRequire(__webpack_require__(4));
6868

@@ -76,7 +76,7 @@ return /******/ (function(modules) { // webpackBootstrap
7676
ABTest: ABTest,
7777
When: Variations.When,
7878
Default: Variations.Default,
79-
experimentClass: experimentClass,
79+
Experiment: Experiment,
8080
Parametrize: Parametrize,
8181
withExperimentParams: withExperimentParams,
8282
parametrize: parametrize
@@ -190,12 +190,12 @@ return /******/ (function(modules) { // webpackBootstrap
190190

191191
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } };
192192

193-
var experimentClass = (function () {
194-
function experimentClass() {
195-
_classCallCheck(this, experimentClass);
193+
var Experiment = (function () {
194+
function Experiment() {
195+
_classCallCheck(this, Experiment);
196196
}
197197

198-
_createClass(experimentClass, {
198+
_createClass(Experiment, {
199199
get: {
200200
value: function get(parameter) {
201201
throw "IMPLEMENT get";
@@ -223,12 +223,10 @@ return /******/ (function(modules) { // webpackBootstrap
223223
}
224224
});
225225

226-
return experimentClass;
226+
return Experiment;
227227
})();
228228

229-
;
230-
231-
module.exports = experimentClass;
229+
module.exports = Experiment;
232230

233231
/***/ },
234232
/* 4 */

dist/react-experiments.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-experiments",
3-
"version": "2.1.0",
3+
"version": "3.0.0",
44
"dependencies": {
55
"react": "^0.13.3"
66
},
@@ -48,8 +48,8 @@
4848
]
4949
},
5050
"scripts": {
51-
"test": "jest",
52-
"build-and-test": "sh build.sh"
51+
"test": "sh build.sh && jest",
52+
"build": "sh build.sh"
5353
},
5454
"license": "MIT"
5555
}

src/experimentClass.js renamed to src/Experiment.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class experimentClass {
1+
export default class Experiment {
22
get(parameter) {
33
throw "IMPLEMENT get";
44
}
@@ -19,5 +19,3 @@ class experimentClass {
1919
throw "IMPLEMENT shouldFetchExperimentParameter";
2020
}
2121
};
22-
23-
export default experimentClass;

0 commit comments

Comments
 (0)