@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuskin/ns-shop",
3
- "version": "7.0.9",
3
+ "version": "7.0.10",
4
4
  "description": "The description that will amaze and astound your audience when they read it",
5
5
  "main": "src/shop.js",
6
6
  "scripts": {
@@ -20,7 +20,8 @@ const shoppingContextCartTypes = {
20
20
 
21
21
  const DEFAULT_CART_TYPE = 'USER';
22
22
 
23
- let cartContents = null;
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 (!cartContents){
232
- cartContents = _equinoxRequest(equinoxRequestOptions).then(result => {
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
- await cartContents
238
-
239
- // if this is a promise, this will resolve it
240
- // otherwise, it won't do anything
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
  }