|
1 | | -import emitter from "../emitter"; |
2 | | -import {canUseDOM} from 'fbjs/lib/ExecutionEnvironment'; |
| 1 | +import emitter from '../emitter'; |
| 2 | +import { canUseDOM } from 'fbjs/lib/ExecutionEnvironment'; |
3 | 3 |
|
4 | 4 | let playSubscription, winSubscription; |
5 | 5 |
|
6 | 6 | export default { |
7 | | - enable(){ |
8 | | - if(canUseDOM) { |
9 | | - if(typeof analytics === "undefined") { |
10 | | - const error = new Error("React A/B Test Segment Helper: 'analytics' global is not defined."); |
11 | | - error.type = "PUSHTELL_HELPER_MISSING_GLOBAL"; |
| 7 | + enable() { |
| 8 | + if (canUseDOM) { |
| 9 | + if (typeof analytics === 'undefined') { |
| 10 | + const error = new Error( |
| 11 | + "React A/B Test Segment Helper: 'analytics' global is not defined." |
| 12 | + ); |
| 13 | + error.type = 'PUSHTELL_HELPER_MISSING_GLOBAL'; |
12 | 14 | throw error; |
13 | 15 | } |
14 | | - playSubscription = emitter.addPlayListener(function(experimentName, variantName){ |
15 | | - analytics.track("Experiment Viewed", { |
16 | | - "experimentName": experimentName, |
17 | | - "variationName": variantName |
18 | | - }, function(){ |
19 | | - emitter.emit("segment-play", experimentName, variantName); |
20 | | - }); |
| 16 | + playSubscription = emitter.addPlayListener(function ( |
| 17 | + experimentName, |
| 18 | + variantName |
| 19 | + ) { |
| 20 | + analytics.track( |
| 21 | + 'Experiment Viewed', |
| 22 | + { |
| 23 | + experimentName: experimentName, |
| 24 | + variationName: variantName, |
| 25 | + }, |
| 26 | + function () { |
| 27 | + emitter.emit('segment-play', experimentName, variantName); |
| 28 | + } |
| 29 | + ); |
21 | 30 | }); |
22 | | - winSubscription = emitter.addWinListener(function(experimentName, variantName){ |
23 | | - analytics.track("Experiment Won", { |
24 | | - "experimentName": experimentName, |
25 | | - "variationName": variantName |
26 | | - }, function(){ |
27 | | - emitter.emit("segment-win", experimentName, variantName); |
28 | | - }); |
| 31 | + winSubscription = emitter.addWinListener(function ( |
| 32 | + experimentName, |
| 33 | + variantName |
| 34 | + ) { |
| 35 | + analytics.track( |
| 36 | + 'Experiment Won', |
| 37 | + { |
| 38 | + experimentName: experimentName, |
| 39 | + variationName: variantName, |
| 40 | + }, |
| 41 | + function () { |
| 42 | + emitter.emit('segment-win', experimentName, variantName); |
| 43 | + } |
| 44 | + ); |
29 | 45 | }); |
30 | 46 | } |
31 | 47 | }, |
32 | | - disable(){ |
33 | | - if(canUseDOM) { |
34 | | - if(!playSubscription || !winSubscription) { |
35 | | - const error = new Error("React A/B Test Segment Helper: Helper was not enabled."); |
36 | | - error.type = "PUSHTELL_HELPER_INVALID_DISABLE"; |
| 48 | + disable() { |
| 49 | + if (canUseDOM) { |
| 50 | + if (!playSubscription || !winSubscription) { |
| 51 | + const error = new Error( |
| 52 | + 'React A/B Test Segment Helper: Helper was not enabled.' |
| 53 | + ); |
| 54 | + error.type = 'PUSHTELL_HELPER_INVALID_DISABLE'; |
37 | 55 | throw error; |
38 | 56 | } |
39 | 57 | playSubscription.remove(); |
40 | 58 | winSubscription.remove(); |
41 | 59 | } |
42 | | - } |
43 | | -} |
| 60 | + }, |
| 61 | +}; |
0 commit comments