[FIX] Intended direct mutation state running before initial state gets initiated (#1197)

This commit is contained in:
Diego Mello 2019-09-17 11:43:49 -03:00 committed by GitHub
parent 8d4d522b63
commit 96eb86927a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 33 deletions

View File

@ -114,7 +114,9 @@ export default class NotificationPreferencesView extends React.Component {
this.mounted = false;
this.rid = props.navigation.getParam('rid');
const room = props.navigation.getParam('room');
this.state = {
room: room || {}
};
if (room && room.observe) {
this.roomObservable = room.observe();
this.subscription = this.roomObservable
@ -126,10 +128,6 @@ export default class NotificationPreferencesView extends React.Component {
}
});
}
this.state = {
room: room || {}
};
}
componentDidMount() {

View File

@ -43,19 +43,6 @@ class RoomActionsView extends React.Component {
super(props);
this.mounted = false;
const room = props.navigation.getParam('room');
if (room && room.observe) {
this.roomObservable = room.observe();
this.subscription = this.roomObservable
.subscribe((changes) => {
if (this.mounted) {
this.setState({ room: changes });
} else {
this.state.room = changes;
}
});
}
this.rid = props.navigation.getParam('rid');
this.t = props.navigation.getParam('t');
this.state = {
@ -67,6 +54,17 @@ class RoomActionsView extends React.Component {
canAutoTranslate: false,
canAddUser: false
};
if (room && room.observe) {
this.roomObservable = room.observe();
this.subscription = this.roomObservable
.subscribe((changes) => {
if (this.mounted) {
this.setState({ room: changes });
} else {
this.state.room = changes;
}
});
}
}
async componentDidMount() {

View File

@ -57,20 +57,7 @@ class RoomMembersView extends React.Component {
this.MUTE_INDEX = 1;
this.actionSheetOptions = [''];
const { rid } = props.navigation.state.params;
const room = props.navigation.getParam('room');
if (room && room.observe) {
this.roomObservable = room.observe();
this.subscription = this.roomObservable
.subscribe((changes) => {
if (this.mounted) {
this.setState({ room: changes });
} else {
this.state.room = changes;
}
});
}
this.state = {
isLoading: false,
allUsers: false,
@ -82,6 +69,17 @@ class RoomMembersView extends React.Component {
room: room || {},
end: false
};
if (room && room.observe) {
this.roomObservable = room.observe();
this.subscription = this.roomObservable
.subscribe((changes) => {
if (this.mounted) {
this.setState({ room: changes });
} else {
this.state.room = changes;
}
});
}
}
async componentDidMount() {

View File

@ -76,10 +76,10 @@ class UploadProgress extends Component {
super(props);
this.mounted = false;
this.ranInitialUploadCheck = false;
this.init();
this.state = {
uploads: []
};
this.init();
}
componentDidMount() {

View File

@ -43,12 +43,12 @@ class ThreadMessagesView extends React.Component {
this.mounted = false;
this.rid = props.navigation.getParam('rid');
this.t = props.navigation.getParam('t');
this.subscribeData();
this.state = {
loading: false,
end: false,
messages: []
};
this.subscribeData();
}
componentDidMount() {