Set our own booleans instead of using isMounted

pull/21833/head
Richard van der Hoff 2016-01-11 11:38:04 +00:00
parent 62cf34b58c
commit c30aeac315
2 changed files with 19 additions and 5 deletions

View File

@ -100,6 +100,12 @@ module.exports = React.createClass({
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
// set a boolean to say we've been unmounted, which any pending
// promises can use to throw away their results.
//
// (We could use isMounted, but facebook have deprecated that.)
this.unmounted = true;
if (this.refs.messagePanel) { if (this.refs.messagePanel) {
// disconnect the D&D event listeners from the message panel. This // disconnect the D&D event listeners from the message panel. This
// is really just for hygiene - the messagePanel is going to be // is really just for hygiene - the messagePanel is going to be
@ -196,7 +202,7 @@ module.exports = React.createClass({
},*/ },*/
onRoomTimeline: function(ev, room, toStartOfTimeline) { onRoomTimeline: function(ev, room, toStartOfTimeline) {
if (!this.isMounted()) return; if (this.unmounted) return;
// ignore anything that comes in whilst paginating: we get one // ignore anything that comes in whilst paginating: we get one
// event for each new matrix event so this would cause a huge // event for each new matrix event so this would cause a huge
@ -355,7 +361,7 @@ module.exports = React.createClass({
// we might have switched rooms since the paginate started - just bin // we might have switched rooms since the paginate started - just bin
// the results if so. // the results if so.
if (!this.isMounted()) return; if (this.unmounted) return;
this.setState({ this.setState({
room: MatrixClientPeg.get().getRoom(this.props.roomId), room: MatrixClientPeg.get().getRoom(this.props.roomId),
@ -538,7 +544,7 @@ module.exports = React.createClass({
return searchPromise.then(function(results) { return searchPromise.then(function(results) {
debuglog("search complete"); debuglog("search complete");
if (!this.isMounted() || !self.state.searching || self.searchId != localSearchId) { if (self.unmounted || !self.state.searching || self.searchId != localSearchId) {
console.error("Discarding stale search results"); console.error("Discarding stale search results");
return; return;
} }

View File

@ -112,6 +112,14 @@ module.exports = React.createClass({
this.checkFillState(); this.checkFillState();
}, },
componentWillUnmount: function() {
// set a boolean to say we've been unmounted, which any pending
// promises can use to throw away their results.
//
// (We could use isMounted(), but facebook have deprecated that.)
this.unmounted = true;
},
onScroll: function(ev) { onScroll: function(ev) {
var sn = this._getScrollNode(); var sn = this._getScrollNode();
debuglog("Scroll event: offset now:", sn.scrollTop, "recentEventScroll:", this.recentEventScroll); debuglog("Scroll event: offset now:", sn.scrollTop, "recentEventScroll:", this.recentEventScroll);
@ -158,7 +166,7 @@ module.exports = React.createClass({
// check the scroll state and send out backfill requests if necessary. // check the scroll state and send out backfill requests if necessary.
checkFillState: function() { checkFillState: function() {
if (!this.isMounted()) { if (this.unmounted) {
return; return;
} }
@ -350,7 +358,7 @@ module.exports = React.createClass({
* message panel. * message panel.
*/ */
_getScrollNode: function() { _getScrollNode: function() {
if (!this.isMounted()) { if (this.unmounted) {
// this shouldn't happen, but when it does, turn the NPE into // this shouldn't happen, but when it does, turn the NPE into
// something more meaningful. // something more meaningful.
throw new Error("ScrollPanel._getScrollNode called when unmounted"); throw new Error("ScrollPanel._getScrollNode called when unmounted");