From b357ef06b92f8af28621811068cd3498d867f076 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Fri, 9 Feb 2018 09:58:22 +0100 Subject: [PATCH] RichText: Throttle changes for performance reasons --- blocks/rich-text/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/blocks/rich-text/index.js b/blocks/rich-text/index.js index a8234fb4c82ea2..c7e7478a081620 100644 --- a/blocks/rich-text/index.js +++ b/blocks/rich-text/index.js @@ -13,6 +13,7 @@ import { find, defer, noop, + throttle, } from 'lodash'; import { nodeListToReact } from 'dom-react'; import 'element-closest'; @@ -92,6 +93,7 @@ export default class RichText extends Component { this.getSettings = this.getSettings.bind( this ); this.onSetup = this.onSetup.bind( this ); this.onChange = this.onChange.bind( this ); + this.throttledOnChange = throttle( this.onChange.bind( this ), 500 ); this.onNewBlock = this.onNewBlock.bind( this ); this.onNodeChange = this.onNodeChange.bind( this ); this.onKeyDown = this.onKeyDown.bind( this ); @@ -149,7 +151,7 @@ export default class RichText extends Component { editor.on( 'BeforeExecCommand', this.maybePropagateUndo ); editor.on( 'PastePreProcess', this.onPastePreProcess, true /* Add before core handlers */ ); editor.on( 'paste', this.onPaste, true /* Add before core handlers */ ); - editor.on( 'input', this.onChange ); + editor.on( 'input', this.throttledOnChange ); patterns.apply( this, [ editor ] );