Skip to content

Commit d76d315

Browse files
committed
chore: added if block to return early in initializeStorage
1 parent cecb4bc commit d76d315

1 file changed

Lines changed: 49 additions & 47 deletions

File tree

src/persistence.js

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,61 +39,63 @@ export default function _Persistence(mpInstance) {
3939
if (!mpInstance._Store.isLocalStorageAvailable) {
4040
mpInstance._Store.SDKConfig.useCookieStorage = true;
4141
}
42-
if (!mpInstance._Store.getPrivacyFlag('SDKState')) {
43-
// https://go.mparticle.com/work/SQDSDKS-6046
44-
if (mpInstance._Store.isLocalStorageAvailable) {
45-
storage = window.localStorage;
46-
if (mpInstance._Store.SDKConfig.useCookieStorage) {
47-
// For migrating from localStorage to cookies -- If an instance switches from localStorage to cookies, then
48-
// no mParticle cookie exists yet and there is localStorage. Get the localStorage, set them to cookies, then delete the localStorage item.
42+
if (mpInstance._Store.getPrivacyFlag('SDKState')) {
43+
return;
44+
}
45+
46+
// https://go.mparticle.com/work/SQDSDKS-6046
47+
if (mpInstance._Store.isLocalStorageAvailable) {
48+
storage = window.localStorage;
49+
if (mpInstance._Store.SDKConfig.useCookieStorage) {
50+
// For migrating from localStorage to cookies -- If an instance switches from localStorage to cookies, then
51+
// no mParticle cookie exists yet and there is localStorage. Get the localStorage, set them to cookies, then delete the localStorage item.
52+
if (localStorageData) {
53+
if (cookies) {
54+
// https://go.mparticle.com/work/SQDSDKS-6047
55+
allData = mpInstance._Helpers.extend(
56+
false,
57+
localStorageData,
58+
cookies
59+
);
60+
} else {
61+
allData = localStorageData;
62+
}
63+
storage.removeItem(mpInstance._Store.storageName);
64+
} else if (cookies) {
65+
allData = cookies;
66+
}
67+
self.storeDataInMemory(allData);
68+
} else {
69+
// For migrating from cookie to localStorage -- If an instance is newly switching from cookies to localStorage, then
70+
// no mParticle localStorage exists yet and there are cookies. Get the cookies, set them to localStorage, then delete the cookies.
71+
if (cookies) {
4972
if (localStorageData) {
50-
if (cookies) {
51-
// https://go.mparticle.com/work/SQDSDKS-6047
52-
allData = mpInstance._Helpers.extend(
53-
false,
54-
localStorageData,
55-
cookies
56-
);
57-
} else {
58-
allData = localStorageData;
59-
}
60-
storage.removeItem(mpInstance._Store.storageName);
61-
} else if (cookies) {
73+
// https://go.mparticle.com/work/SQDSDKS-6047
74+
allData = mpInstance._Helpers.extend(
75+
false,
76+
localStorageData,
77+
cookies
78+
);
79+
} else {
6280
allData = cookies;
6381
}
6482
self.storeDataInMemory(allData);
83+
self.expireCookies(mpInstance._Store.storageName);
6584
} else {
66-
// For migrating from cookie to localStorage -- If an instance is newly switching from cookies to localStorage, then
67-
// no mParticle localStorage exists yet and there are cookies. Get the cookies, set them to localStorage, then delete the cookies.
68-
if (cookies) {
69-
if (localStorageData) {
70-
// https://go.mparticle.com/work/SQDSDKS-6047
71-
allData = mpInstance._Helpers.extend(
72-
false,
73-
localStorageData,
74-
cookies
75-
);
76-
} else {
77-
allData = cookies;
78-
}
79-
self.storeDataInMemory(allData);
80-
self.expireCookies(mpInstance._Store.storageName);
81-
} else {
82-
self.storeDataInMemory(localStorageData);
83-
}
85+
self.storeDataInMemory(localStorageData);
8486
}
85-
} else {
86-
self.storeDataInMemory(cookies);
8787
}
88+
} else {
89+
self.storeDataInMemory(cookies);
90+
}
8891

89-
// https://go.mparticle.com/work/SQDSDKS-6046
90-
// Stores all non-current user MPID information into the store
91-
for (var key in allData) {
92-
if (allData.hasOwnProperty(key)) {
93-
if (!SDKv2NonMPIDCookieKeys[key]) {
94-
mpInstance._Store.nonCurrentUserMPIDs[key] =
95-
allData[key];
96-
}
92+
// https://go.mparticle.com/work/SQDSDKS-6046
93+
// Stores all non-current user MPID information into the store
94+
for (var key in allData) {
95+
if (allData.hasOwnProperty(key)) {
96+
if (!SDKv2NonMPIDCookieKeys[key]) {
97+
mpInstance._Store.nonCurrentUserMPIDs[key] =
98+
allData[key];
9799
}
98100
}
99101
}

0 commit comments

Comments
 (0)