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

fix: comlink proxy method arguments shouldn't put in promesa

Tienson Qin 2 лет назад
Родитель
Сommit
e2ea7d7c29

+ 7 - 6
src/main/frontend/db_worker.cljs

@@ -18,12 +18,13 @@
 (defn- init-sqlite-module!
   []
   (when-not @*sqlite
-    (p/let [base-url (str js/self.location.protocol "//" js/self.location.host)
-            sqlite-wasm-url (str base-url "/js/")
-            sqlite (sqlite3InitModule (clj->js {:url sqlite-wasm-url
-                                                :print js/console.log
-                                                :printErr js/console.error}))]
-      (reset! *sqlite sqlite))))
+    (let [base-url (str js/self.location.protocol "//" js/self.location.host)
+          sqlite-wasm-url (str base-url "/js/")]
+      (sqlite3InitModule (clj->js {:url sqlite-wasm-url
+                                   :print js/console.log
+                                   :printErr js/console.error})
+                         (fn [sqlite]
+                           (reset! *sqlite sqlite))))))
 
 (defn- close-all-dbs!
   []

+ 2 - 2
src/main/frontend/handler.cljs

@@ -214,6 +214,7 @@
   [render]
   (test/setup-test!)
   (get-system-info)
+  (db-browser/start-db-worker!)
   (set-global-error-notification!)
 
   (set! js/window.onhashchange #(state/hide-custom-context-menu!)) ;; close context menu when page navs
@@ -243,8 +244,7 @@
   (p/do!
    (when (mobile-util/native-platform?)
      (mobile/mobile-preinit))
-   (-> (p/let [_ (db-browser/start-db-worker!)
-               repos (get-repos)
+   (-> (p/let [repos (get-repos)
                _ (state/set-repos! repos)
                _ (mobile-util/hide-splash) ;; hide splash as early as ui is stable
                _ (restore-and-setup! repos)]

+ 12 - 14
src/main/frontend/persist_db/browser.cljs

@@ -15,17 +15,14 @@
 (defn start-db-worker!
   []
   (when-not (or config/publishing? util/node-test?)
-    (p/let [worker-url (if (util/electron?)
-                         "js/db-worker.js"
-                         "/static/js/db-worker.js")
-            worker (js/Worker. worker-url)
-            _ (prn :debug :worker worker)
-            ^js sqlite (Comlink/wrap worker)
-            ;; _ (.init sqlite)
-            ]
-      (prn :debug :sqlite)
-      (js/console.dir sqlite)
-      (reset! *sqlite sqlite))))
+    (let [worker-url (if (util/electron?)
+                       "js/db-worker.js"
+                       "/static/js/db-worker.js")
+          worker (js/Worker. worker-url)
+          ^js sqlite (Comlink/wrap worker)]
+      (reset! *sqlite sqlite)
+      ;; (.init sqlite)
+      )))
 
 (defrecord InBrowser []
   protocol/PersistentDB
@@ -60,11 +57,12 @@
 
   (<fetch-initital-data [_this repo _opts]
     (prn ::fetch-initital-data repo @*sqlite)
-    (-> (p/let [^js sqlite @*sqlite
+    (-> (let [^js sqlite @*sqlite
                 ;; <fetch-initital-data is called when init/re-loading graph
                 ;; the underlying DB should be opened
-                _ (.newDB sqlite repo)]
-          (.getInitialData sqlite repo))
+              ]
+          (p/let [_ (.newDB sqlite repo)]
+            (.getInitialData sqlite repo)))
         (p/catch (fn [error]
                    (prn :debug :fetch-initial-data-error)
                    (js/console.error error)