diff --git a/frontend/src/app/main.cljs b/frontend/src/app/main.cljs index 522715331..3cbbe0d70 100644 --- a/frontend/src/app/main.cljs +++ b/frontend/src/app/main.cljs @@ -105,8 +105,7 @@ (rx/map deref) (rx/filter du/is-authenticated?) (rx/take 1) - (rx/map #(ws/initialize)) - (rx/tap #(plugins/init!))))))) + (rx/map #(ws/initialize))))))) (defn ^:export init [] @@ -116,7 +115,8 @@ (cur/init-styles) (thr/init!) (init-ui) - (st/emit! (initialize))) + (st/emit! (plugins/initialize) + (initialize))) (defn ^:export reinit ([] diff --git a/frontend/src/app/plugins.cljs b/frontend/src/app/plugins.cljs index 551591b4a..36346de27 100644 --- a/frontend/src/app/plugins.cljs +++ b/frontend/src/app/plugins.cljs @@ -16,15 +16,20 @@ [beicon.v2.core :as rx] [potok.v2.core :as ptk])) -(defn init! +(defn init-plugins-runtime! [] - (->> st/stream - (rx/filter (ptk/type? ::features/initialize)) - (rx/take 1) - ;; We need to wait to the init event to finish - (rx/observe-on :async) - (rx/subs! - (fn [] - (when (features/active-feature? @st/state "plugins/runtime") - (when-let [init-runtime (obj/get global "initPluginsRuntime")] - (init-runtime (fn [plugin-id] (api/create-context plugin-id))))))))) + (when-let [init-runtime (obj/get global "initPluginsRuntime")] + (init-runtime (fn [plugin-id] (api/create-context plugin-id))))) + +(defn initialize + [] + (ptk/reify ::initialize + ptk/WatchEvent + (watch [_ _ stream] + (->> stream + (rx/filter (ptk/type? ::features/initialize)) + (rx/observe-on :async) + (rx/filter #(features/active-feature? @st/state "plugins/runtime")) + (rx/take 1) + (rx/tap init-plugins-runtime!) + (rx/ignore))))) diff --git a/frontend/src/features.cljs b/frontend/src/features.cljs index 5b111096f..0fa5ec46b 100644 --- a/frontend/src/features.cljs +++ b/frontend/src/features.cljs @@ -27,6 +27,6 @@ (defn ^:export plugins [] (st/emit! (features/enable-feature "plugins/runtime")) - (plugins/init!) + (plugins/init-plugins-runtime!) nil)