Simplify GroupStore listener registration

This commit is contained in:
Luke Barnard 2017-10-27 11:36:32 +01:00
parent 1715206f62
commit e094c32c62
4 changed files with 14 additions and 12 deletions

View File

@ -447,7 +447,7 @@ export default React.createClass({
_initGroupStore: function(groupId) { _initGroupStore: function(groupId) {
this._groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), groupId); this._groupStore = GroupStoreCache.getGroupStore(MatrixClientPeg.get(), groupId);
this._groupStore.on('update', () => { this._groupStore.registerListener(() => {
const summary = this._groupStore.getSummary(); const summary = this._groupStore.getSummary();
if (summary.profile) { if (summary.profile) {
// Default profile fields should be "" for later sending to the server (which // Default profile fields should be "" for later sending to the server (which
@ -464,7 +464,6 @@ export default React.createClass({
}); });
}); });
this._groupStore.on('error', (err) => { this._groupStore.on('error', (err) => {
console.error(err);
this.setState({ this.setState({
summary: null, summary: null,
error: err, error: err,

View File

@ -50,12 +50,9 @@ export default withMatrixClient(React.createClass({
_initGroupStore: function(groupId) { _initGroupStore: function(groupId) {
this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId);
this._groupStore.on('update', () => { this._groupStore.registerListener(() => {
this._fetchMembers(); this._fetchMembers();
}); });
this._groupStore.on('error', (err) => {
console.error(err);
});
}, },
_fetchMembers: function() { _fetchMembers: function() {

View File

@ -47,16 +47,14 @@ export default React.createClass({
_initGroupStore: function(groupId) { _initGroupStore: function(groupId) {
this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId); this._groupStore = GroupStoreCache.getGroupStore(this.context.matrixClient, groupId);
this._groupStore.on('update', () => { this._groupStore.registerListener(() => {
this._fetchRooms(); this._fetchRooms();
}); });
this._groupStore.on('error', (err) => { this._groupStore.on('error', (err) => {
console.error('Error in group store (listened to by GroupRoomList)', err);
this.setState({ this.setState({
rooms: null, rooms: null,
}); });
}); });
this._fetchRooms();
}, },
_fetchRooms: function() { _fetchRooms: function() {

View File

@ -29,9 +29,10 @@ export default class GroupStore extends EventEmitter {
this._matrixClient = matrixClient; this._matrixClient = matrixClient;
this._summary = {}; this._summary = {};
this._rooms = []; this._rooms = [];
this._fetchSummary();
this._fetchRooms(); this.on('error', (err) => {
this._fetchMembers(); console.error(`GroupStore for ${this.groupId} encountered error`, err);
});
} }
_fetchMembers() { _fetchMembers() {
@ -80,6 +81,13 @@ export default class GroupStore extends EventEmitter {
this.emit('update'); this.emit('update');
} }
registerListener(fn) {
this.on('update', fn);
this._fetchSummary();
this._fetchRooms();
this._fetchMembers();
}
getSummary() { getSummary() {
return this._summary; return this._summary;
} }