Merge pull request #860 from HaNdTriX/overlay

Fix Overlay Memory Leak
old
Javi Velasco 2016-10-12 16:46:32 +02:00 committed by GitHub
commit 60ca599fe8
2 changed files with 22 additions and 23 deletions

View File

@ -26,7 +26,7 @@ class Overlay extends Component {
componentDidMount () {
if (this.props.active) {
this.escKeyListener = document.body.addEventListener('keydown', this.handleEscKey.bind(this));
document.body.addEventListener('keydown', this.handleEscKey);
document.body.style.overflow = 'hidden';
}
}
@ -37,20 +37,17 @@ class Overlay extends Component {
}
componentDidUpdate () {
if (this.props.active && !this.escKeyListener) {
this.escKeyListener = document.body.addEventListener('keydown', this.handleEscKey.bind(this));
if (this.props.active) {
document.body.addEventListener('keydown', this.handleEscKey);
}
}
componentWillUnmount () {
if (!document.querySelectorAll('[data-react-toolbox="overlay"]')[1]) document.body.style.overflow = '';
if (this.escKeyListener) {
document.body.removeEventListener('keydown', this.handleEscKey);
this.escKeyListener = null;
}
document.body.removeEventListener('keydown', this.handleEscKey);
}
handleEscKey (e) {
handleEscKey = (e) => {
if (this.props.active && this.props.onEscKeyDown && e.which === 27) {
this.props.onEscKeyDown(e);
}

View File

@ -37,16 +37,28 @@ var Overlay = function (_Component) {
_inherits(Overlay, _Component);
function Overlay() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Overlay);
return _possibleConstructorReturn(this, (Overlay.__proto__ || Object.getPrototypeOf(Overlay)).apply(this, arguments));
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Overlay.__proto__ || Object.getPrototypeOf(Overlay)).call.apply(_ref, [this].concat(args))), _this), _this.handleEscKey = function (e) {
if (_this.props.active && _this.props.onEscKeyDown && e.which === 27) {
_this.props.onEscKeyDown(e);
}
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Overlay, [{
key: 'componentDidMount',
value: function componentDidMount() {
if (this.props.active) {
this.escKeyListener = document.body.addEventListener('keydown', this.handleEscKey.bind(this));
document.body.addEventListener('keydown', this.handleEscKey);
document.body.style.overflow = 'hidden';
}
}
@ -59,25 +71,15 @@ var Overlay = function (_Component) {
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
if (this.props.active && !this.escKeyListener) {
this.escKeyListener = document.body.addEventListener('keydown', this.handleEscKey.bind(this));
if (this.props.active) {
document.body.addEventListener('keydown', this.handleEscKey);
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (!document.querySelectorAll('[data-react-toolbox="overlay"]')[1]) document.body.style.overflow = '';
if (this.escKeyListener) {
document.body.removeEventListener('keydown', this.handleEscKey);
this.escKeyListener = null;
}
}
}, {
key: 'handleEscKey',
value: function handleEscKey(e) {
if (this.props.active && this.props.onEscKeyDown && e.which === 27) {
this.props.onEscKeyDown(e);
}
document.body.removeEventListener('keydown', this.handleEscKey);
}
}, {
key: 'render',