A bit of refactoring

This commit is contained in:
jos 2017-01-08 20:51:08 +01:00
parent 6f1fbac9ac
commit ba1eb2a837
2 changed files with 17 additions and 17 deletions

View File

@ -30,18 +30,13 @@ export default class ModeMenu extends Component {
} }
handleClick = () => { handleClick = () => {
// we trigger the onChangeMode on the next tick, after the click event try {
// has been finished. This is a workaround for preact not neatly replacing this.props.onRequestClose()
// a rendered app whilst the event is still being handled. this.props.onChangeMode(mode)
setTimeout(() => { }
try { catch (err) {
this.props.onRequestClose() this.props.onError(err)
this.props.onChangeMode(mode) }
}
catch (err) {
this.props.onError(err)
}
})
} }
componentDidMount () { componentDidMount () {

View File

@ -179,13 +179,18 @@ function jsoneditor (container, options = {}) {
} }
function handleChangeMode (mode) { function handleChangeMode (mode) {
const prevMode = editor._mode // we execute editor.setMode on the next tick, after the click event
// has been finished. This is a workaround for preact which does not
// neatly replace a rendered app whilst the event is still being handled.
setTimeout(() => {
const prevMode = editor._mode
editor.setMode(mode) editor.setMode(mode)
if (editor._options.onChangeMode) { if (editor._options.onChangeMode) {
editor._options.onChangeMode(mode, prevMode) editor._options.onChangeMode(mode, prevMode)
} }
})
} }
function handleError (err) { function handleError (err) {