Skip to content
Snippets Groups Projects
Commit 430099fe authored by Alf Eaton's avatar Alf Eaton
Browse files

debounce onDocumentChange

parent 5c39f8d0
No related branches found
No related tags found
No related merge requests found
import React from 'react' import React from 'react'
import { debounce } from 'lodash'
import { Editor as SlateEditor, Plain } from 'slate' import { Editor as SlateEditor, Plain } from 'slate'
import EditorToolbar from './EditorToolbar' import EditorToolbar from './EditorToolbar'
...@@ -10,6 +11,12 @@ class Editor extends React.Component { ...@@ -10,6 +11,12 @@ class Editor extends React.Component {
state: undefined state: undefined
} }
constructor (props) {
super(props)
this.throttledOnDocumentChange = debounce(this.onDocumentChange, 1000)
}
componentDidMount () { componentDidMount () {
this.deserialize(this.props.value) this.deserialize(this.props.value)
} }
...@@ -46,8 +53,7 @@ class Editor extends React.Component { ...@@ -46,8 +53,7 @@ class Editor extends React.Component {
this.setState({ state }) this.setState({ state })
} }
// TODO: debouncing? onDocumentChange = (document, state) => {
onDocumentChange = (document, state) => {
const { converter, onDocumentChange } = this.props const { converter, onDocumentChange } = this.props
if (typeof onDocumentChange === 'function') { if (typeof onDocumentChange === 'function') {
...@@ -152,7 +158,7 @@ class Editor extends React.Component { ...@@ -152,7 +158,7 @@ class Editor extends React.Component {
onKeyDown={this.onKeyDown} onKeyDown={this.onKeyDown}
onPaste={this.onReceive} onPaste={this.onReceive}
onDrop={this.onReceive} onDrop={this.onReceive}
onDocumentChange={this.onDocumentChange} onDocumentChange={this.throttledOnDocumentChange}
placeholder={placeholder} placeholder={placeholder}
spellCheck spellCheck
/> />
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment