Don't reset editor state if props didn't change. Fixes #34

This commit is contained in:
Tulir Asokan 2018-12-09 14:58:59 +02:00
parent 0e4cea6f52
commit 5704b3e53b
3 changed files with 21 additions and 2 deletions

View file

@ -8,7 +8,13 @@ class BaseMainView extends Component {
}
componentWillReceiveProps(nextProps) {
this.setState(Object.assign(this.initialState, nextProps.entry))
const newState = Object.assign(this.initialState, nextProps.entry)
for (const key of this.entryKeys) {
if (this.props.entry[key] === nextProps.entry[key]) {
newState[key] = this.state[key]
}
}
this.setState(newState)
}
delete = async () => {
@ -25,8 +31,12 @@ class BaseMainView extends Component {
}
}
get entryKeys() {
return []
}
get initialState() {
throw Error("Not implemented")
return {}
}
get hasInstances() {

View file

@ -46,6 +46,11 @@ class Client extends BaseMainView {
this.deleteFunc = api.deleteClient
}
get entryKeys() {
return ["id", "displayname", "homeserver", "avatar_url", "access_token", "sync",
"autojoin", "enabled", "started"]
}
get initialState() {
return {
id: "",

View file

@ -40,6 +40,10 @@ class Instance extends BaseMainView {
this.updateClientOptions()
}
get entryKeys() {
return ["id", "primary_user", "enabled", "started", "type", "config"]
}
get initialState() {
return {
id: "",