Skip to content
Permalink
Browse files

feat: add getActiveVariant function to ExperimentConsumer and withExp…

…eriments
  • Loading branch information...
danhayden committed May 30, 2018
1 parent 6ac4498 commit aec03d44a944eeeda5a3498f47e475e35c36a511
Showing with 11 additions and 1 deletion.
  1. +11 −1 src/index.js
@@ -67,11 +67,20 @@ class ExperimentProvider extends Component {
.then(this.getExperiments);
};

getActiveVariant = experimentId => {
const { experiments } = this.state;
const experimentIds = Object.keys(experiments);
return experimentIds.includes(experimentId)
? experiments[experimentId].activeVariant
: null;
};

state = {
experiments: {},
createExperiment: this.createExperiment,
removeExperiment: this.removeExperiment,
setExperimentVariant: this.setExperimentVariant
setExperimentVariant: this.setExperimentVariant,
getActiveVariant: this.getActiveVariant
};

componentDidMount() {
@@ -169,6 +178,7 @@ function withExperiments(WrappedComponent) {
createExperiment={context.createExperiment}
removeExperiment={context.removeExperiment}
setExperimentVariant={context.setExperimentVariant}
getActiveVariant={context.getActiveVariant}
/>
)}
</ExperimentConsumer>

0 comments on commit aec03d4

Please sign in to comment.
You can’t perform that action at this time.