Debounce language changes (#141)

- Closes #140
main
Michael Fix 7 years ago committed by GitHub
parent 2365b8a5f9
commit 94e4767808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,8 @@ import React from 'react'
import domtoimage from 'dom-to-image'
import Spinner from 'react-spinner'
import toHash from 'tohash'
import debounce from 'lodash.debounce'
import ms from 'ms'
import WindowControls from '../components/WindowControls'
import CodeMirror from '../lib/react-codemirror'
import {
@ -55,7 +57,8 @@ class Carbon extends React.Component {
this.props.updateCode(newCode)
}
handleLanguageChange(newCode, config) {
handleLanguageChange = debounce(
(newCode, config) => {
const props = (config && config.customProps) || this.props
if (props.config.language === 'auto') {
@ -70,7 +73,10 @@ class Carbon extends React.Component {
} else {
this.setState({ language: props.config.language })
}
}
},
ms('300ms'),
{ trailing: true }
)
render() {
const config = { ...DEFAULT_SETTINGS, ...this.props.config }

Loading…
Cancel
Save