Browse Source

Merge pull request #2567 from weseek/imprv/added-debounce-functions

added debounce
Yuki Takei 5 years ago
parent
commit
d66abae69a
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/client/js/components/PageEditor/LinkEditModal.jsx

+ 5 - 2
src/client/js/components/PageEditor/LinkEditModal.jsx

@@ -8,6 +8,8 @@ import {
   ModalFooter,
 } from 'reactstrap';
 
+import { debounce } from 'throttle-debounce';
+
 import path from 'path';
 import Preview from './Preview';
 
@@ -48,16 +50,17 @@ class LinkEditModal extends React.PureComponent {
     this.toggleIsUsePamanentLink = this.toggleIsUsePamanentLink.bind(this);
     this.save = this.save.bind(this);
     this.generateLink = this.generateLink.bind(this);
-    this.getPreview = this.getPreview.bind(this);
     this.renderPreview = this.renderPreview.bind(this);
     this.getRootPath = this.getRootPath.bind(this);
+
+    this.getPreviewDebounced = debounce(200, this.getPreview.bind(this));
   }
 
   componentDidUpdate(prevState) {
     const { linkInputValue: prevLinkInputValue } = prevState;
     const { linkInputValue } = this.state;
     if (linkInputValue !== prevLinkInputValue) {
-      this.getPreview(linkInputValue);
+      this.getPreviewDebounced(linkInputValue);
     }
   }