mirror of
https://github.com/penpot/penpot.git
synced 2025-01-08 16:00:19 -05:00
✨ Make workspace and features system aware of render.wasm loading
This commit is contained in:
parent
dd1997e23c
commit
5d4511fc6a
4 changed files with 44 additions and 32 deletions
|
@ -76,6 +76,7 @@
|
|||
[app.main.repo :as rp]
|
||||
[app.main.streams :as ms]
|
||||
[app.main.worker :as uw]
|
||||
[app.render-wasm :as render.wasm]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.globals :as ug]
|
||||
[app.util.http :as http]
|
||||
|
@ -264,14 +265,21 @@
|
|||
(watch [_ _ stream]
|
||||
(->> (rp/cmd! :get-project {:id project-id})
|
||||
(rx/mapcat (fn [project]
|
||||
(->> (rp/cmd! :get-team {:id (:team-id project)})
|
||||
(rx/mapcat (fn [team]
|
||||
(let [bundle {:team team
|
||||
:project project
|
||||
:file-id file-id
|
||||
:project-id project-id}]
|
||||
(rx/of (du/set-current-team team)
|
||||
(ptk/data-event ::bundle-stage-1 bundle))))))))
|
||||
(rx/concat
|
||||
;; Wait the wasm module to be loaded or failed to
|
||||
;; load. We need to wait the promise to be resolved
|
||||
;; before continue with the next workspace loading
|
||||
;; steps
|
||||
(->> (rx/from render.wasm/module)
|
||||
(rx/ignore))
|
||||
(->> (rp/cmd! :get-team {:id (:team-id project)})
|
||||
(rx/mapcat (fn [team]
|
||||
(let [bundle {:team team
|
||||
:project project
|
||||
:file-id file-id
|
||||
:project-id project-id}]
|
||||
(rx/of (du/set-current-team team)
|
||||
(ptk/data-event ::bundle-stage-1 bundle)))))))))
|
||||
(rx/take-until
|
||||
(rx/filter (ptk/type? ::fetch-bundle) stream))))))
|
||||
|
||||
|
@ -354,13 +362,12 @@
|
|||
(let [stoper-s (rx/filter (ptk/type? ::finalize-file) stream)]
|
||||
(rx/merge
|
||||
(rx/of (ntf/hide)
|
||||
;; We initialize the features without knowning the
|
||||
;; team specific features in this step.
|
||||
(features/initialize)
|
||||
(dcm/retrieve-comment-threads file-id)
|
||||
(fetch-bundle project-id file-id))
|
||||
|
||||
;; (when (contains? cf/flags :renderer-v2)
|
||||
;; (rx/of (renderer/init)))
|
||||
|
||||
(->> stream
|
||||
(rx/filter dch/commit?)
|
||||
(rx/map deref)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
[app.common.logging :as log]
|
||||
[app.config :as cf]
|
||||
[app.main.store :as st]
|
||||
[app.render-wasm :as render.wasm]
|
||||
[beicon.v2.core :as rx]
|
||||
[clojure.set :as set]
|
||||
[cuerdas.core :as str]
|
||||
|
@ -110,7 +111,7 @@
|
|||
(when *assert*
|
||||
(->> (rx/from cfeat/no-migration-features)
|
||||
;; text editor v2 isn't enabled by default even in devenv
|
||||
;; wasm render v1 isn't enabled by default even in devenv
|
||||
;; wasm render v1 isn't enabled by default even in devenv
|
||||
(rx/filter #(not (or (contains? cfeat/backend-only-features %)
|
||||
(= "text-editor/v2" %)
|
||||
(= "render-wasm/v1" %)
|
||||
|
@ -120,6 +121,11 @@
|
|||
|
||||
ptk/EffectEvent
|
||||
(effect [_ state _]
|
||||
(let [features (get-team-enabled-features state)]
|
||||
(if (contains? features "render-wasm/v1")
|
||||
(render.wasm/initialize true)
|
||||
(render.wasm/initialize false)))
|
||||
|
||||
(log/trc :hint "initialized features"
|
||||
:team (str/join "," (:features-team state))
|
||||
:runtime (str/join "," (:features-runtime state)))))))
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
[app.main.ui.workspace.viewport.utils :as utils]
|
||||
[app.main.ui.workspace.viewport.viewport-ref :refer [create-viewport-ref]]
|
||||
[app.main.ui.workspace.viewport.widgets :as widgets]
|
||||
[app.render-wasm :as render.wasm]
|
||||
[app.util.debug :as dbg]
|
||||
[beicon.v2.core :as rx]
|
||||
[rumext.v2 :as mf]))
|
||||
|
@ -657,6 +656,7 @@
|
|||
|
||||
(mf/defc viewport
|
||||
[props]
|
||||
(if ^boolean render.wasm/enabled?
|
||||
[:& viewport.wasm/viewport props]
|
||||
[:& viewport-classic props]))
|
||||
(let [wasm-renderer-enabled? (features/use-feature "render-wasm/v1")]
|
||||
(if ^boolean wasm-renderer-enabled?
|
||||
[:& viewport.wasm/viewport props]
|
||||
[:& viewport-classic props])))
|
||||
|
|
|
@ -11,15 +11,12 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.types.shape.impl :as ctsi]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.features :as features]
|
||||
[app.main.store :as st]
|
||||
[app.util.object :as obj]
|
||||
[promesa.core :as p]))
|
||||
|
||||
(def enabled?
|
||||
(features/active-feature? @st/state "render-wasm/v1"))
|
||||
|
||||
(set! app.common.types.shape.impl/enabled-wasm-ready-shape enabled?)
|
||||
(defn initialize
|
||||
[enabled?]
|
||||
(set! app.common.types.shape.impl/enabled-wasm-ready-shape enabled?))
|
||||
|
||||
(defonce internal-module #js {})
|
||||
|
||||
|
@ -139,16 +136,18 @@
|
|||
(obj/set! js/window "shape_list" (fn [] ((unchecked-get internal-module "_shape_list"))))))
|
||||
|
||||
(defonce module
|
||||
(->> (js/dynamicImport "/js/render_wasm.js")
|
||||
(p/mcat (fn [module]
|
||||
(let [default (unchecked-get module "default")]
|
||||
(default))))
|
||||
(p/fmap (fn [module]
|
||||
(set! internal-module module)
|
||||
true))
|
||||
(p/merr (fn [cause]
|
||||
(js/console.error cause)
|
||||
(p/resolved false)))))
|
||||
(if (exists? js/dynamicImport)
|
||||
(->> (js/dynamicImport "/js/render_wasm.js")
|
||||
(p/mcat (fn [module]
|
||||
(let [default (unchecked-get module "default")]
|
||||
(default))))
|
||||
(p/fmap (fn [module]
|
||||
(set! internal-module module)
|
||||
true))
|
||||
(p/merr (fn [cause]
|
||||
(js/console.error cause)
|
||||
(p/resolved false))))
|
||||
(p/resolved false)))
|
||||
|
||||
(set! app.common.types.shape.impl/wasm-create-shape create-shape)
|
||||
(set! app.common.types.shape.impl/wasm-use-shape use-shape)
|
||||
|
|
Loading…
Reference in a new issue