add constantTimeDispatcher and use it for strategic refreshes.

constantTimeDispatcher lets you poke a specific react component to do something
without having to do any O(N) operations.  This is useful if you have thousands
of RoomTiles in a RoomSubList and want to just tell one of them to update,
without either having to do a full comparison of this.props.list or have each
and every RoomTile subscribe to a generic event from flux or node's eventemitter

*UNTESTED*
This commit is contained in:
Matthew Hodgson 2017-04-17 20:58:43 +01:00
parent 691639d1e0
commit da569c2c8d
4 changed files with 136 additions and 24 deletions

View file

@ -27,6 +27,7 @@ var RoomNotifs = require('../../../RoomNotifs');
var FormattingUtils = require('../../../utils/FormattingUtils');
import AccessibleButton from '../elements/AccessibleButton';
var UserSettingsStore = require('../../../UserSettingsStore');
var constantTimeDispatcher = require('../../../ConstantTimeDispatcher');
module.exports = React.createClass({
displayName: 'RoomTile',
@ -89,16 +90,22 @@ module.exports = React.createClass({
},
componentWillMount: function() {
constantTimeDispatcher.register("RoomTile.refresh", this.props.room.roomId, this.onRefresh);
MatrixClientPeg.get().on("accountData", this.onAccountData);
},
componentWillUnmount: function() {
constantTimeDispatcher.unregister("RoomTile.refresh", this.props.room.roomId, this.onRefresh);
var cli = MatrixClientPeg.get();
if (cli) {
MatrixClientPeg.get().removeListener("accountData", this.onAccountData);
}
},
onRefresh: function() {
this.forceUpdate();
},
onClick: function() {
if (this.props.onClick) {
this.props.onClick(this.props.room.roomId);