Gaëtan Renaudeau
7 years ago
committed by
GitHub
3 changed files with 28 additions and 20 deletions
@ -1,18 +1,18 @@ |
|||||
import { shareAnalyticsSelector } from 'reducers/settings' |
// @flow
|
||||
import { start, stop } from 'analytics/segment' |
|
||||
|
import { hasCompletedOnboardingSelector } from 'reducers/settings' |
||||
|
import { start } from 'analytics/segment' |
||||
|
import type { State } from 'reducers' |
||||
|
|
||||
let isAnalyticsStarted = false |
let isAnalyticsStarted = false |
||||
|
|
||||
export default store => next => action => { |
export default (store: *) => (next: *) => (action: *) => { |
||||
next(action) |
next(action) |
||||
const state = store.getState() |
const state: State = store.getState() |
||||
const shareAnalytics = shareAnalyticsSelector(state) |
const hasCompletedOnboarding = hasCompletedOnboardingSelector(state) |
||||
if (shareAnalytics !== isAnalyticsStarted) { |
|
||||
isAnalyticsStarted = shareAnalytics |
if (hasCompletedOnboarding && !isAnalyticsStarted) { |
||||
if (shareAnalytics) { |
isAnalyticsStarted = true |
||||
start(store) |
start(store) |
||||
} else { |
|
||||
stop() |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
Loading…
Reference in new issue