@shopgate/pwa-common
Version:
Common library for the Shopgate Connect PWA.
14 lines • 5.5 kB
JavaScript
import _regeneratorRuntime from"@babel/runtime/regenerator";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 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);});};}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,{Component}from'react';import PropTypes from'prop-types';import{Provider}from'react-redux';import{CookiesProvider}from'react-cookie';import{loadCustomStyles}from'@shopgate/engage/styles';import ErrorBoundary from"./components/ErrorBoundary";import{appDidStart}from"./action-creators/app";import I18n from"./components/I18n";import{getIsSessionExpired}from"./selectors/user";import logout from"./actions/user/logout";/**
* The application component.
* It sets up the store and the react router. The router's children (routes) come from
* the theme's Main.jsx file which uses this component as the root element.
* @returns {JSX}
*/var App=/*#__PURE__*/function(_Component){function App(){_classCallCheck(this,App);return _callSuper(this,App,arguments);}_inherits(App,_Component);return _createClass(App,[{key:"componentDidMount",value:/**
* Registers the component for the native events and fires the onload AppCommand.
*/function componentDidMount(){var _this2=this;/**
* Async helper function that performs optional steps before appDidStart action is dispatched
*/var performAppStart=/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(){return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:if(!getIsSessionExpired(_this2.props.store.getState())){_context.next=9;break;}_context.prev=1;_context.next=4;return _this2.props.store.dispatch(logout(undefined,true));case 4:_context.next=9;break;case 6:_context.prev=6;_context.t0=_context["catch"](1);// Noting to do here
console.error('AppStartLogout failed',_context.t0);case 9:_this2.props.store.dispatch(appDidStart("".concat(window.location.pathname).concat(window.location.search)));case 10:case"end":return _context.stop();}},_callee,null,[[1,6]]);}));return function performAppStart(){return _ref.apply(this,arguments);};}();performAppStart();loadCustomStyles();}/**
* Renders the component.
* @returns {JSX}
*/},{key:"render",value:function render(){return React.createElement(CookiesProvider,null,React.createElement(ErrorBoundary,{key:"error.root",store:this.props.store,isRoot:true},React.createElement(Provider,{store:this.props.store},React.createElement(I18n.Provider,null,React.createElement("div",null,this.props.children)))));}}]);}(Component);export default App;