Просмотр исходного кода

WIP: GC-529 invoke saveOnHackmd API

* use debounce when postMessage
Yuki Takei 7 лет назад
Родитель
Сommit
de186167e0
1 измененных файлов с 8 добавлено и 4 удалено
  1. 8 4
      resource/js/agent-for-hackmd.js

+ 8 - 4
resource/js/agent-for-hackmd.js

@@ -9,7 +9,7 @@
  *
  * @author Yuki Takei <yuki@weseek.co.jp>
  */
-// import { debounce } from 'throttle-debounce';
+import { debounce } from 'throttle-debounce';
 
 /* eslint-disable no-console  */
 
@@ -38,15 +38,19 @@ function insertStyle() {
 }
 
 function postMessageOnSave() {
-  console.log('notifyChanges');
-  window.parent.postMessage('notifyChanges', allowedOrigin);
+  const data = '{ "operation": "notifyBodyChanges" }';
+  window.parent.postMessage(data, allowedOrigin);
 }
 
 function addEventListenersToCodemirror() {
   // get CodeMirror instance
   const editor = window.editor;
+
+  // generate debounced function
+  const debouncedFunc = debounce(1500, postMessageOnSave);
+
   editor.on('change', (cm, change) => {
-    postMessageOnSave();
+    debouncedFunc();
   });
 }