charlie 1 рік тому
батько
коміт
25f93f998a
1 змінених файлів з 11 додано та 11 видалено
  1. 11 11
      src/main/logseq/api.cljs

+ 11 - 11
src/main/logseq/api.cljs

@@ -1077,17 +1077,17 @@
 (defn ^:export exper_load_scripts
   [pid & scripts]
   (when-let [^js _pl (plugin-handler/get-plugin-inst pid)]
-    (doseq [s scripts
-            :let [upt-status #(state/upt-plugin-resource pid :scripts s :status %)
-                  init?      (plugin-handler/register-plugin-resources pid :scripts {:key s :src s})]]
-      (when init?
-        (p/catch
-          (p/then
-            (do
-              (upt-status :pending)
-              (loader/load s nil {:attributes {:data-ref (name pid)}}))
-            #(upt-status :done))
-          #(upt-status :error))))))
+    (some-> (for [s scripts
+                  :let [upt-status #(state/upt-plugin-resource pid :scripts s :status %)
+                        init? (contains? #{:error nil} (:status (state/get-plugin-resource pid :scripts s)))]]
+              (when init?
+                (plugin-handler/register-plugin-resources pid :scripts {:key s :src s})
+                (upt-status :pending)
+                (-> (loader/load s nil {:attributes {:data-ref (name pid)}})
+                  (p/then (fn [] (upt-status :done)))
+                  (p/catch (fn [] (upt-status :error))))))
+      (vec)
+      (p/all))))
 
 ;; http request
 (defonce *request-k (volatile! 0))