@nuskin/ns-shop 7.0.9 → 7.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cart/equinoxCartService.js +15 -12
package/package.json
CHANGED
|
@@ -20,7 +20,8 @@ const shoppingContextCartTypes = {
|
|
|
20
20
|
|
|
21
21
|
const DEFAULT_CART_TYPE = 'USER';
|
|
22
22
|
|
|
23
|
-
let
|
|
23
|
+
let requestStatus = 'idle';
|
|
24
|
+
let cartPromise = null;
|
|
24
25
|
|
|
25
26
|
export default {
|
|
26
27
|
addProductToEquinoxCart,
|
|
@@ -223,22 +224,25 @@ function _getCartShoppingContext() {
|
|
|
223
224
|
async function getEquinoxCart() {
|
|
224
225
|
|
|
225
226
|
const cartType = _getCartShoppingContext();
|
|
226
|
-
|
|
227
|
+
|
|
227
228
|
const equinoxRequestOptions = {
|
|
228
229
|
method: 'GET',
|
|
229
230
|
endpoint: `carts/${cartType}`
|
|
230
231
|
}
|
|
231
|
-
if
|
|
232
|
-
|
|
233
|
-
cartContents = result;
|
|
234
|
-
});
|
|
232
|
+
if(requestStatus === 'pending'){
|
|
233
|
+
return await resolveCartPromise();
|
|
235
234
|
}
|
|
235
|
+
if (requestStatus === 'idle'){
|
|
236
|
+
requestStatus = 'pending';
|
|
237
|
+
cartPromise = _equinoxRequest(equinoxRequestOptions);
|
|
238
|
+
return await resolveCartPromise();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
236
241
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
return cartContents;
|
|
242
|
+
async function resolveCartPromise () {
|
|
243
|
+
const response = await cartPromise;
|
|
244
|
+
requestStatus = 'idle';
|
|
245
|
+
return response;
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
/**
|
|
@@ -467,7 +471,6 @@ const runConfigCallback = async (runConfig) => {
|
|
|
467
471
|
const publishEquinoxCartCount = (options) => {
|
|
468
472
|
getEquinoxCart().then((response) => {
|
|
469
473
|
const cart = response.data;
|
|
470
|
-
cartContents = null;
|
|
471
474
|
events.publish(events.shop.CART_UPDATED, { cartInfo: { qty: cart.value.count }, ...options });
|
|
472
475
|
});
|
|
473
476
|
}
|