From e6ab7116c645db527ed05b291140d8ea3e0f654d Mon Sep 17 00:00:00 2001 From: Kat Hagan Date: Thu, 27 Aug 2020 17:03:00 -0700 Subject: [PATCH] only dispatch SET_ANALYTICS if the value is different from what we have in state (#2306) --- lib/state/simperium/middleware.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/state/simperium/middleware.ts b/lib/state/simperium/middleware.ts index e7b461444..270acb605 100644 --- a/lib/state/simperium/middleware.ts +++ b/lib/state/simperium/middleware.ts @@ -155,9 +155,15 @@ export const initSimperium = ( return; } - dispatch({ - type: 'SET_ANALYTICS', - allowAnalytics: !!updatedEntity.analytics_enabled, + preferencesBucket.get('preferences-key').then((preferences) => { + if ( + updatedEntity.analytics_enabled !== preferences.data.analytics_enabled + ) { + dispatch({ + type: 'SET_ANALYTICS', + allowAnalytics: !!updatedEntity.analytics_enabled, + }); + } }); });