A bit of refactoring
This commit is contained in:
parent
6f1fbac9ac
commit
ba1eb2a837
|
@ -30,10 +30,6 @@ export default class ModeMenu extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick = () => {
|
handleClick = () => {
|
||||||
// we trigger the onChangeMode on the next tick, after the click event
|
|
||||||
// has been finished. This is a workaround for preact not neatly replacing
|
|
||||||
// a rendered app whilst the event is still being handled.
|
|
||||||
setTimeout(() => {
|
|
||||||
try {
|
try {
|
||||||
this.props.onRequestClose()
|
this.props.onRequestClose()
|
||||||
this.props.onChangeMode(mode)
|
this.props.onChangeMode(mode)
|
||||||
|
@ -41,7 +37,6 @@ export default class ModeMenu extends Component {
|
||||||
catch (err) {
|
catch (err) {
|
||||||
this.props.onError(err)
|
this.props.onError(err)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
|
|
@ -179,6 +179,10 @@ function jsoneditor (container, options = {}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChangeMode (mode) {
|
function handleChangeMode (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
|
const prevMode = editor._mode
|
||||||
|
|
||||||
editor.setMode(mode)
|
editor.setMode(mode)
|
||||||
|
@ -186,6 +190,7 @@ function jsoneditor (container, options = {}) {
|
||||||
if (editor._options.onChangeMode) {
|
if (editor._options.onChangeMode) {
|
||||||
editor._options.onChangeMode(mode, prevMode)
|
editor._options.onChangeMode(mode, prevMode)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleError (err) {
|
function handleError (err) {
|
||||||
|
|
Loading…
Reference in New Issue