mirror of https://github.com/vector-im/riot-web
Cancel calls to rate-limited funcs on unmount
The tests were throwing up warnings about state being accessed, and null MatrixClients being called, after component unmount.pull/21833/head
parent
6aa5e5a493
commit
8fe470bce1
|
@ -273,6 +273,9 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
window.removeEventListener('resize', this.onResize);
|
window.removeEventListener('resize', this.onResize);
|
||||||
|
|
||||||
|
// cancel any pending calls to the rate_limited_funcs
|
||||||
|
this._updateRoomMembers.cancelPendingCall();
|
||||||
|
|
||||||
// no need to do this as Dir & Settings are now overlays. It just burnt CPU.
|
// no need to do this as Dir & Settings are now overlays. It just burnt CPU.
|
||||||
// console.log("Tinter.tint from RoomView.unmount");
|
// console.log("Tinter.tint from RoomView.unmount");
|
||||||
// Tinter.tint(); // reset colourscheme
|
// Tinter.tint(); // reset colourscheme
|
||||||
|
|
|
@ -58,6 +58,8 @@ module.exports = React.createClass({
|
||||||
if (cli) {
|
if (cli) {
|
||||||
cli.removeListener("RoomState.members", this.onRoomStateMember);
|
cli.removeListener("RoomState.members", this.onRoomStateMember);
|
||||||
}
|
}
|
||||||
|
// cancel any pending calls to the rate_limited_funcs
|
||||||
|
this._updateList.cancelPendingCall();
|
||||||
},
|
},
|
||||||
|
|
||||||
_updateList: new rate_limited_func(function() {
|
_updateList: new rate_limited_func(function() {
|
||||||
|
@ -100,7 +102,7 @@ module.exports = React.createClass({
|
||||||
<EntityTile key="dynamic_invite_tile" suppressOnHover={true} showInviteButton={true}
|
<EntityTile key="dynamic_invite_tile" suppressOnHover={true} showInviteButton={true}
|
||||||
avatarJsx={ <BaseAvatar name="@" width={36} height={36} /> }
|
avatarJsx={ <BaseAvatar name="@" width={36} height={36} /> }
|
||||||
className="mx_EntityTile_invitePlaceholder"
|
className="mx_EntityTile_invitePlaceholder"
|
||||||
presenceState="online" onClick={this.onThirdPartyInvite} name={"Invite by email"}
|
presenceState="online" onClick={this.onThirdPartyInvite} name={"Invite by email"}
|
||||||
/>,
|
/>,
|
||||||
function(query) {
|
function(query) {
|
||||||
return true; // always show this
|
return true; // always show this
|
||||||
|
|
|
@ -81,6 +81,9 @@ module.exports = React.createClass({
|
||||||
cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs);
|
cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs);
|
||||||
// cli.removeListener("Room.timeline", this.onRoomTimeline);
|
// cli.removeListener("Room.timeline", this.onRoomTimeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cancel any pending calls to the rate_limited_funcs
|
||||||
|
this._updateList.cancelPendingCall();
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -101,6 +101,8 @@ module.exports = React.createClass({
|
||||||
MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents);
|
MatrixClientPeg.get().removeListener("RoomState.events", this.onRoomStateEvents);
|
||||||
MatrixClientPeg.get().removeListener("RoomMember.name", this.onRoomMemberName);
|
MatrixClientPeg.get().removeListener("RoomMember.name", this.onRoomMemberName);
|
||||||
}
|
}
|
||||||
|
// cancel any pending calls to the rate_limited_funcs
|
||||||
|
this._delayedRefreshRoomList.cancelPendingCall();
|
||||||
},
|
},
|
||||||
|
|
||||||
onRoom: function(room) {
|
onRoom: function(room) {
|
||||||
|
|
|
@ -21,13 +21,16 @@ limitations under the License.
|
||||||
*
|
*
|
||||||
* Note that the function must not take arguments, since the args
|
* Note that the function must not take arguments, since the args
|
||||||
* could be different for each invocarion of the function.
|
* could be different for each invocarion of the function.
|
||||||
|
*
|
||||||
|
* The returned function has a 'cancelPendingCall' property which can be called
|
||||||
|
* on unmount or similar to cancel any pending update.
|
||||||
*/
|
*/
|
||||||
module.exports = function(f, minIntervalMs) {
|
module.exports = function(f, minIntervalMs) {
|
||||||
this.lastCall = 0;
|
this.lastCall = 0;
|
||||||
this.scheduledCall = undefined;
|
this.scheduledCall = undefined;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return function() {
|
var wrapper = function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
|
||||||
if (self.lastCall < now - minIntervalMs) {
|
if (self.lastCall < now - minIntervalMs) {
|
||||||
|
@ -44,5 +47,23 @@ module.exports = function(f, minIntervalMs) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
// add the cancelPendingCall property
|
||||||
|
wrapper.cancelPendingCall = function() {
|
||||||
|
if (self.scheduledCall) {
|
||||||
|
clearTimeout(self.scheduledCall);
|
||||||
|
self.scheduledCall = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// make sure that cancelPendingCall is copied when react rebinds the
|
||||||
|
// wrapper
|
||||||
|
var _bind = wrapper.bind;
|
||||||
|
wrapper.bind = function() {
|
||||||
|
var rebound = _bind.apply(this, arguments);
|
||||||
|
rebound.cancelPendingCall = wrapper.cancelPendingCall;
|
||||||
|
return rebound;
|
||||||
|
};
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue