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

View File

@ -43,19 +43,6 @@ class RoomActionsView extends React.Component {
super(props); super(props);
this.mounted = false; this.mounted = false;
const room = props.navigation.getParam('room'); 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.rid = props.navigation.getParam('rid');
this.t = props.navigation.getParam('t'); this.t = props.navigation.getParam('t');
this.state = { this.state = {
@ -67,6 +54,17 @@ class RoomActionsView extends React.Component {
canAutoTranslate: false, canAutoTranslate: false,
canAddUser: 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() { async componentDidMount() {

View File

@ -57,20 +57,7 @@ class RoomMembersView extends React.Component {
this.MUTE_INDEX = 1; this.MUTE_INDEX = 1;
this.actionSheetOptions = ['']; this.actionSheetOptions = [''];
const { rid } = props.navigation.state.params; const { rid } = props.navigation.state.params;
const room = props.navigation.getParam('room'); 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 = { this.state = {
isLoading: false, isLoading: false,
allUsers: false, allUsers: false,
@ -82,6 +69,17 @@ class RoomMembersView extends React.Component {
room: room || {}, room: room || {},
end: false 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() { async componentDidMount() {

View File

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

View File

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