@shopgate/engage
Version:
Shopgate's ENGAGE library.
52 lines (49 loc) • 1.68 kB
JavaScript
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import "core-js/modules/es.string.replace.js";
import React from 'react';
import PropTypes from 'prop-types';
import { UIEvents } from '@shopgate/pwa-core';
import { NAVIGATION_PUSH, NAVIGATION_POP, NAVIGATION_REPLACE, NAVIGATION_RESET } from "../../core/router/helpers";
import connect from "./connector";
/**
* Handles
*/
let NavigationHandler = /*#__PURE__*/function (_React$PureComponent) {
/**
* @param {Object} props The component props.
*/
function NavigationHandler(props) {
var _this;
_this = _React$PureComponent.call(this, props) || this;
UIEvents.addListener(NAVIGATION_PUSH, props.push);
UIEvents.addListener(NAVIGATION_POP, props.pop);
UIEvents.addListener(NAVIGATION_REPLACE, props.replace);
UIEvents.addListener(NAVIGATION_RESET, props.reset);
return _this;
}
/**
* Removes the event listeners.
*/
_inheritsLoose(NavigationHandler, _React$PureComponent);
var _proto = NavigationHandler.prototype;
_proto.componentWillUnmount = function componentWillUnmount() {
UIEvents.removeListener(NAVIGATION_PUSH, this.props.push);
UIEvents.removeListener(NAVIGATION_POP, this.props.pop);
UIEvents.removeListener(NAVIGATION_REPLACE, this.props.replace);
UIEvents.removeListener(NAVIGATION_RESET, this.props.reset);
}
/**
* @returns {null}
*/;
_proto.render = function render() {
return this.props.children;
};
return NavigationHandler;
}(React.PureComponent);
NavigationHandler.defaultProps = {
pop: () => {},
push: () => {},
replace: () => {},
reset: () => {}
};
export default connect(NavigationHandler);