@shopgate/engage
Version:
Shopgate's ENGAGE library.
22 lines • 4.79 kB
JavaScript
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function");}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor);}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor;}function _callSuper(_this,derived,args){function isNativeReflectConstruct(){if(typeof Reflect==="undefined"||!Reflect.construct)return false;if(Reflect.construct.sham)return false;if(typeof Proxy==="function")return true;try{return!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(e){return false;}}derived=_getPrototypeOf(derived);return _possibleConstructorReturn(_this,isNativeReflectConstruct()?Reflect.construct(derived,args||[],_getPrototypeOf(_this).constructor):derived.apply(_this,args));}function _possibleConstructorReturn(self,call){if(call&&(_typeof(call)==="object"||typeof call==="function")){return call;}return _assertThisInitialized(self);}function _assertThisInitialized(self){if(self===void 0){throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return self;}function _getPrototypeOf(o){_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function _getPrototypeOf(o){return o.__proto__||Object.getPrototypeOf(o);};return _getPrototypeOf(o);}function _inherits(subClass,superClass){if(typeof superClass!=="function"&&superClass!==null){throw new TypeError("Super expression must either be null or a function");}subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:true,configurable:true}});if(superClass)_setPrototypeOf(subClass,superClass);}function _setPrototypeOf(o,p){_setPrototypeOf=Object.setPrototypeOf||function _setPrototypeOf(o,p){o.__proto__=p;return o;};return _setPrototypeOf(o,p);}import React from'react';import PropTypes from'prop-types';import{CART_ITEM_TYPE_PRODUCT}from'@shopgate/engage/cart';import{useCartItemProduct}from"./CartItem.hooks";/**
* Provides legacy context for CartItemProduct component and its children.
* Within PWA7 the context was refactored to the new context API. To keep compatibility with
* older extensions, this provider is used to provide the legacy context.
*
* Should be removed when PWA 7 is deployed to all of the shops and affected extensions can be
* updated without the need to support older PWA versions.
*/var LegacyProvider=/*#__PURE__*/function(_React$Component){/**
* @param {Object} props The component props.
*/function LegacyProvider(props){var _this2;_classCallCheck(this,LegacyProvider);_this2=_callSuper(this,LegacyProvider,[props]);_this2.state={cartItemId:props.cartItemId,product:props.product};return _this2;}/**
* @param {Object} nextProps Next props
* @param {*} prevState Prev state
* @returns {Object|null}
*/_inherits(LegacyProvider,_React$Component);return _createClass(LegacyProvider,[{key:"getChildContext",value:/**
* @returns {Object}
*/function getChildContext(){return{type:CART_ITEM_TYPE_PRODUCT,cartItemId:this.state.cartItemId,product:this.state.product};}/**
* @returns {JSX.Element}
*/},{key:"render",value:function render(){return this.props.children;}}],[{key:"getDerivedStateFromProps",value:function getDerivedStateFromProps(nextProps,prevState){if(nextProps.cartItemId!==prevState.cartItemId||nextProps.product!==prevState.product){return{cartItemId:nextProps.cartItemId,product:nextProps.product};}return null;}}]);}(React.Component);LegacyProvider.childContextTypes={type:PropTypes.string,cartItemId:PropTypes.string,product:PropTypes.shape()};/**
* Bridges the CartItemProductContext value to the legacy CartItemProduct context.
* @param {Object} props The component props.
* @returns {JSX.Element}
*/var CartItemProductProviderLegacy=function CartItemProductProviderLegacy(_ref){var children=_ref.children;var _useCartItemProduct=useCartItemProduct(),cartItemId=_useCartItemProduct.cartItemId,product=_useCartItemProduct.product;return React.createElement(LegacyProvider,{cartItemId:cartItemId,product:product},children);};export default CartItemProductProviderLegacy;