@shopgate/pwa-common-commerce 7.20.0-beta.2 → 7.20.0-beta.4
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/favorites/actions/addFavorites.js +3 -3
- package/favorites/actions/addFavoritesList.js +2 -2
- package/favorites/actions/fetchFavoriteIds.js +9 -0
- package/favorites/actions/fetchFavorites.js +5 -6
- package/favorites/actions/fetchFavoritesList.js +6 -2
- package/favorites/actions/fetchFavoritesListsWithItems.js +7 -2
- package/favorites/actions/removeFavorites.js +3 -3
- package/favorites/actions/removeFavoritesList.js +2 -2
- package/favorites/actions/toggleFavorites.js +2 -2
- package/favorites/actions/updateFavorites.js +3 -3
- package/favorites/actions/updateFavoritesList.js +2 -2
- package/favorites/constants/Pipelines.js +1 -1
- package/favorites/selectors/index.js +18 -3
- package/favorites/subscriptions/index.js +6 -4
- package/favorites/subscriptions/spec.js +2 -2
- package/package.json +3 -3
- package/product/actions/fetchProductImages.js +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_ADD_FAVORITES}from"../constants/Pipelines";import{successAddFavorites,errorAddFavorites}from"../action-creators";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}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{mutable}from'@shopgate/pwa-common/helpers/redux';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{getWishlistItemNotesEnabled,getWishlistItemQuantityEnabled}from'@shopgate/engage/core/selectors';import{SHOPGATE_USER_ADD_FAVORITES}from"../constants/Pipelines";import{successAddFavorites,errorAddFavorites}from"../action-creators";import{getHasMultipleFavoritesListsSupport,getFavoritesDefaultList}from"../selectors";/**
|
|
2
2
|
* Adds a single product to the favorite list using the `addFavorites` pipeline.
|
|
3
3
|
* @param {string} productId Id of the product to be added.
|
|
4
4
|
* @param {string} listId Id of the list to be added.
|
|
@@ -6,5 +6,5 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
|
|
|
6
6
|
* @param {string} notes New favorites notes to set
|
|
7
7
|
* @param {boolean} showToast Whether to show a confirmation toast after product was added
|
|
8
8
|
* @returns {Function} A redux thunk.
|
|
9
|
-
*/function addFavorites(productId){var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var quantity=arguments.length>2?arguments[2]:undefined;var notes=arguments.length>3?arguments[3]:undefined;var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var
|
|
10
|
-
|
|
9
|
+
*/function addFavorites(productId){var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var quantity=arguments.length>2?arguments[2]:undefined;var notes=arguments.length>3?arguments[3]:undefined;var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,hasMultiSupport,quantityEnabled,notesEnabled,defaultList,takenListId,request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:state=getState();hasMultiSupport=getHasMultipleFavoritesListsSupport(state);quantityEnabled=getWishlistItemQuantityEnabled(state);notesEnabled=getWishlistItemNotesEnabled(state);// Fallback for deprecated calls without list id.
|
|
10
|
+
defaultList=getFavoritesDefaultList(state);takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES).setInput(_extends({productId:productId},hasMultiSupport?{favoritesListId:takenListId}:null,{},quantityEnabled?{quantity:quantity}:null,{},notesEnabled?{notes:notes}:null)).setRetries(0).dispatch();_context.prev=7;_context.next=10;return request;case 10:dispatch(successAddFavorites(productId,takenListId,showToast));_context.next=16;break;case 13:_context.prev=13;_context.t0=_context["catch"](7);dispatch(errorAddFavorites(productId,_context.t0,takenListId));case 16:return _context.abrupt("return",request);case 17:case"end":return _context.stop();}},_callee,null,[[7,13]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default mutable(addFavorites);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_ADD_FAVORITES_LIST}from"../constants/Pipelines";import{SUCCESS_ADD_FAVORITES_LIST}from"../constants";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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{mutable}from'@shopgate/pwa-common/helpers/redux';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_ADD_FAVORITES_LIST}from"../constants/Pipelines";import{SUCCESS_ADD_FAVORITES_LIST}from"../constants";/**
|
|
2
2
|
* Adds a new favorite list.
|
|
3
3
|
* @param {string} name Name of the wishlist.
|
|
4
4
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/function addFavoritesList(name){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request,_ref3,id;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES_LIST).setInput({name:name}).setRetries(0).dispatch();_context.prev=1;_context.next=4;return request;case 4:_ref3=_context.sent;id=_ref3.id;dispatch({type:SUCCESS_ADD_FAVORITES_LIST,listId:id,name:name});_context.next=11;break;case 9:_context.prev=9;_context.t0=_context["catch"](1);case 11:case"end":return _context.stop();}},_callee,null,[[1,9]]);}));return function(_x){return _ref.apply(this,arguments);};}());}export default addFavoritesList;
|
|
5
|
+
*/function addFavoritesList(name){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request,_ref3,id;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES_LIST).setInput({name:name}).setRetries(0).dispatch();_context.prev=1;_context.next=4;return request;case 4:_ref3=_context.sent;id=_ref3.id;dispatch({type:SUCCESS_ADD_FAVORITES_LIST,listId:id,name:name});_context.next=11;break;case 9:_context.prev=9;_context.t0=_context["catch"](1);case 11:case"end":return _context.stop();}},_callee,null,[[1,9]]);}));return function(_x){return _ref.apply(this,arguments);};}());}export default mutable(addFavoritesList);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{EFAVORITE,EUNKNOWN}from'@shopgate/pwa-core/constants/Pipeline';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_USER_GET_FAVORITE_IDS}from"../constants/Pipelines";import{receiveFavorites,requestFavorites,errorFetchFavorites}from"../action-creators";import{getHasMultipleFavoritesListsSupport,makeGetFavoritesProductsByList}from"../selectors";/**
|
|
2
|
+
* Fetch favorite IDs of a favorites list action.
|
|
3
|
+
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
|
+
* @param {string} [favoritesListId] The ID of the favorites list
|
|
5
|
+
* @returns {Function} A redux thunk.
|
|
6
|
+
*/function fetchFavoriteIds(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var favoritesListId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:'DEFAULT';return function(dispatch,getState){var hasMultiSupport=getHasMultipleFavoritesListsSupport(getState());var getFavoritesProductsByList=makeGetFavoritesProductsByList(function(){return favoritesListId;});var data=getFavoritesProductsByList(getState());if(!ignoreCache&&!shouldFetchData(data)){return Promise.resolve(data);}var timestamp=Date.now();dispatch(requestFavorites(favoritesListId));return new PipelineRequest(SHOPGATE_USER_GET_FAVORITE_IDS).setInput(_extends({},hasMultiSupport?{favoritesListId:favoritesListId}:null)).setErrorBlacklist([EFAVORITE,EUNKNOWN]).dispatch().then(function(_ref){var productIds=_ref.productIds;/**
|
|
7
|
+
* Sanitize the pipeline return value to archive compatibility with the reducers for the
|
|
8
|
+
* fetchFavorites pipeline.
|
|
9
|
+
*/var items=productIds.map(function(productId){return{product:{id:productId}};});var sanitizedResponse={items:items,itemCount:items.length};dispatch(receiveFavorites(sanitizedResponse.items,timestamp,favoritesListId));return sanitizedResponse;})["catch"](function(err){dispatch(errorFetchFavorites(err,favoritesListId));});};}/** @mixes {MutableFunction} */export default mutable(fetchFavoriteIds);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{EFAVORITE,EUNKNOWN,EBIGAPI,ELIMIT}from'@shopgate/pwa-core/constants/Pipeline';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{hasNewServices}from'@shopgate/engage/core/helpers';import{SHOPGATE_USER_GET_FAVORITES}from"../constants/Pipelines";import{receiveFavorites,requestFavorites,errorFetchFavorites}from"../action-creators";import receiveProducts from"../../product/action-creators/receiveProducts";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{EFAVORITE,EUNKNOWN,EBIGAPI,ELIMIT}from'@shopgate/pwa-core/constants/Pipeline';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{hasNewServices}from'@shopgate/engage/core/helpers';import{SHOPGATE_USER_GET_FAVORITES}from"../constants/Pipelines";import{receiveFavorites,requestFavorites,errorFetchFavorites}from"../action-creators";import{getHasMultipleFavoritesListsSupport,makeGetFavoritesProductsByList,getFavoritesDefaultList}from"../selectors";import receiveProducts from"../../product/action-creators/receiveProducts";/**
|
|
2
2
|
* Fetch favorites action.
|
|
3
3
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
4
|
* @param {string} listId The id of the list that needs to be fetched.
|
|
5
5
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/function fetchFavorites(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:undefined;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
result.items=((result===null||result===void 0?void 0:result.products)||[]).map(function(product){return{product:product,note:null,quantity:1};});delete result.products;}dispatch(receiveProducts({products:result.items.map(function(_ref2){var product=_ref2.product;return product;}),fetchInventory:false}));dispatch(receiveFavorites(result.items,timestamp,takenListId));return _context.abrupt("return",result);case 20:_context.prev=20;_context.t0=_context["catch"](10);dispatch(errorFetchFavorites(_context.t0,takenListId));return _context.abrupt("return",null);case 24:case"end":return _context.stop();}},_callee,null,[[10,20]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}/** @mixes {MutableFunction} */export default mutable(fetchFavorites);
|
|
6
|
+
*/function fetchFavorites(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:undefined;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var defaultList,takenListId,hasMultiSupport,getFavoritesProductsByList,data,timestamp,pipelineVersion,request,result;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:// Fallback for deprecated calls without list id.
|
|
7
|
+
defaultList=getFavoritesDefaultList(getState());takenListId=listId||defaultList.code;hasMultiSupport=getHasMultipleFavoritesListsSupport(getState());getFavoritesProductsByList=makeGetFavoritesProductsByList(function(){return takenListId;});data=getFavoritesProductsByList(getState());if(!(!ignoreCache&&!shouldFetchData(data))){_context.next=7;break;}return _context.abrupt("return",null);case 7:timestamp=Date.now();dispatch(requestFavorites(takenListId));// v2 of the getFavorites pipeline doesn't exist right now within the old services
|
|
8
|
+
pipelineVersion=hasNewServices()?2:1;request=new PipelineRequest(SHOPGATE_USER_GET_FAVORITES).setVersion(pipelineVersion).setInput(_extends({},hasMultiSupport?{favoritesListId:takenListId}:null)).setErrorBlacklist([EFAVORITE,EUNKNOWN,EBIGAPI,ELIMIT]).dispatch();_context.prev=11;_context.next=14;return request;case 14:result=_context.sent;if(pipelineVersion===1){// Convert response data based on the pipeline version
|
|
9
|
+
result.items=((result===null||result===void 0?void 0:result.products)||[]).map(function(product){return{product:product,note:null,quantity:1};});delete result.products;}dispatch(receiveProducts({products:result.items.map(function(_ref2){var product=_ref2.product;return product;}),fetchInventory:false}));dispatch(receiveFavorites(result.items,timestamp,takenListId));return _context.abrupt("return",result);case 21:_context.prev=21;_context.t0=_context["catch"](11);dispatch(errorFetchFavorites(_context.t0,takenListId));return _context.abrupt("return",null);case 25:case"end":return _context.stop();}},_callee,null,[[11,21]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}/** @mixes {MutableFunction} */export default mutable(fetchFavorites);
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData}from'@shopgate/pwa-common/helpers/redux';import{SHOPGATE_USER_GET_FAVORITES_LIST}from"../constants/Pipelines";import{RECEIVE_FAVORITES_LISTS}from"../constants";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import{getFavoritesListState,getHasMultipleFavoritesListsSupport}from"../selectors";import{SHOPGATE_USER_GET_FAVORITES_LIST}from"../constants/Pipelines";import{RECEIVE_FAVORITES_LISTS}from"../constants";/**
|
|
2
2
|
* Fetch favorites list action.
|
|
3
3
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
4
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/function fetchFavoritesLists(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var data,_ref3,
|
|
5
|
+
*/function fetchFavoritesLists(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,hasMultiSupport,favoritesLists,data,_ref3,_favoritesLists;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:state=getState();hasMultiSupport=getHasMultipleFavoritesListsSupport(state);if(hasMultiSupport){_context.next=6;break;}/**
|
|
6
|
+
* If the doesn't have support for multiple favorite lists, we just mock the pipeline response
|
|
7
|
+
* and don't dispatch the request. So we can keep backwards compatibility with older
|
|
8
|
+
* extensions that don't support the pipeline.
|
|
9
|
+
*/favoritesLists=[{id:'DEFAULT',name:''}];dispatch({type:RECEIVE_FAVORITES_LISTS,favoritesLists:favoritesLists});return _context.abrupt("return",favoritesLists);case 6:data=getFavoritesListState(state);if(!(!ignoreCache&&!shouldFetchData(data))){_context.next=9;break;}return _context.abrupt("return",(data===null||data===void 0?void 0:data.lists)||[]);case 9:_context.prev=9;_context.next=12;return new PipelineRequest(SHOPGATE_USER_GET_FAVORITES_LIST).dispatch();case 12:_ref3=_context.sent;_favoritesLists=_ref3.favoritesLists;dispatch({type:RECEIVE_FAVORITES_LISTS,favoritesLists:_favoritesLists});return _context.abrupt("return",_favoritesLists);case 18:_context.prev=18;_context.t0=_context["catch"](9);return _context.abrupt("return",[]);case 21:case"end":return _context.stop();}},_callee,null,[[9,18]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}/** @mixes {MutableFunction} */export default mutable(fetchFavoritesLists);
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 fetchFavorites from"./fetchFavorites";import fetchFavoritesList from"./fetchFavoritesList";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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{getUseGetFavoriteIdsPipeline}from"../selectors";import fetchFavorites from"./fetchFavorites";import fetchFavoriteIds from"./fetchFavoriteIds";import fetchFavoritesList from"./fetchFavoritesList";/**
|
|
2
2
|
*
|
|
3
3
|
* Combine fetch favorites list action and fetch favorites action.
|
|
4
4
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
5
5
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/function fetchFavoritesListsWithItems(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var lists,itemPromises,wishlistItems;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.next=2;return dispatch(fetchFavoritesList(ignoreCache));case 2:_context.t0=_context.sent;if(_context.t0){_context.next=5;break;}_context.t0=[];case 5:lists=_context.t0;
|
|
6
|
+
*/function fetchFavoritesListsWithItems(){var ignoreCache=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var lists,useGetFavoriteIdsPipeline,itemPromises,wishlistItems;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:_context.next=2;return dispatch(fetchFavoritesList(ignoreCache));case 2:_context.t0=_context.sent;if(_context.t0){_context.next=5;break;}_context.t0=[];case 5:lists=_context.t0;useGetFavoriteIdsPipeline=getUseGetFavoriteIdsPipeline(getState());itemPromises=lists.map(function(list){/**
|
|
7
|
+
* In PWA6 the fetchFavoriteIds pipelines was used to retrieve the contents of the
|
|
8
|
+
* favorites list. Its response doesn't contain product objects, but only product ids.
|
|
9
|
+
* For compatibility reasons and simplification, the action returns an object that's similar
|
|
10
|
+
* to the fetchFavorites response, so that the existing reducers can be used.
|
|
11
|
+
*/if(useGetFavoriteIdsPipeline){return dispatch(fetchFavoriteIds(ignoreCache,list.id));}return dispatch(fetchFavorites(ignoreCache,list.id));});_context.next=10;return Promise.all(itemPromises);case 10:wishlistItems=_context.sent;return _context.abrupt("return",lists.map(function(_ref2,index){var id=_ref2.id,name=_ref2.name;return{id:id,name:name,itemCount:(wishlistItems[index]||{}).itemCount,items:(wishlistItems[index]||{}).items};}));case 12:case"end":return _context.stop();}},_callee);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default fetchFavoritesListsWithItems;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import{successRemoveFavorites,errorRemoveFavorites}from"../action-creators";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}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{mutable}from'@shopgate/pwa-common/helpers/redux';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import{successRemoveFavorites,errorRemoveFavorites}from"../action-creators";import{getHasMultipleFavoritesListsSupport,getFavoritesDefaultList}from"../selectors";/**
|
|
2
2
|
* Removes a single product from the favorite list using the `deleteFavorites` pipeline.
|
|
3
3
|
* @param {string} productId Id of the product to be deleted.
|
|
4
4
|
* @param {string} listId Id of the list to be deleted.
|
|
5
5
|
* @param {number} quantity Quantity of the favorite
|
|
6
6
|
* @param {string} notes Notes of the favorite
|
|
7
7
|
* @returns {Function} A redux thunk.
|
|
8
|
-
*/function removeFavorites(productId,listId,quantity,notes){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var
|
|
9
|
-
|
|
8
|
+
*/function removeFavorites(productId,listId,quantity,notes){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,hasMultiSupport,defaultList,takenListId,request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:state=getState();hasMultiSupport=getHasMultipleFavoritesListsSupport(state);// Fallback for deprecated calls without list id.
|
|
9
|
+
defaultList=getFavoritesDefaultList(state);takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_DELETE_FAVORITES).setInput(_extends({productId:productId},hasMultiSupport?{favoritesListId:takenListId}:null)).setRetries(0).dispatch();_context.prev=5;_context.next=8;return request;case 8:dispatch(successRemoveFavorites(productId,takenListId));_context.next=14;break;case 11:_context.prev=11;_context.t0=_context["catch"](5);dispatch(errorRemoveFavorites(productId,takenListId,_context.t0,quantity,notes));case 14:return _context.abrupt("return",request);case 15:case"end":return _context.stop();}},_callee,null,[[5,11]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default mutable(removeFavorites);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_REMOVE_FAVORITES_LIST}from"../constants/Pipelines";import{SUCCESS_REMOVE_FAVORITES_LIST}from"../constants";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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{mutable}from'@shopgate/pwa-common/helpers/redux';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_REMOVE_FAVORITES_LIST}from"../constants/Pipelines";import{SUCCESS_REMOVE_FAVORITES_LIST}from"../constants";/**
|
|
2
2
|
* Adds a new favorite list.
|
|
3
3
|
* @param {string} listId Id of the wishlist.
|
|
4
4
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/function removeFavoritesList(listId){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest(SHOPGATE_USER_REMOVE_FAVORITES_LIST).setInput({id:listId}).setRetries(0).dispatch();_context.prev=1;_context.next=4;return request;case 4:dispatch({type:SUCCESS_REMOVE_FAVORITES_LIST,listId:listId});_context.next=9;break;case 7:_context.prev=7;_context.t0=_context["catch"](1);case 9:case"end":return _context.stop();}},_callee,null,[[1,7]]);}));return function(_x){return _ref.apply(this,arguments);};}());}export default removeFavoritesList;
|
|
5
|
+
*/function removeFavoritesList(listId){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest(SHOPGATE_USER_REMOVE_FAVORITES_LIST).setInput({id:listId}).setRetries(0).dispatch();_context.prev=1;_context.next=4;return request;case 4:dispatch({type:SUCCESS_REMOVE_FAVORITES_LIST,listId:listId});_context.next=9;break;case 7:_context.prev=7;_context.t0=_context["catch"](1);case 9:case"end":return _context.stop();}},_callee,null,[[1,7]]);}));return function(_x){return _ref.apply(this,arguments);};}());}export default mutable(removeFavoritesList);
|
|
@@ -29,8 +29,8 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
|
|
|
29
29
|
* @param {string} listId List identifier.
|
|
30
30
|
* @param {boolean} withRelatives When true relatives which are on list are also removed.
|
|
31
31
|
* @return {Function}
|
|
32
|
-
*/export var toggleFavorite=function
|
|
33
|
-
var wishlistItemQuantityEnabled=getWishlistItemQuantityEnabled(state);var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(state);if(wishlistItemQuantityEnabled||!loadWishlistOnAppStartEnabled){dispatch(addFavorite(productId,listId));}else{var isOnList=makeIsProductOnSpecificFavoriteList(function(){return productId;},function(){return listId;})(state);dispatch(!isOnList?addFavorite(productId,listId):removeFavorites(productId,withRelatives,listId));}};};/**
|
|
32
|
+
*/export var toggleFavorite=mutable(function(productId,listId){var withRelatives=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;return function(dispatch,getState){var state=getState();// With quantity enabled the favorites button always adds (increases quantity)
|
|
33
|
+
var wishlistItemQuantityEnabled=getWishlistItemQuantityEnabled(state);var loadWishlistOnAppStartEnabled=getLoadWishlistOnAppStartEnabled(state);if(wishlistItemQuantityEnabled||!loadWishlistOnAppStartEnabled){dispatch(addFavorite(productId,listId));}else{var isOnList=makeIsProductOnSpecificFavoriteList(function(){return productId;},function(){return listId;})(state);dispatch(!isOnList?addFavorite(productId,listId):removeFavorites(productId,withRelatives,listId));}};});/**
|
|
34
34
|
* Updatest a product in the favorite list (debounced and buffered).
|
|
35
35
|
* @param {string} productId Product identifier.
|
|
36
36
|
* @param {string} listId List identifier.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import isNumber from'lodash/isNumber';import isString from'lodash/isString';import{SHOPGATE_USER_UPDATE_FAVORITES}from"../constants/Pipelines";import{errorUpdateFavorites,successUpdateFavorites}from"../action-creators";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}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{mutable}from'@shopgate/pwa-common/helpers/redux';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import isNumber from'lodash/isNumber';import isString from'lodash/isString';import{SHOPGATE_USER_UPDATE_FAVORITES}from"../constants/Pipelines";import{errorUpdateFavorites,successUpdateFavorites}from"../action-creators";import{getHasMultipleFavoritesListsSupport,getFavoritesDefaultList}from"../selectors";/**
|
|
2
2
|
* Updates a single product on the favorite list using the `updateFavorites` pipeline.
|
|
3
3
|
* @param {string} productId The id of the product.
|
|
4
4
|
* @param {string} listId Id of the list to be updated.
|
|
5
5
|
* @param {number} quantity New favorites quantity to set
|
|
6
6
|
* @param {string} notes ew favorites notes to set
|
|
7
7
|
* @returns {Function} A redux thunk.
|
|
8
|
-
*/function updateFavorites(productId){var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var quantity=arguments.length>2?arguments[2]:undefined;var notes=arguments.length>3?arguments[3]:undefined;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var
|
|
9
|
-
|
|
8
|
+
*/function updateFavorites(productId){var listId=arguments.length>1&&arguments[1]!==undefined?arguments[1]:null;var quantity=arguments.length>2?arguments[2]:undefined;var notes=arguments.length>3?arguments[3]:undefined;return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch,getState){var state,hasMultiSupport,defaultList,takenListId,request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:state=getState();hasMultiSupport=getHasMultipleFavoritesListsSupport(state);// Fallback for deprecated calls without list id.
|
|
9
|
+
defaultList=getFavoritesDefaultList(state);takenListId=listId||defaultList.id;request=new PipelineRequest(SHOPGATE_USER_UPDATE_FAVORITES).setInput(_extends({productId:productId},hasMultiSupport?{favoritesListId:takenListId}:null,{},isNumber(quantity)?{quantity:quantity}:{},{},isString(notes)?{notes:notes}:{})).setRetries(0).dispatch();_context.prev=5;_context.next=8;return request;case 8:dispatch(successUpdateFavorites(productId,takenListId));_context.next=14;break;case 11:_context.prev=11;_context.t0=_context["catch"](5);dispatch(errorUpdateFavorites(productId,_context.t0,takenListId));case 14:return _context.abrupt("return",request);case 15:case"end":return _context.stop();}},_callee,null,[[5,11]]);}));return function(_x,_x2){return _ref.apply(this,arguments);};}());}export default mutable(updateFavorites);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _regeneratorRuntime from"@babel/runtime/regenerator";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 PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_UPDATE_FAVORITES_LIST}from"../constants/Pipelines";import{SUCCESS_UPDATE_FAVORITES_LIST}from"../constants";/**
|
|
1
|
+
import _regeneratorRuntime from"@babel/runtime/regenerator";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{mutable}from'@shopgate/pwa-common/helpers/redux';import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{SHOPGATE_USER_UPDATE_FAVORITES_LIST}from"../constants/Pipelines";import{SUCCESS_UPDATE_FAVORITES_LIST}from"../constants";/**
|
|
2
2
|
* Adds a new favorite list.
|
|
3
3
|
* @param {string} listId Id of the wishlist.
|
|
4
4
|
* @param {string} name Name of the wishlist.
|
|
5
5
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/function updateFavoritesList(listId,name){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest(SHOPGATE_USER_UPDATE_FAVORITES_LIST).setInput({id:listId,name:name}).setRetries(0).dispatch();_context.prev=1;_context.next=4;return request;case 4:dispatch({type:SUCCESS_UPDATE_FAVORITES_LIST,listId:listId,name:name});_context.next=9;break;case 7:_context.prev=7;_context.t0=_context["catch"](1);case 9:case"end":return _context.stop();}},_callee,null,[[1,7]]);}));return function(_x){return _ref.apply(this,arguments);};}());}export default updateFavoritesList;
|
|
6
|
+
*/function updateFavoritesList(listId,name){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var request;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:request=new PipelineRequest(SHOPGATE_USER_UPDATE_FAVORITES_LIST).setInput({id:listId,name:name}).setRetries(0).dispatch();_context.prev=1;_context.next=4;return request;case 4:dispatch({type:SUCCESS_UPDATE_FAVORITES_LIST,listId:listId,name:name});_context.next=9;break;case 7:_context.prev=7;_context.t0=_context["catch"](1);case 9:case"end":return _context.stop();}},_callee,null,[[1,7]]);}));return function(_x){return _ref.apply(this,arguments);};}());}export default mutable(updateFavoritesList);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export var SHOPGATE_USER_GET_FAVORITES='shopgate.user.getFavorites';export var SHOPGATE_USER_ADD_FAVORITES='shopgate.user.addFavorites';export var SHOPGATE_USER_DELETE_FAVORITES='shopgate.user.deleteFavorites';export var SHOPGATE_USER_UPDATE_FAVORITES='shopgate.user.updateFavorites';export var SHOPGATE_USER_GET_FAVORITES_LIST='shopgate.user.getFavoritesLists';export var SHOPGATE_USER_ADD_FAVORITES_LIST='shopgate.user.addFavoritesList';export var SHOPGATE_USER_UPDATE_FAVORITES_LIST='shopgate.user.updateFavoritesList';export var SHOPGATE_USER_REMOVE_FAVORITES_LIST='shopgate.user.removeFavoritesList';
|
|
1
|
+
export var SHOPGATE_USER_GET_FAVORITES='shopgate.user.getFavorites';export var SHOPGATE_USER_GET_FAVORITE_IDS='shopgate.user.getFavoriteIds';export var SHOPGATE_USER_ADD_FAVORITES='shopgate.user.addFavorites';export var SHOPGATE_USER_DELETE_FAVORITES='shopgate.user.deleteFavorites';export var SHOPGATE_USER_UPDATE_FAVORITES='shopgate.user.updateFavorites';export var SHOPGATE_USER_GET_FAVORITES_LIST='shopgate.user.getFavoritesLists';export var SHOPGATE_USER_ADD_FAVORITES_LIST='shopgate.user.addFavoritesList';export var SHOPGATE_USER_UPDATE_FAVORITES_LIST='shopgate.user.updateFavoritesList';export var SHOPGATE_USER_REMOVE_FAVORITES_LIST='shopgate.user.removeFavoritesList';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{createSelector}from'reselect';import uniq from'lodash/uniq';import{getProducts,getProductId}from"../../product/selectors/product";import{getKnownRelatives}from"../../product/selectors/variants";var defaultIds=[];/**
|
|
1
|
+
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import{createSelector}from'reselect';import uniq from'lodash/uniq';import appConfig from'@shopgate/pwa-common/helpers/config';import{hasNewServices}from'@shopgate/engage/core/helpers';import{getProducts,getProductId}from"../../product/selectors/product";import{getKnownRelatives}from"../../product/selectors/variants";var defaultIds=[];/**
|
|
2
2
|
* @param {Object} state The global state.
|
|
3
3
|
* @return {Object}
|
|
4
4
|
*/export var getFavoritesState=function getFavoritesState(state){return state.favorites||{};};/**
|
|
@@ -11,7 +11,7 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
11
11
|
*/export var getFavoritesLists=function getFavoritesLists(state){var _getFavoritesListStat;return((_getFavoritesListStat=getFavoritesListState(state))===null||_getFavoritesListStat===void 0?void 0:_getFavoritesListStat.lists)||[];};/**
|
|
12
12
|
* @param {Object} state The global state.
|
|
13
13
|
* @return {Object|null}
|
|
14
|
-
*/export var getFavoritesProducts=createSelector(getFavoritesState,function(state){if(!state.products){return null;}return state.products;});export var getFavoritesDefaultList=createSelector(getFavoritesLists,function(lists){return
|
|
14
|
+
*/export var getFavoritesProducts=createSelector(getFavoritesState,function(state){if(!state.products){return null;}return state.products;});export var getFavoritesDefaultList=createSelector(getFavoritesLists,function(lists){var _lists$find;return(_lists$find=lists.find(function(list){return list.id==='DEFAULT';}))!==null&&_lists$find!==void 0?_lists$find:{id:'DEFAULT'};});export var hasMultipleFavoritesList=createSelector(getFavoritesLists,function(lists){return lists.length>1;});/**
|
|
15
15
|
* A selector that gets the id of the favorites list by the given name
|
|
16
16
|
* @param {Object} state The current application state.
|
|
17
17
|
* @param {Object} props The component props.
|
|
@@ -77,4 +77,19 @@ function _extends(){_extends=Object.assign||function(target){for(var i=1;i<argum
|
|
|
77
77
|
* @param {Object} state Current state.
|
|
78
78
|
* @param {string} productId Product id.
|
|
79
79
|
* @return {boolean}
|
|
80
|
-
*/export var isRelativeProductOnList=createSelector(getProductRelativesOnFavorites,function(relativesOnFavorites){return relativesOnFavorites.length>0;});export var getCommentDialogSettings=createSelector(getFavoritesListState,getFavoritesProducts,getProducts,function(_ref9,favItems,products){var _favItems$byList$list2,_products$item$produc2;var commentDialog=_ref9.commentDialog;var _ref10=commentDialog||{},listId=_ref10.listId,productId=_ref10.productId;if(!listId||!productId){return undefined;}var items=((_favItems$byList$list2=favItems.byList[listId])===null||_favItems$byList$list2===void 0?void 0:_favItems$byList$list2.items)||[];var item=items.find(function(_ref11){var itemProductId=_ref11.productId;return productId===itemProductId;});if(!item){return undefined;}return{listId:listId,productId:productId,item:item,product:(_products$item$produc2=products[item.productId])===null||_products$item$produc2===void 0?void 0:_products$item$produc2.productData};})
|
|
80
|
+
*/export var isRelativeProductOnList=createSelector(getProductRelativesOnFavorites,function(relativesOnFavorites){return relativesOnFavorites.length>0;});export var getCommentDialogSettings=createSelector(getFavoritesListState,getFavoritesProducts,getProducts,function(_ref9,favItems,products){var _favItems$byList$list2,_products$item$produc2;var commentDialog=_ref9.commentDialog;var _ref10=commentDialog||{},listId=_ref10.listId,productId=_ref10.productId;if(!listId||!productId){return undefined;}var items=((_favItems$byList$list2=favItems.byList[listId])===null||_favItems$byList$list2===void 0?void 0:_favItems$byList$list2.items)||[];var item=items.find(function(_ref11){var itemProductId=_ref11.productId;return productId===itemProductId;});if(!item){return undefined;}return{listId:listId,productId:productId,item:item,product:(_products$item$produc2=products[item.productId])===null||_products$item$produc2===void 0?void 0:_products$item$produc2.productData};});/**
|
|
81
|
+
* Creates a selector that selects all products that belong
|
|
82
|
+
* to the given favorite list.
|
|
83
|
+
* @param {Function} getListCode Callback that's supposed to return a favorites list code
|
|
84
|
+
* @returns {Function}
|
|
85
|
+
*/export var makeGetFavoritesProductsByList=function makeGetFavoritesProductsByList(getListCode){return createSelector(getFavoritesProducts,getListCode,function(favProducts,listId){var products=favProducts.byList[listId]||{};return products;});};/**
|
|
86
|
+
* Creates a selector to check if the app has support for multiple favorites list.
|
|
87
|
+
* @returns {Function}
|
|
88
|
+
*/export var getHasMultipleFavoritesListsSupport=function getHasMultipleFavoritesListsSupport(){var _appConfig$favoritesM;return hasNewServices()||(appConfig===null||appConfig===void 0?void 0:(_appConfig$favoritesM=appConfig.favoritesMode)===null||_appConfig$favoritesM===void 0?void 0:_appConfig$favoritesM.hasMultipleFavoritesLists);};/**
|
|
89
|
+
* Creates a selector the determine if the PWA is supposed to fetch favorite list entries via the
|
|
90
|
+
* "getFavoriteIds" pipeline instead of "getFavorites".
|
|
91
|
+
*
|
|
92
|
+
* This pipeline was introduced in PWA6 when support for more than 100 items per favorite list was
|
|
93
|
+
* requested. PWA-1877
|
|
94
|
+
* @returns {Function}
|
|
95
|
+
*/export var getUseGetFavoriteIdsPipeline=function getUseGetFavoriteIdsPipeline(){return!hasNewServices();};
|
|
@@ -1,9 +1,11 @@
|
|
|
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,makeGetFavoritesCountByList,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{makeGetRoutePattern}from'@shopgate/engage/core/selectors';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,makeGetFavoritesCountByList,makeGetProductRelativesOnFavorites,getFavoritesProducts,getUseGetFavoriteIdsPipeline}from"../selectors";import fetchFavoriteIds from"../actions/fetchFavoriteIds";/**
|
|
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
|
-
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
|
|
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&&makeGetRoutePattern()(getState())!==FAVORITES_PATH)){_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$favorites2=_appConfig$favorites===void 0?{}:_appConfig$favorites,_appConfig$favorites3=_appConfig$favorites2.limit,limit=_appConfig$favorites3===void 0?100:_appConfig$favorites3;var count=makeGetFavoritesCountByList(function(){return action===null||action===void 0?void 0:action.listId;})(state)
|
|
6
|
+
dispatch(cancelRequestSyncFavorites(0,action.listId));return;}var _appConfig$favorites=appConfig.favorites,_appConfig$favorites2=_appConfig$favorites===void 0?{}:_appConfig$favorites,_appConfig$favorites3=_appConfig$favorites2.limit,limit=_appConfig$favorites3===void 0?100:_appConfig$favorites3;var count=makeGetFavoritesCountByList(function(){return action===null||action===void 0?void 0:action.listId;})(state);// When the getFavorites pipeline is used to fetch favorites, the amount of items is limited
|
|
7
|
+
// since it returns full product entities. Hence adding more items needs to be prevented.
|
|
8
|
+
if(limit&&count>=limit&&!getUseGetFavoriteIdsPipeline(state)){// Dispatch a local error only, because the request to add is prevented
|
|
7
9
|
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,action.showToast));}});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
10
|
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
11
|
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
|
|
@@ -13,7 +15,7 @@ dispatch(idleSyncFavorites(action.listId));}});// Catch local limit errors (back
|
|
|
13
15
|
subscribe(errorFavoritesLimit$,function(_ref12){var dispatch=_ref12.dispatch;dispatch(showModal({confirm:null,dismiss:'modal.ok',title:'modal.title_error',message:'favorites.error_limit'}));});/**
|
|
14
16
|
* Request after N seconds since last add or remove request to make sure
|
|
15
17
|
* backend did actually save it
|
|
16
|
-
*/subscribe(refreshFavorites$,/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref13){var dispatch,action;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:dispatch=_ref13.dispatch,action=_ref13.action;if(!action.listId){_context4.next=
|
|
18
|
+
*/subscribe(refreshFavorites$,/*#__PURE__*/function(){var _ref14=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref13){var dispatch,action,getState,useGetFavoriteIdsPipeline;return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:dispatch=_ref13.dispatch,action=_ref13.action,getState=_ref13.getState;if(!action.listId){_context4.next=5;break;}useGetFavoriteIdsPipeline=getUseGetFavoriteIdsPipeline(getState());if(useGetFavoriteIdsPipeline){dispatch(fetchFavoriteIds(true,action.listId));}else{dispatch(fetchFavorites(true,action.listId));}return _context4.abrupt("return");case 5:_context4.next=7;return dispatch(fetchFavoritesListsWithItems(true));case 7:case"end":return _context4.stop();}},_callee4);}));return function(_x4){return _ref14.apply(this,arguments);};}());/**
|
|
17
19
|
* Takes an action buffer of the request-add, request-remove and request-update favorites actions
|
|
18
20
|
* and triggers Pipeline requests for all of them. Errors are handled autonomously.
|
|
19
21
|
* After all pipeline requests are done it resets the favorite page's state to "idle".
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _regeneratorRuntime from"@babel/runtime/regenerator";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{subscribe,invoke,getSubscriptionCount,resetSubscriptions}from'@shopgate/pwa-common/subscriptions/mock';import pipelineDependencies from'@shopgate/pwa-core/classes/PipelineDependencies';import showModal from'@shopgate/pwa-common/actions/modal/showModal';import{appDidStart$}from'@shopgate/pwa-common/streams';import{favoritesWillEnter$,shouldFetchFreshFavorites$,addProductToFavoritesDebounced$,removeProductFromFavoritesDebounced$,didReceiveFlushFavoritesBuffer$,errorFavoritesLimit$,refreshFavorites$,updateProductInFavoritesDebounced$}from"../streams";import favorites from"./index";import fetchFavorites from"../actions/fetchFavorites";import addFavorites from"../actions/addFavorites";import removeFavorites from"../actions/removeFavorites";import updateFavorites from"../actions/updateFavorites";import{FAVORITES_LIMIT_ERROR}from"../constants";import{SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES}from"../constants/Pipelines";import{addProductToFavorites,removeProductFromFavorites,requestAddFavorites,requestRemoveFavorites,cancelRequestSyncFavorites,errorFavorites,idleSyncFavorites,updateProductInFavorites,requestUpdateFavorites}from"../action-creators";import{getFavoritesProducts,getFavoritesCount,makeGetProductRelativesOnFavorites}from"../selectors";import fetchFavoritesListsWithItems from"../actions/fetchFavoritesListsWithItems";// Required for custom runner without env-setup
|
|
2
2
|
jest.mock('@shopgate/pwa-core',function(){});jest.mock('@shopgate/pwa-common/actions/modal/showModal',function(){return jest.fn().mockReturnValue('showModal');});jest.mock('@shopgate/pwa-common-commerce/product',function(){return{fetchProductsById:jest.fn()};});jest.mock('@shopgate/pwa-common/providers',function(){return{LoadingProvider:{setLoading:jest.fn(),unsetLoading:jest.fn()}};});var mockedDefaultListId='DEFAULT';jest.mock("../actions/fetchFavorites",function(){return jest.fn().mockReturnValue('fetchFavoritesResult');});jest.mock("../actions/fetchFavoritesList",function(){return jest.fn().mockResolvedValue([{id:'DEFAULT',name:'Wish List'}]);});jest.mock("../actions/fetchFavoritesListsWithItems",function(){var original=jest.requireActual('../actions/fetchFavoritesListsWithItems');return{__esModule:true,"default":jest.fn(original["default"])};});// Mock all used selectors to avoid mocking the store
|
|
3
|
-
var mockedGetFavoritesProductsIdsReturnValue;var mockedGetFavoritesCountReturnValue;var mockedGetFavoritesCountByListReturnValue;var mockedGetFavoritesProductsReturnValue;var mockedGetProductRelativesOnFavoritesReturnValue;var mockedMakeGetFavoritesReturnValue;var mockedMakeGetFavoritesCountByList=jest.fn(function(){return mockedGetFavoritesCountByListReturnValue||0;});jest.mock("../selectors",function(){return{getFavoritesProductsIds:jest.fn(function(){return mockedGetFavoritesProductsIdsReturnValue;}),getFavoritesProducts:jest.fn(function(){return mockedGetFavoritesProductsReturnValue;}),getFavoritesCount:jest.fn(function(){return mockedGetFavoritesCountReturnValue;}),makeGetFavoritesCountByList:jest.fn(function(){return mockedMakeGetFavoritesCountByList;}),makeGetFavorites:jest.fn(function(){return mockedMakeGetFavoritesReturnValue;}),makeGetProductRelativesOnFavorites:jest.fn(function(){return jest.fn().mockReturnValue(mockedGetProductRelativesOnFavoritesReturnValue);})};});jest.mock("../actions/addFavorites",function(){return jest.fn().mockReturnValue('addFavoritesResult');});jest.mock("../actions/removeFavorites",function(){return jest.fn().mockReturnValue('removeFavoritesResult');});jest.mock("../actions/updateFavorites",function(){return jest.fn().mockReturnValue('updateFavoritesResult');});var mockedHasFavorites=true;var mockedFavoritesLimit=100;jest.mock('@shopgate/pwa-common/helpers/config',function(){return{get hasFavorites(){return mockedHasFavorites;},get favorites(){return{limit:mockedFavoritesLimit};},get themeConfig(){return{};}};});/**
|
|
3
|
+
var mockedGetFavoritesProductsIdsReturnValue;var mockedGetFavoritesCountReturnValue;var mockedGetFavoritesCountByListReturnValue;var mockedGetFavoritesProductsReturnValue;var mockedGetProductRelativesOnFavoritesReturnValue;var mockedMakeGetFavoritesReturnValue;var mockedMakeGetFavoritesCountByList=jest.fn(function(){return mockedGetFavoritesCountByListReturnValue||0;});jest.mock("../selectors",function(){return{getFavoritesProductsIds:jest.fn(function(){return mockedGetFavoritesProductsIdsReturnValue;}),getFavoritesProducts:jest.fn(function(){return mockedGetFavoritesProductsReturnValue;}),getFavoritesCount:jest.fn(function(){return mockedGetFavoritesCountReturnValue;}),makeGetFavoritesCountByList:jest.fn(function(){return mockedMakeGetFavoritesCountByList;}),makeGetFavorites:jest.fn(function(){return mockedMakeGetFavoritesReturnValue;}),makeGetProductRelativesOnFavorites:jest.fn(function(){return jest.fn().mockReturnValue(mockedGetProductRelativesOnFavoritesReturnValue);}),getUseGetFavoriteIdsPipeline:jest.fn().mockReturnValue(false)};});jest.mock("../actions/addFavorites",function(){return jest.fn().mockReturnValue('addFavoritesResult');});jest.mock("../actions/removeFavorites",function(){return jest.fn().mockReturnValue('removeFavoritesResult');});jest.mock("../actions/updateFavorites",function(){return jest.fn().mockReturnValue('updateFavoritesResult');});var mockedHasFavorites=true;var mockedFavoritesLimit=100;jest.mock('@shopgate/pwa-common/helpers/config',function(){return{get hasFavorites(){return mockedHasFavorites;},get favorites(){return{limit:mockedFavoritesLimit};},get themeConfig(){return{};}};});/**
|
|
4
4
|
* Flushes the promise queue.
|
|
5
5
|
* @returns {Promise}
|
|
6
6
|
*/var flushPromises=function flushPromises(){return new Promise(function(resolve){return setImmediate(resolve);});};describe('Favorites - subscriptions',function(){describe('Favorites enabled',function(){var pipelineDependenciesSet=pipelineDependencies.set;beforeAll(function(){// Make sure no conflicting subscriptions exist
|
|
@@ -14,7 +14,7 @@ mockedGetFavoritesProductsIdsReturnValue=productIds;mockedGetFavoritesCountRetur
|
|
|
14
14
|
expect(pipelineDependencies.set).toHaveBeenCalledTimes(2);expect(pipelineDependencies.set.mock.calls[0][0]).toBe(SHOPGATE_USER_ADD_FAVORITES);expect(pipelineDependencies.set.mock.calls[0][1]).toEqual([SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);expect(pipelineDependencies.set.mock.calls[1][0]).toBe(SHOPGATE_USER_DELETE_FAVORITES);expect(pipelineDependencies.set.mock.calls[1][1]).toEqual([SHOPGATE_USER_ADD_FAVORITES,SHOPGATE_USER_DELETE_FAVORITES]);});it('should fetch favorites',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(){return _regeneratorRuntime.wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:_context2.next=2;return invoke(appDidStart$,{dispatch:dispatch,getState:getState});case 2:expect(fetchFavoritesListsWithItems).toHaveBeenCalledTimes(1);expect(fetchFavoritesListsWithItems).toHaveBeenCalledWith(false);expect(dispatch).toHaveBeenCalledTimes(3);case 5:case"end":return _context2.stop();}},_callee2);})));});describe('favoritesWillEnter$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(favoritesWillEnter$)).toBe(1);});it('should not return any value',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(){return _regeneratorRuntime.wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:_context3.t0=expect;_context3.next=3;return invoke(favoritesWillEnter$,{dispatch:dispatch,getState:getState});case 3:_context3.t1=_context3.sent;(0,_context3.t0)(_context3.t1).toBeUndefined();case 5:case"end":return _context3.stop();}},_callee3);})));it('should handle fetch and map favorites',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(){return _regeneratorRuntime.wrap(function _callee4$(_context4){while(1)switch(_context4.prev=_context4.next){case 0:_context4.next=2;return invoke(favoritesWillEnter$,{dispatch:dispatch,getState:getState});case 2:expect(fetchFavoritesListsWithItems).toHaveBeenCalledTimes(1);expect(fetchFavoritesListsWithItems).toHaveBeenCalledWith(true);expect(dispatch).toHaveBeenCalledTimes(3);case 5:case"end":return _context4.stop();}},_callee4);})));});describe('shouldFetchFreshFavorites$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(shouldFetchFreshFavorites$)).toBe(1);});it('should not return any value',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(){return _regeneratorRuntime.wrap(function _callee5$(_context5){while(1)switch(_context5.prev=_context5.next){case 0:_context5.next=2;return expect(invoke(shouldFetchFreshFavorites$,{dispatch:dispatch})).resolves.toBeUndefined();case 2:case"end":return _context5.stop();}},_callee5);})));it('should fetch fresh favorites without using the cache',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(){return _regeneratorRuntime.wrap(function _callee6$(_context6){while(1)switch(_context6.prev=_context6.next){case 0:_context6.next=2;return invoke(shouldFetchFreshFavorites$,{dispatch:dispatch,getState:getState});case 2:expect(fetchFavoritesListsWithItems).toHaveBeenCalledTimes(1);expect(fetchFavoritesListsWithItems).toHaveBeenCalledWith(true);expect(dispatch).toHaveBeenCalledTimes(3);case 5:case"end":return _context6.stop();}},_callee6);})));});describe('addProductToFavoritesDebounced$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(addProductToFavoritesDebounced$)).toBe(1);});it('should not return any value',function(){expect(invoke(addProductToFavoritesDebounced$,{action:addProductToFavorites('prod3'),dispatch:dispatch,getState:getState})).toBeUndefined();});it('should cancel the request when the product is already there',function(){invoke(addProductToFavoritesDebounced$,{action:addProductToFavorites('prod1',mockedDefaultListId),dispatch:dispatch,getState:getState});expect(getState).toHaveBeenCalledTimes(1);expect(getFavoritesProducts).toHaveBeenCalledWith(getState());expect(getFavoritesProducts).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(cancelRequestSyncFavorites(0,mockedDefaultListId));expect(dispatch).toHaveBeenCalledTimes(1);});it('should proceed and dispatch an error if the product is not yet on the list and the limit is reached',function(){var favoritesLimit=mockedFavoritesLimit;var productId='prod3';mockedFavoritesLimit=2;mockedGetFavoritesCountByListReturnValue=2;invoke(addProductToFavoritesDebounced$,{action:addProductToFavorites(productId,'DEFAULT'),dispatch:dispatch,getState:getState});expect(getState).toHaveBeenCalledTimes(1);expect(getFavoritesProducts).toHaveBeenCalledWith(getState());expect(getFavoritesProducts).toHaveBeenCalledTimes(1);expect(mockedMakeGetFavoritesCountByList).toHaveBeenCalledWith(getState());expect(mockedMakeGetFavoritesCountByList).toHaveBeenCalledTimes(1);expect(mockedMakeGetFavoritesCountByList).toHaveReturnedWith(mockedGetFavoritesCountByListReturnValue);var error=new Error('Limit exceeded');error.code=FAVORITES_LIMIT_ERROR;expect(dispatch).toHaveBeenCalledWith(errorFavorites(productId,error));expect(dispatch).toHaveBeenCalledTimes(1);mockedFavoritesLimit=favoritesLimit;});it('should proceed and dispatch an add request if all is good',function(){var productId='prod3';invoke(addProductToFavoritesDebounced$,{action:addProductToFavorites(productId),dispatch:dispatch,getState:getState});expect(getState).toHaveBeenCalledTimes(1);expect(getFavoritesProducts).toHaveBeenCalledWith(getState());expect(getFavoritesProducts).toHaveBeenCalledTimes(1);expect(mockedMakeGetFavoritesCountByList).toHaveBeenCalledWith(getState());expect(mockedMakeGetFavoritesCountByList).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(requestAddFavorites(productId));expect(dispatch).toHaveBeenCalledTimes(1);});});describe('updateProductInFavoritesDebounced$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(updateProductInFavoritesDebounced$)).toBe(1);});it('should not return any value',function(){expect(invoke(updateProductInFavoritesDebounced$,{action:updateProductInFavorites('prod3'),dispatch:dispatch,getState:getState})).toBeUndefined();});it('should proceed and dispatch an add request if all is good',function(){var productId='prod3';invoke(updateProductInFavoritesDebounced$,{action:updateProductInFavorites(productId),dispatch:dispatch,getState:getState});expect(dispatch).toHaveBeenCalledWith(requestUpdateFavorites(productId));expect(dispatch).toHaveBeenCalledTimes(1);});});describe('removeProductFromFavoritesDebounced$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(removeProductFromFavoritesDebounced$)).toBe(1);});it('should not return any value',function(){expect(invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites('prod1',true,mockedDefaultListId),dispatch:dispatch,getState:getState})).toBeUndefined();expect(invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites('prod1',false,mockedDefaultListId),dispatch:dispatch,getState:getState})).toBeUndefined();});it('should not do anything if no products are on the list and currently fetching',function(){mockedGetFavoritesCountReturnValue=0;mockedGetFavoritesProductsReturnValue.isFetching=true;invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites('prod1',false,mockedDefaultListId),dispatch:dispatch,getState:getState});expect(getFavoritesCount).toHaveBeenCalledTimes(1);expect(makeGetProductRelativesOnFavorites).toHaveBeenCalledTimes(0);expect(getFavoritesProducts).toHaveBeenCalledTimes(1);expect(getState).toHaveBeenCalledTimes(2);expect(dispatch).toHaveBeenCalledTimes(1);});it('should idle-sync when no products are on the list and not fetching',function(){mockedGetFavoritesCountReturnValue=0;invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites('prod1',false,mockedDefaultListId),dispatch:dispatch,getState:getState});expect(getFavoritesCount).toHaveBeenCalledTimes(1);expect(makeGetProductRelativesOnFavorites).toHaveBeenCalledTimes(0);expect(getFavoritesProducts).toHaveBeenCalledTimes(1);expect(getState).toHaveBeenCalledTimes(2);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(idleSyncFavorites(mockedDefaultListId));});it('should dispatch a remove request for each relative',function(){var productId='prod0';var mock=jest.fn(function(){return productIds;});makeGetProductRelativesOnFavorites.mockReturnValueOnce(mock);invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites(productId,true,mockedDefaultListId),dispatch:dispatch,getState:getState});// Expect multiple remove requests to be dispatched
|
|
15
15
|
expect(makeGetProductRelativesOnFavorites).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledTimes(4);expect(dispatch.mock.calls[1][0]).toEqual(requestRemoveFavorites(productIds[0],mockedDefaultListId)(dispatch,getState));expect(dispatch.mock.calls[3][0]).toEqual(requestRemoveFavorites(productIds[1],mockedDefaultListId)(dispatch,getState));});it('should cancel the remove request if the product is not on the list',function(){var productId='prod0';mockedGetProductRelativesOnFavoritesReturnValue=productIds;invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites(productId,false,mockedDefaultListId),dispatch:dispatch,getState:getState});// Don't expect any remove requests to be triggered
|
|
16
16
|
expect(makeGetProductRelativesOnFavorites).toHaveBeenCalledTimes(0);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(cancelRequestSyncFavorites(0,mockedDefaultListId));});it('should request the removal of the single favorite item',function(){var productId='prod0';mockedGetFavoritesProductsReturnValue={byList:{DEFAULT:{items:[].concat(mockedGetFavoritesProductsReturnValue.byList.DEFAULT.items,[{productId:productId,quantity:1,notes:null}])}}};var mock=jest.fn(function(){return productIds;});makeGetProductRelativesOnFavorites.mockReturnValueOnce(mock);invoke(removeProductFromFavoritesDebounced$,{action:removeProductFromFavorites(productId,false,mockedDefaultListId),dispatch:dispatch,getState:getState});// Only one removal request is expected
|
|
17
|
-
expect(makeGetProductRelativesOnFavorites).toHaveBeenCalledTimes(0);expect(dispatch).toHaveBeenCalledTimes(2);expect(dispatch.mock.calls[1][0]).toEqual(requestRemoveFavorites(productId,mockedDefaultListId)(dispatch,getState));});});describe('errorFavoritesLimit$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(errorFavoritesLimit$)).toBe(1);});it('should not return any value',function(){expect(invoke(errorFavoritesLimit$,{dispatch:dispatch})).toBeUndefined();});it('should dispatch an action to show a modal',function(){invoke(errorFavoritesLimit$,{dispatch:dispatch});expect(showModal).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(showModal({confirm:null,dismiss:'modal.ok',title:'modal.title_error',message:'favorites.error_limit'}));});});describe('refreshFavorites$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(refreshFavorites$)).toBe(1);});it('should not return any value',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1)switch(_context7.prev=_context7.next){case 0:_context7.next=2;return expect(invoke(refreshFavorites$,{dispatch:dispatch,action:{listId:mockedDefaultListId}})).resolves.toBeUndefined();case 2:case"end":return _context7.stop();}},_callee7);})));it('should refresh favorites by fetching them without using the cache',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1)switch(_context8.prev=_context8.next){case 0:_context8.next=2;return invoke(refreshFavorites$,{dispatch:dispatch,action:{listId:mockedDefaultListId}});case 2:expect(fetchFavorites).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(fetchFavorites(true));case 5:case"end":return _context8.stop();}},_callee8);})));});describe('didReceiveFlushFavoritesBuffer$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(didReceiveFlushFavoritesBuffer$)).toBe(1);});it('should not return any value',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(){var productId;return _regeneratorRuntime.wrap(function _callee9$(_context9){while(1)switch(_context9.prev=_context9.next){case 0:productId='prod1';_context9.t0=expect;_context9.next=4;return invoke(didReceiveFlushFavoritesBuffer$,null);case 4:_context9.t1=_context9.sent;(0,_context9.t0)(_context9.t1).toBeUndefined();_context9.t2=expect;_context9.next=9;return invoke(didReceiveFlushFavoritesBuffer$,[]);case 9:_context9.t3=_context9.sent;(0,_context9.t2)(_context9.t3).toBeUndefined();_context9.t4=expect;_context9.next=14;return invoke(didReceiveFlushFavoritesBuffer$,[{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState}]);case 14:_context9.t5=_context9.sent;(0,_context9.t4)(_context9.t5).toBeUndefined();_context9.t6=expect;_context9.next=19;return invoke(didReceiveFlushFavoritesBuffer$,[{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState},{action:requestUpdateFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState},{action:requestRemoveFavorites(productId,mockedDefaultListId)(dispatch,getState),dispatch:dispatch,getState:getState}]);case 19:_context9.t7=_context9.sent;(0,_context9.t6)(_context9.t7).toBeUndefined();case 21:case"end":return _context9.stop();}},_callee9);})));it('should cancel all redundant requests',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(){var productId;return _regeneratorRuntime.wrap(function _callee10$(_context10){while(1)switch(_context10.prev=_context10.next){case 0:productId='prod1';// Add and remove the same product to make both redundant
|
|
17
|
+
expect(makeGetProductRelativesOnFavorites).toHaveBeenCalledTimes(0);expect(dispatch).toHaveBeenCalledTimes(2);expect(dispatch.mock.calls[1][0]).toEqual(requestRemoveFavorites(productId,mockedDefaultListId)(dispatch,getState));});});describe('errorFavoritesLimit$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(errorFavoritesLimit$)).toBe(1);});it('should not return any value',function(){expect(invoke(errorFavoritesLimit$,{dispatch:dispatch})).toBeUndefined();});it('should dispatch an action to show a modal',function(){invoke(errorFavoritesLimit$,{dispatch:dispatch});expect(showModal).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(showModal({confirm:null,dismiss:'modal.ok',title:'modal.title_error',message:'favorites.error_limit'}));});});describe('refreshFavorites$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(refreshFavorites$)).toBe(1);});it('should not return any value',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(){return _regeneratorRuntime.wrap(function _callee7$(_context7){while(1)switch(_context7.prev=_context7.next){case 0:_context7.next=2;return expect(invoke(refreshFavorites$,{dispatch:dispatch,action:{listId:mockedDefaultListId},getState:getState})).resolves.toBeUndefined();case 2:case"end":return _context7.stop();}},_callee7);})));it('should refresh favorites by fetching them without using the cache',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee8(){return _regeneratorRuntime.wrap(function _callee8$(_context8){while(1)switch(_context8.prev=_context8.next){case 0:_context8.next=2;return invoke(refreshFavorites$,{dispatch:dispatch,action:{listId:mockedDefaultListId},getState:getState});case 2:expect(fetchFavorites).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledTimes(1);expect(dispatch).toHaveBeenCalledWith(fetchFavorites(true));case 5:case"end":return _context8.stop();}},_callee8);})));});describe('didReceiveFlushFavoritesBuffer$',function(){it('should subscribe to the stream',function(){expect(getSubscriptionCount(didReceiveFlushFavoritesBuffer$)).toBe(1);});it('should not return any value',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee9(){var productId;return _regeneratorRuntime.wrap(function _callee9$(_context9){while(1)switch(_context9.prev=_context9.next){case 0:productId='prod1';_context9.t0=expect;_context9.next=4;return invoke(didReceiveFlushFavoritesBuffer$,null);case 4:_context9.t1=_context9.sent;(0,_context9.t0)(_context9.t1).toBeUndefined();_context9.t2=expect;_context9.next=9;return invoke(didReceiveFlushFavoritesBuffer$,[]);case 9:_context9.t3=_context9.sent;(0,_context9.t2)(_context9.t3).toBeUndefined();_context9.t4=expect;_context9.next=14;return invoke(didReceiveFlushFavoritesBuffer$,[{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState}]);case 14:_context9.t5=_context9.sent;(0,_context9.t4)(_context9.t5).toBeUndefined();_context9.t6=expect;_context9.next=19;return invoke(didReceiveFlushFavoritesBuffer$,[{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState},{action:requestUpdateFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState},{action:requestRemoveFavorites(productId,mockedDefaultListId)(dispatch,getState),dispatch:dispatch,getState:getState}]);case 19:_context9.t7=_context9.sent;(0,_context9.t6)(_context9.t7).toBeUndefined();case 21:case"end":return _context9.stop();}},_callee9);})));it('should cancel all redundant requests',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee10(){var productId;return _regeneratorRuntime.wrap(function _callee10$(_context10){while(1)switch(_context10.prev=_context10.next){case 0:productId='prod1';// Add and remove the same product to make both redundant
|
|
18
18
|
_context10.next=3;return invoke(didReceiveFlushFavoritesBuffer$,[{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState},{action:requestRemoveFavorites(productId,mockedDefaultListId)(dispatch,getState),dispatch:dispatch,getState:getState}]);case 3:expect(dispatch).toHaveBeenCalledTimes(2);expect(dispatch).toHaveBeenCalledWith(cancelRequestSyncFavorites(2,mockedDefaultListId));case 5:case"end":return _context10.stop();}},_callee10);})));it('should filter out duplicated add requests',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee11(){var productId;return _regeneratorRuntime.wrap(function _callee11$(_context11){while(1)switch(_context11.prev=_context11.next){case 0:productId='prod1';// Add the same product twice
|
|
19
19
|
_context11.next=3;return invoke(didReceiveFlushFavoritesBuffer$,[{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState},{action:requestAddFavorites(productId,mockedDefaultListId),dispatch:dispatch,getState:getState}]);case 3:_context11.next=5;return flushPromises();case 5:// One cancel and one add action call as well as one idle-sync afterwards
|
|
20
20
|
expect(addFavorites).toHaveBeenCalledTimes(1);expect(addFavorites.mock.calls[0][0]).toBe(productId);expect(dispatch).toHaveBeenCalledTimes(2);expect(dispatch.mock.calls[0][0]).toEqual(addFavorites());expect(dispatch.mock.calls[1][0]).toEqual(idleSyncFavorites(mockedDefaultListId));case 10:case"end":return _context11.stop();}},_callee11);})));it('should filter out duplicated remove requests',/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee12(){var productId;return _regeneratorRuntime.wrap(function _callee12$(_context12){while(1)switch(_context12.prev=_context12.next){case 0:productId='prod1';// Remove the same product twice
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopgate/pwa-common-commerce",
|
|
3
|
-
"version": "7.20.0-beta.
|
|
3
|
+
"version": "7.20.0-beta.4",
|
|
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.20.0-beta.
|
|
23
|
-
"@shopgate/pwa-core": "7.20.0-beta.
|
|
22
|
+
"@shopgate/pwa-common": "7.20.0-beta.4",
|
|
23
|
+
"@shopgate/pwa-core": "7.20.0-beta.4",
|
|
24
24
|
"lodash": "^4.17.4",
|
|
25
25
|
"react": "~16.12.0",
|
|
26
26
|
"react-dom": "~16.12.0"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import requestProductImages from"../action-creators/requestProductImages";import{SHOPGATE_CATALOG_GET_PRODUCT_IMAGES}from"../constants/Pipelines";import receiveProductImages from"../action-creators/receiveProductImages";import errorProductImages from"../action-creators/errorProductImages";import{getProductImagesState}from
|
|
1
|
+
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';import{shouldFetchData,mutable}from'@shopgate/pwa-common/helpers/redux';import requestProductImages from"../action-creators/requestProductImages";import{SHOPGATE_CATALOG_GET_PRODUCT_IMAGES}from"../constants/Pipelines";import receiveProductImages from"../action-creators/receiveProductImages";import errorProductImages from"../action-creators/errorProductImages";import{getProductImagesState}from"../selectors/product";/**
|
|
2
2
|
* Maybe requests images for a product from server.
|
|
3
3
|
* @param {string} productId The product ID.
|
|
4
4
|
* @return {Function} The dispatched action.
|