UNPKG

@elastic/eui

Version:

Elastic UI Component Library

61 lines (60 loc) 2.45 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import { Component } from 'react'; export var EuiWindowEvent = /*#__PURE__*/function (_Component) { function EuiWindowEvent() { _classCallCheck(this, EuiWindowEvent); return _callSuper(this, EuiWindowEvent, arguments); } _inherits(EuiWindowEvent, _Component); return _createClass(EuiWindowEvent, [{ key: "componentDidMount", value: function componentDidMount() { this.addEvent(this.props); } }, { key: "componentDidUpdate", value: function componentDidUpdate(prevProps) { if (prevProps.event !== this.props.event || prevProps.handler !== this.props.handler) { this.removeEvent(prevProps); this.addEvent(this.props); } } }, { key: "componentWillUnmount", value: function componentWillUnmount() { this.removeEvent(this.props); } }, { key: "addEvent", value: function addEvent(_ref) { var event = _ref.event, handler = _ref.handler; window.addEventListener(event, handler); } }, { key: "removeEvent", value: function removeEvent(_ref2) { var event = _ref2.event, handler = _ref2.handler; window.removeEventListener(event, handler); } }, { key: "render", value: function render() { return null; } }]); }(Component);