@elastic/eui
Version:
Elastic UI Component Library
69 lines (67 loc) • 2.91 kB
JavaScript
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";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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 EuiObserver = /*#__PURE__*/function (_Component) {
function EuiObserver() {
var _this;
_classCallCheck(this, EuiObserver);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _callSuper(this, EuiObserver, [].concat(args));
_defineProperty(_this, "name", 'EuiObserver');
_defineProperty(_this, "childNode", null);
_defineProperty(_this, "observer", null);
_defineProperty(_this, "updateChildNode", function (ref) {
if (_this.childNode === ref) return; // node hasn't changed
// if there's an existing observer disconnect it
if (_this.observer != null) {
_this.observer.disconnect();
_this.observer = null;
}
_this.childNode = ref;
if (_this.childNode != null) {
_this.beginObserve();
}
});
_defineProperty(_this, "beginObserve", function () {
throw new Error('EuiObserver has no default observation method');
});
return _this;
}
_inherits(EuiObserver, _Component);
return _createClass(EuiObserver, [{
key: "componentDidMount",
value: function componentDidMount() {
if (this.childNode == null) {
throw new Error("".concat(this.name, " did not receive a ref"));
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
if (this.observer != null) {
this.observer.disconnect();
}
}
}, {
key: "render",
value: function render() {
var props = this.props;
return props.children(this.updateChildNode);
}
}]);
}(Component);