Disable wasm loading if feature is disabled

This commit is contained in:
Andrey Antukh 2024-11-27 09:24:27 +01:00
parent b17d7c0289
commit 1de35b2e3a
3 changed files with 42 additions and 37 deletions

View file

@ -127,7 +127,7 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ stream] (watch [_ _ stream]
(let [stopper (rx/filter (ptk/type? ::finalize) stream)] (let [stopper (rx/filter (ptk/type? ::finalize-team) stream)]
(->> (rx/merge (->> (rx/merge
(rx/of (fetch-teams)) (rx/of (fetch-teams))
(->> stream (->> stream

View file

@ -267,30 +267,34 @@
[project-id file-id] [project-id file-id]
(ptk/reify ::fetch-bundle-stage-1 (ptk/reify ::fetch-bundle-stage-1
ptk/WatchEvent ptk/WatchEvent
(watch [_ _ stream] (watch [_ state stream]
(->> (rp/cmd! :get-project {:id project-id}) (let [render-wasm? (features/active-feature? state "render-wasm/v1")]
(rx/mapcat (fn [project] (->> (rp/cmd! :get-project {:id project-id})
(rx/concat (rx/mapcat (fn [project]
;; Wait the wasm module to be loaded or failed to (rx/concat
;; load. We need to wait the promise to be resolved ;; Wait the wasm module to be loaded or failed to
;; before continue with the next workspace loading ;; load. We need to wait the promise to be resolved
;; steps ;; before continue with the next workspace loading
(->> (rx/from wasm/module) ;; steps
(rx/ignore))
(->> (rp/cmd! :get-team {:id (:team-id project)}) (if ^boolean render-wasm?
(rx/mapcat (fn [team] (->> (rx/from @wasm/module)
(let [bundle {:team team (rx/ignore))
:project project (rx/empty))
:file-id file-id
:project-id project-id}] (->> (rp/cmd! :get-team {:id (:team-id project)})
;; FIXME: this should not be handled here, pending (rx/mapcat (fn [team]
;; refactor of urls and team initialization (let [bundle {:team team
;; normalization :project project
(rx/of (dtm/set-current-team team) :file-id file-id
(ptk/data-event ::bundle-stage-1 bundle))))))))) :project-id project-id}]
(rx/take-until ;; FIXME: this should not be handled here, pending
(rx/filter (ptk/type? ::fetch-bundle) stream)))))) ;; refactor of urls and team initialization
;; normalization
(rx/of (dtm/set-current-team team)
(ptk/data-event ::bundle-stage-1 bundle)))))))))
(rx/take-until
(rx/filter (ptk/type? ::fetch-bundle) stream)))))))
(defn- fetch-bundle-stage-2 (defn- fetch-bundle-stage-2
[{:keys [file-id project-id project] :as bundle}] [{:keys [file-id project-id project] :as bundle}]

View file

@ -239,16 +239,17 @@
(set! (.-height canvas) (* dpr (.-clientHeight ^js canvas)))) (set! (.-height canvas) (* dpr (.-clientHeight ^js canvas))))
(defonce module (defonce module
(if (exists? js/dynamicImport) (delay
(let [uri (cf/resolve-static-asset "js/render_wasm.js")] (if (exists? js/dynamicImport)
(->> (js/dynamicImport (str uri)) (let [uri (cf/resolve-static-asset "js/render_wasm.js")]
(p/mcat (fn [module] (->> (js/dynamicImport (str uri))
(let [default (unchecked-get module "default")] (p/mcat (fn [module]
(default)))) (let [default (unchecked-get module "default")]
(p/fmap (fn [module] (default))))
(set! internal-module module) (p/fmap (fn [module]
true)) (set! internal-module module)
(p/merr (fn [cause] true))
(js/console.error cause) (p/merr (fn [cause]
(p/resolved false))))) (js/console.error cause)
(p/resolved false))) (p/resolved false)))))
(p/resolved false))))