@shopgate/pwa-common-commerce 7.9.0-beta.6 → 7.9.0-beta.7

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.
@@ -39,8 +39,10 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
39
39
  * @returns {boolean}
40
40
  */export var isInitialLoading=createSelector(getFavoritesProducts,function(products){if(!products){return true;}return!Object.values(products===null||products===void 0?void 0:products.byList).every(function(l){return l.ready;});});/**
41
41
  * @param {Object} state The global state.
42
- * @return {number}
43
- */export var getFavoritesCount=createSelector(getFavoritesProducts,function(products){if(!(products===null||products===void 0?void 0:products.byList)){return 0;}return Object.values(products.byList).reduce(function(prev,list){return prev+list.items.reduce(function(acc,_ref4){var _ref4$quantity=_ref4.quantity,quantity=_ref4$quantity===void 0?1:_ref4$quantity;return acc+quantity;},0);},0);});/**
42
+ * @param {Object} props The selector props
43
+ * @param {boolean} [props.useItemQuantity=false] Whether to consider item quantity at calculation
44
+ * @return {Function}
45
+ */export var getFavoritesCount=createSelector(getFavoritesProducts,function(_,props){return(props===null||props===void 0?void 0:props.useItemQuantity)||false;},function(products,useItemQuantity){if(!(products===null||products===void 0?void 0:products.byList)){return 0;}return Object.values(products.byList).reduce(function(prev,list){return prev+list.items.reduce(function(acc,_ref4){var _ref4$quantity=_ref4.quantity,quantity=_ref4$quantity===void 0?1:_ref4$quantity;if(useItemQuantity){return acc+quantity;}return acc+1;},0);},0);});/**
44
46
  * @param {Object} state The global state.
45
47
  * @return {boolean}
46
48
  */export var hasFavorites=createSelector(getFavoritesCount,function(count){return!!count;});/**
@@ -4,22 +4,24 @@ import{routeWillEnter$}from'@shopgate/pwa-common/streams/router';import{main$}fr
4
4
  * Gets triggered when the favorites page is about to be entered.
5
5
  * @type {Observable}
6
6
  */export var favoritesWillEnter$=routeWillEnter$.filter(function(_ref){var action=_ref.action;return action.route.pattern===FAVORITES_PATH||action.route.pathname===WISH_LIST_PATH;});/**
7
+ * Gets triggered when ADD_PRODUCT_TO_FAVORITES action is dispatched
8
+ */export var addProductToFavorites$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===ADD_PRODUCT_TO_FAVORITES;});/**
7
9
  * Gets triggered when the debounce time of `addProductToFavorites` passes.
8
10
  * @type {Observable}
9
- */export var addProductToFavoritesDebounced$=main$.filter(function(_ref2){var action=_ref2.action;return action.type===ADD_PRODUCT_TO_FAVORITES;}).debounceTime(FAVORITE_BUTTON_DEBOUNCE_TIME);/**
11
+ */export var addProductToFavoritesDebounced$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===ADD_PRODUCT_TO_FAVORITES;}).debounceTime(FAVORITE_BUTTON_DEBOUNCE_TIME);/**
10
12
  * Gets triggered when the debounce time of `updateProductInFavorites` passes.
11
13
  * @type {Observable}
12
- */export var updateProductInFavoritesDebounced$=main$.filter(function(_ref3){var action=_ref3.action;return action.type===UPDATE_PRODUCT_IN_FAVORITES;}).debounceTime(FAVORITE_QUANTITY_DEBOUNCE_TIME);/**
14
+ */export var updateProductInFavoritesDebounced$=main$.filter(function(_ref4){var action=_ref4.action;return action.type===UPDATE_PRODUCT_IN_FAVORITES;}).debounceTime(FAVORITE_QUANTITY_DEBOUNCE_TIME);/**
13
15
  * Gets triggered when the debounce time of `removeProductFromFavorites` passes.
14
16
  * @type {Observable}
15
- */export var removeProductFromFavoritesDebounced$=main$.filter(function(_ref4){var action=_ref4.action;return action.type===REMOVE_PRODUCT_FROM_FAVORITES;}).debounceTime(FAVORITE_BUTTON_DEBOUNCE_TIME);/**
17
+ */export var removeProductFromFavoritesDebounced$=main$.filter(function(_ref5){var action=_ref5.action;return action.type===REMOVE_PRODUCT_FROM_FAVORITES;}).debounceTime(FAVORITE_BUTTON_DEBOUNCE_TIME);/**
16
18
  * Gets triggered when any errors related to the favorite list occur.
17
19
  * @type {Observable}
18
- */export var favoritesError$=main$.filter(function(_ref5){var action=_ref5.action;return[ERROR_FETCH_FAVORITES,ERROR_ADD_FAVORITES,ERROR_REMOVE_FAVORITES,ERROR_FAVORITES].includes(action.type);});/**
20
+ */export var favoritesError$=main$.filter(function(_ref6){var action=_ref6.action;return[ERROR_FETCH_FAVORITES,ERROR_ADD_FAVORITES,ERROR_REMOVE_FAVORITES,ERROR_FAVORITES].includes(action.type);});/**
19
21
  * Gets triggered when errors occur, that are only related to the frontend part of the
20
22
  * favorite list.
21
23
  * @type {Observable}
22
- */export var errorFavoritesLimit$=favoritesError$.filter(function(_ref6){var action=_ref6.action;return action.type===ERROR_FAVORITES&&action.error&&action.error.code===FAVORITES_LIMIT_ERROR;});/**
24
+ */export var errorFavoritesLimit$=favoritesError$.filter(function(_ref7){var action=_ref7.action;return action.type===ERROR_FAVORITES&&action.error&&action.error.code===FAVORITES_LIMIT_ERROR;});/**
23
25
  * Gets triggered when the app started or when the favorites page is about to be entered.
24
26
  * @type {Observable}
25
27
  */export var shouldFetchFavorites$=favoritesWillEnter$.merge(appDidStart$);/**
@@ -28,39 +30,39 @@ import{routeWillEnter$}from'@shopgate/pwa-common/streams/router';import{main$}fr
28
30
  */export var shouldFetchFreshFavorites$=userDidLogin$.merge(userDidLogout$);/**
29
31
  * Gets triggered when the favorites updated in any way.
30
32
  * @type {Observable}
31
- */export var favoritesDidUpdate$=main$.filter(function(_ref7){var action=_ref7.action;return[REQUEST_ADD_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,RECEIVE_FAVORITES,ERROR_FETCH_FAVORITES].includes(action.type);});/**
33
+ */export var favoritesDidUpdate$=main$.filter(function(_ref8){var action=_ref8.action;return[REQUEST_ADD_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,RECEIVE_FAVORITES,ERROR_FETCH_FAVORITES].includes(action.type);});/**
32
34
  * Gets triggered when an "add to favorites" action is being placed into the favorite list buffer.
33
35
  * @type {Observable}
34
- */export var favoritesWillAddItem$=main$.filter(function(_ref8){var action=_ref8.action;return action.type===REQUEST_ADD_FAVORITES;});/**
36
+ */export var favoritesWillAddItem$=main$.filter(function(_ref9){var action=_ref9.action;return action.type===REQUEST_ADD_FAVORITES;});/**
35
37
  * Gets triggered when a single product has been successfully added to the favorite list.
36
38
  * @type {Observable}
37
- */export var favoritesDidAddItem$=main$.filter(function(_ref9){var action=_ref9.action;return action.type===SUCCESS_ADD_FAVORITES;});/**
39
+ */export var favoritesDidAddItem$=main$.filter(function(_ref10){var action=_ref10.action;return action.type===SUCCESS_ADD_FAVORITES;});/**
38
40
  * Gets triggered when a "remove from favorites" action is being placed into the favorite
39
41
  * list buffer.
40
42
  * @type {Observable}
41
- */export var favoritesWillRemoveItem$=main$.filter(function(_ref10){var action=_ref10.action;return action.type===REQUEST_REMOVE_FAVORITES;});/**
43
+ */export var favoritesWillRemoveItem$=main$.filter(function(_ref11){var action=_ref11.action;return action.type===REQUEST_REMOVE_FAVORITES;});/**
42
44
  * Gets triggered when a single product has been successfully removed from the favorite list.
43
45
  * @type {Observable}
44
- */export var favoritesDidRemoveItem$=main$.filter(function(_ref11){var action=_ref11.action;return action.type===SUCCESS_REMOVE_FAVORITES;});/**
46
+ */export var favoritesDidRemoveItem$=main$.filter(function(_ref12){var action=_ref12.action;return action.type===SUCCESS_REMOVE_FAVORITES;});/**
45
47
  * Gets triggered when the favorite list has successfully been received from the backend.
46
48
  * @type {Observable}
47
- */export var receiveFavorites$=main$.filter(function(_ref12){var action=_ref12.action;return action.type===RECEIVE_FAVORITES;});export var receiveFavoritesWhileVisible$=receiveFavorites$.filter(function(_ref13){var getState=_ref13.getState;var currentPath=getCurrentPathname(getState());return currentPath===FAVORITES_PATH||currentPath===WISH_LIST_PATH;});/**
49
+ */export var receiveFavorites$=main$.filter(function(_ref13){var action=_ref13.action;return action.type===RECEIVE_FAVORITES;});export var receiveFavoritesWhileVisible$=receiveFavorites$.filter(function(_ref14){var getState=_ref14.getState;var currentPath=getCurrentPathname(getState());return currentPath===FAVORITES_PATH||currentPath===WISH_LIST_PATH;});/**
48
50
  * Gets triggered whenever all favorite changes have been successfully processed or once when
49
51
  * any of the buffered change requests fails.
50
52
  * @type {Observable}
51
- */export var favoritesSyncIdle$=main$.filter(function(_ref14){var action=_ref14.action;return action.type===IDLE_SYNC_FAVORITES;});/**
53
+ */export var favoritesSyncIdle$=main$.filter(function(_ref15){var action=_ref15.action;return action.type===IDLE_SYNC_FAVORITES;});/**
52
54
  * Gets triggered after an favorites list has been added.
53
- */export var favoritesListAdded$=main$.filter(function(_ref15){var action=_ref15.action;return action.type===SUCCESS_ADD_FAVORITES_LIST;});/**
55
+ */export var favoritesListAdded$=main$.filter(function(_ref16){var action=_ref16.action;return action.type===SUCCESS_ADD_FAVORITES_LIST;});/**
54
56
  * Gets triggered when the favorites should be refreshed to maintain data consistency.
55
57
  * @type {Observable}
56
58
  */export var refreshFavorites$=favoritesSyncIdle$.debounceTime(FETCH_FAVORITES_THROTTLE);/**
57
59
  * Gets triggered when a product is requested to be added, removed or updated
58
60
  * from the favorite list.
59
61
  * @type {Observable}
60
- */export var didRequestChangeFavorites$=main$.filter(function(_ref16){var action=_ref16.action;return action.type===REQUEST_ADD_FAVORITES||action.type===REQUEST_REMOVE_FAVORITES||action.type===REQUEST_UPDATE_FAVORITES;});/**
62
+ */export var didRequestChangeFavorites$=main$.filter(function(_ref17){var action=_ref17.action;return action.type===REQUEST_ADD_FAVORITES||action.type===REQUEST_REMOVE_FAVORITES||action.type===REQUEST_UPDATE_FAVORITES;});/**
61
63
  * Gets triggered when the favorites action buffer should be flushed immediately.
62
64
  * @type {Observable}
63
- */export var didRequestFlushFavoritesBuffer$=main$.filter(function(_ref17){var action=_ref17.action;return action.type===REQUEST_FLUSH_FAVORITES_BUFFER;});/**
65
+ */export var didRequestFlushFavoritesBuffer$=main$.filter(function(_ref18){var action=_ref18.action;return action.type===REQUEST_FLUSH_FAVORITES_BUFFER;});/**
64
66
  * Gets triggered when the favorites buffer is supposed to be flushed after some delay time or
65
67
  * when the `requestFlushFavoritesBuffer` action was triggered.
66
68
  * @type {Observable}
@@ -1,9 +1,9 @@
1
- import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import appConfig from'@shopgate/pwa-common/helpers/config';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{appDidStart$}from'@shopgate/pwa-common/streams';import groupBy from'lodash/groupBy';import ToastProvider from'@shopgate/pwa-common/providers/toast';import{getLoadWishlistOnAppStartEnabled,getWishlistItemQuantityEnabled}from'@shopgate/engage/core/selectors/shopSettings';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{favoritesWillEnter$,shouldFetchFreshFavorites$,addProductToFavoritesDebounced$,removeProductFromFavoritesDebounced$,errorFavoritesLimit$,refreshFavorites$,didReceiveFlushFavoritesBuffer$,updateProductInFavoritesDebounced$,favoritesDidAddItem$,favoritesSyncIdle$}from"../streams";import{SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import addFavorites from"../actions/addFavorites";import updateFavorites from"../actions/updateFavorites";import removeFavorites from"../actions/removeFavorites";import fetchFavoritesListsWithItems from"../actions/fetchFavoritesListsWithItems";import fetchFavorites from"../actions/fetchFavorites";import{requestAddFavorites,requestRemoveFavorites,cancelRequestSyncFavorites,errorFavorites,idleSyncFavorites,requestUpdateFavorites}from"../action-creators";import{REQUEST_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,FAVORITES_LIMIT_ERROR,REQUEST_UPDATE_FAVORITES,FAVORITES_PATH}from"../constants";import{getFavoritesCount,makeGetProductRelativesOnFavorites,getFavoritesProducts}from"../selectors";/**
1
+ import _regeneratorRuntime from"@babel/runtime/regenerator";function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import appConfig from'@shopgate/pwa-common/helpers/config';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{appDidStart$}from'@shopgate/pwa-common/streams';import groupBy from'lodash/groupBy';import ToastProvider from'@shopgate/pwa-common/providers/toast';import{getLoadWishlistOnAppStartEnabled,getWishlistItemQuantityEnabled}from'@shopgate/engage/core/selectors/shopSettings';import{LoadingProvider}from'@shopgate/pwa-common/providers';import{favoritesWillEnter$,shouldFetchFreshFavorites$,addProductToFavoritesDebounced$,addProductToFavorites$,removeProductFromFavoritesDebounced$,errorFavoritesLimit$,refreshFavorites$,didReceiveFlushFavoritesBuffer$,updateProductInFavoritesDebounced$,favoritesDidAddItem$,favoritesSyncIdle$}from"../streams";import{SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import addFavorites from"../actions/addFavorites";import updateFavorites from"../actions/updateFavorites";import removeFavorites from"../actions/removeFavorites";import fetchFavoritesListsWithItems from"../actions/fetchFavoritesListsWithItems";import fetchFavorites from"../actions/fetchFavorites";import{requestAddFavorites,requestRemoveFavorites,cancelRequestSyncFavorites,errorFavorites,idleSyncFavorites,requestUpdateFavorites}from"../action-creators";import{REQUEST_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,FAVORITES_LIMIT_ERROR,REQUEST_UPDATE_FAVORITES,FAVORITES_PATH}from"../constants";import{getFavoritesCount,makeGetProductRelativesOnFavorites,getFavoritesProducts}from"../selectors";/**
2
2
  * @param {Function} subscribe Subscribes to an observable.
3
3
  */export default function favorites(subscribe){if(!appConfig.hasFavorites){return;}/** App start */subscribe(appDidStart$,/*#__PURE__*/function(){var _ref2=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref){var dispatch,getState,loadWishlistOnAppStartEnabled;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:dispatch=_ref.dispatch,getState=_ref.getState;// Setup sync pipeline dependencies (concurrency to each other and themselves)
4
4
  pipelineDependencies.set(SHOPGATE_USER_ADD_FAVORITES,[SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);pipelineDependencies.set(SHOPGATE_USER_DELETE_FAVORITES,[SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());if(!loadWishlistOnAppStartEnabled){_context.next=7;break;}_context.next=7;return dispatch(fetchFavoritesListsWithItems(false));case 7:case"end":return _context.stop();}}},_callee);}));return function(_x){return _ref2.apply(this,arguments);};}());/** Favorites route enter */subscribe(favoritesWillEnter$,/*#__PURE__*/function(){var _ref4=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3){var dispatch;return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:dispatch=_ref3.dispatch;_context2.next=3;return dispatch(fetchFavoritesListsWithItems(true));case 3:case"end":return _context2.stop();}}},_callee2);}));return function(_x2){return _ref4.apply(this,arguments);};}());/** User login / logout */subscribe(shouldFetchFreshFavorites$,/*#__PURE__*/function(){var _ref6=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref5){var dispatch;return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:dispatch=_ref5.dispatch;_context3.next=3;return dispatch(fetchFavoritesListsWithItems(true));case 3:case"end":return _context3.stop();}}},_callee3);}));return function(_x3){return _ref6.apply(this,arguments);};}());subscribe(addProductToFavoritesDebounced$,function(_ref7){var _getFavoritesProducts;var action=_ref7.action,dispatch=_ref7.dispatch,getState=_ref7.getState;var state=getState();var wishlistItemQuantityEnabled=getWishlistItemQuantityEnabled(state);// Nothing to do, when the store already contains the item
5
5
  var activeProductInList=(_getFavoritesProducts=getFavoritesProducts(state).byList[action.listId])===null||_getFavoritesProducts===void 0?void 0:_getFavoritesProducts.items.find(function(_ref8){var productId=_ref8.productId;return productId===action.productId;});if(activeProductInList&&!wishlistItemQuantityEnabled){// Call cancel action with "zero" count, because request was even dispatched
6
- dispatch(cancelRequestSyncFavorites(0,action.listId));return;}var _appConfig$favorites=appConfig.favorites;_appConfig$favorites=_appConfig$favorites===void 0?{}:_appConfig$favorites;var _appConfig$favorites$=_appConfig$favorites.limit,limit=_appConfig$favorites$===void 0?100:_appConfig$favorites$;var count=getFavoritesCount(state);if(count>=limit){// Dispatch a local error only, because the request to add is prevented
6
+ dispatch(cancelRequestSyncFavorites(0,action.listId));return;}var _appConfig$favorites=appConfig.favorites;_appConfig$favorites=_appConfig$favorites===void 0?{}:_appConfig$favorites;var _appConfig$favorites$=_appConfig$favorites.limit,limit=_appConfig$favorites$===void 0?100:_appConfig$favorites$;var count=getFavoritesCount(state);if(limit&&count>=limit){// Dispatch a local error only, because the request to add is prevented
7
7
  var error=new Error('Limit exceeded');error.code=FAVORITES_LIMIT_ERROR;dispatch(errorFavorites(action.productId,error));}else{dispatch(requestAddFavorites(action.productId,action.listId,action.quantity,action.notes));}});subscribe(updateProductInFavoritesDebounced$,function(_ref9){var action=_ref9.action,dispatch=_ref9.dispatch;dispatch(requestUpdateFavorites(action.productId,action.listId,action.quantity,action.notes));});subscribe(removeProductFromFavoritesDebounced$,function(_ref10){var _getFavoritesProducts2;var action=_ref10.action,dispatch=_ref10.dispatch,getState=_ref10.getState;var count=getFavoritesCount(getState());if(count>0){if(action.withRelatives){// Will only handle ids which are present in the store, no additional check needed
8
8
  var allOnList=makeGetProductRelativesOnFavorites(function(){return action.listId;})(getState(),{productId:action.productId});allOnList.forEach(function(id){return dispatch(requestRemoveFavorites(id,action.listId));});return;}// Avoids trying to remove something that was already removed (incoming fetch response)
9
9
  var list=getFavoritesProducts(getState()).byList[action.listId];if(!(list===null||list===void 0?void 0:list.items.find(function(_ref11){var productId=_ref11.productId;return productId===action.productId;}))){// Call cancel action with "zero" count, because request was even dispatched
@@ -20,4 +20,10 @@ subscribe(errorFavoritesLimit$,function(_ref12){var dispatch=_ref12.dispatch;dis
20
20
  */subscribe(didReceiveFlushFavoritesBuffer$,/*#__PURE__*/function(){var _ref15=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(actionBuffer){var dispatch,actions,actionsByListAndProduct,idleLists;return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1){switch(_context6.prev=_context6.next){case 0:if(!(!Array.isArray(actionBuffer)||!actionBuffer.length)){_context6.next=2;break;}return _context6.abrupt("return");case 2:LoadingProvider.setLoading(FAVORITES_PATH);// All actions provide the same functionality, just take the first entry
21
21
  dispatch=actionBuffer[0].dispatch;// Group all buffered actions by listId and productID
22
22
  actions=actionBuffer.map(function(_ref16){var action=_ref16.action;return action;});actionsByListAndProduct=groupBy(actions,function(_ref17){var listId=_ref17.listId,productId=_ref17.productId;return"".concat(listId,"-").concat(productId,"}");});idleLists=[];_context6.next=9;return Object.values(actionsByListAndProduct).forEach(/*#__PURE__*/function(){var _ref18=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(groupedActions){var _groupedActions,_groupedActions$,productId,listId,quantity,notes,updateActions,addActions,removeActions,_updateActions$slice,_updateActions$slice2,lastUpdateAction,addRemoveBalance;return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:_groupedActions=_slicedToArray(groupedActions,1),_groupedActions$=_groupedActions[0];_groupedActions$=_groupedActions$===void 0?{}:_groupedActions$;productId=_groupedActions$.productId,listId=_groupedActions$.listId,quantity=_groupedActions$.quantity,notes=_groupedActions$.notes;updateActions=groupedActions.filter(function(action){return action.type===REQUEST_UPDATE_FAVORITES;});addActions=groupedActions.filter(function(action){return action.type===REQUEST_ADD_FAVORITES;});removeActions=groupedActions.filter(function(action){return action.type===REQUEST_REMOVE_FAVORITES;});_context5.prev=6;if(!(updateActions.length>0)){_context5.next=11;break;}_updateActions$slice=updateActions.slice(-1),_updateActions$slice2=_slicedToArray(_updateActions$slice,1),lastUpdateAction=_updateActions$slice2[0];_context5.next=11;return dispatch(updateFavorites(lastUpdateAction.productId,lastUpdateAction.listId,lastUpdateAction.quantity,lastUpdateAction.notes));case 11:// Sum up all adds and removes, based on sum dispatch add / remove
23
- addRemoveBalance=addActions.length-removeActions.length;if(!(addRemoveBalance>0)){_context5.next=15;break;}_context5.next=15;return dispatch(addFavorites(productId,listId,quantity,notes));case 15:if(!(addRemoveBalance<0)){_context5.next=18;break;}_context5.next=18;return dispatch(removeFavorites(productId,listId,quantity,notes));case 18:if(!(updateActions.length===0&&addRemoveBalance===0)){_context5.next=22;break;}dispatch(cancelRequestSyncFavorites(groupedActions.length,listId));_context5.next=26;break;case 22:if(idleLists.includes(listId)){_context5.next=26;break;}idleLists.push(listId);_context5.next=26;return dispatch(idleSyncFavorites(listId));case 26:_context5.next=34;break;case 28:_context5.prev=28;_context5.t0=_context5["catch"](6);if(idleLists.includes(listId)){_context5.next=34;break;}idleLists.push(listId);_context5.next=34;return dispatch(idleSyncFavorites(listId));case 34:case"end":return _context5.stop();}}},_callee5,null,[[6,28]]);}));return function(_x6){return _ref18.apply(this,arguments);};}());case 9:case"end":return _context6.stop();}}},_callee6);}));return function(_x5){return _ref15.apply(this,arguments);};}());subscribe(favoritesSyncIdle$,function(){LoadingProvider.resetLoading(FAVORITES_PATH);});subscribe(favoritesDidAddItem$,function(_ref19){var events=_ref19.events;var shouldShowToast=true;if(shouldShowToast){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});}
23
+ addRemoveBalance=addActions.length-removeActions.length;if(!(addRemoveBalance>0)){_context5.next=15;break;}_context5.next=15;return dispatch(addFavorites(productId,listId,quantity,notes));case 15:if(!(addRemoveBalance<0)){_context5.next=18;break;}_context5.next=18;return dispatch(removeFavorites(productId,listId,quantity,notes));case 18:if(!(updateActions.length===0&&addRemoveBalance===0)){_context5.next=22;break;}dispatch(cancelRequestSyncFavorites(groupedActions.length,listId));_context5.next=26;break;case 22:if(idleLists.includes(listId)){_context5.next=26;break;}idleLists.push(listId);_context5.next=26;return dispatch(idleSyncFavorites(listId));case 26:_context5.next=34;break;case 28:_context5.prev=28;_context5.t0=_context5["catch"](6);if(idleLists.includes(listId)){_context5.next=34;break;}idleLists.push(listId);_context5.next=34;return dispatch(idleSyncFavorites(listId));case 34:case"end":return _context5.stop();}}},_callee5,null,[[6,28]]);}));return function(_x6){return _ref18.apply(this,arguments);};}());case 9:case"end":return _context6.stop();}}},_callee6);}));return function(_x5){return _ref15.apply(this,arguments);};}());subscribe(favoritesSyncIdle$,function(){LoadingProvider.resetLoading(FAVORITES_PATH);});subscribe(addProductToFavorites$,function(_ref19){var events=_ref19.events,getState=_ref19.getState;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is disabled, toast is shown instantly after the add
24
+ // action was dispatched. We don't have to wait for the "debounced" action, since
25
+ // removal of wishlist items is not possible.
26
+ if(!loadWishlistOnAppStartEnabled){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});subscribe(favoritesDidAddItem$,function(_ref20){var events=_ref20.events,getState=_ref20.getState;var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(getState());// When wish list loading on app start is enabled, toast is shown after the add action from
27
+ // the buffer system is dispatched. We wait for that since the item might have been removed
28
+ // again within the debounce time.
29
+ if(loadWishlistOnAppStartEnabled){events.emit(ToastProvider.ADD,{id:'favorites.added',message:'favorites.added'});}});}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/pwa-common-commerce",
3
- "version": "7.9.0-beta.6",
3
+ "version": "7.9.0-beta.7",
4
4
  "description": "Commerce library for the Shopgate Connect PWA.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -19,8 +19,8 @@
19
19
  "reselect": "^3.0.1"
20
20
  },
21
21
  "devDependencies": {
22
- "@shopgate/pwa-common": "7.9.0-beta.6",
23
- "@shopgate/pwa-core": "7.9.0-beta.6",
22
+ "@shopgate/pwa-common": "7.9.0-beta.7",
23
+ "@shopgate/pwa-core": "7.9.0-beta.7",
24
24
  "lodash": "^4.17.4",
25
25
  "react": "~16.12.0",
26
26
  "react-dom": "~16.12.0"