Explorar o código

fix: 现在JSON输入时校验能正确地防抖

Jinyao %!s(int64=5) %!d(string=hai) anos
pai
achega
3ed4467b92
Modificáronse 2 ficheiros con 4 adicións e 5 borrados
  1. 2 2
      src/utils/debounce.ts
  2. 2 3
      src/views/Project/Pipeline.vue

+ 2 - 2
src/utils/debounce.ts

@@ -1,6 +1,6 @@
 /* eslint-disable */
 const debounce = (fn: Function, delay: number) => {
-  let timer: NodeJS.Timeout | null = null;
+  let timer: NodeJS.Timeout;
   return function () {
     // @ts-ignore
     const context = this;
@@ -8,7 +8,7 @@ const debounce = (fn: Function, delay: number) => {
     if (timer) {
       clearTimeout(timer);
     }
-    timer = setTimeout(fn.apply(context, args), delay);
+    timer = setTimeout(() => fn.apply(context, args), delay);
   };
 };
 

+ 2 - 3
src/views/Project/Pipeline.vue

@@ -335,15 +335,14 @@ export default {
       }
     },
     // eslint-disable-next-line func-names
-    // FIXME: debounce效果有点问题,待排查
     lintJson: debounce(function (value) {
+      this.jsonValid = true;
       try {
         const result = jsonlint.parse(value);
         this.pipelineConfig = JSON.stringify(result, null, '  ');
-        this.jsonValid = true;
       } catch (e) {
         this.jsonValid = false;
-        this.hint = e;
+        this.hint = `${value}\n${e}`;
       }
     }, 500),
     async handlePipelineUpdateConfirm() {