diff --git a/scripts/dist.clj b/scripts/dist.clj index fa94adf42..38fea0ee7 100644 --- a/scripts/dist.clj +++ b/scripts/dist.clj @@ -5,7 +5,7 @@ (let [start (System/nanoTime)] (b/build (b/inputs "src" "vendor") - {:main 'uxbox.core + {:main 'uxbox.main :parallel-build false :warnings {:ns-var-clash false} :output-to "resources/public/js/main.js" diff --git a/scripts/figwheel.clj b/scripts/figwheel.clj index dbd26cf90..22933bf9c 100644 --- a/scripts/figwheel.clj +++ b/scripts/figwheel.clj @@ -5,24 +5,49 @@ {:figwheel-options {:css-dirs ["resources/public/css"] :server-port 3449 :server-ip "0.0.0.0"} - :build-ids ["dev"] + :build-ids ["main", "preview"] :all-builds - [{:id "dev" + [{:id "main" :figwheel {:on-jsload "uxbox.ui/init"} :source-paths ["src" "vendor"] :compiler - {:main 'uxbox.core + {:main 'uxbox.main :asset-path "js" :parallel-build false :optimizations :none + ;; :closure-defines {"uxbox.repo.core.url" + ;; "https://test.uxbox.io/api"} :closure-defines {"uxbox.repo.core.url" - "https://test.uxbox.io/api"} + "http://localhost:6060/api"} :warnings {:ns-var-clash false} :pretty-print true :language-in :ecmascript6 :language-out :ecmascript5 :output-to "resources/public/js/main.js" :output-dir "resources/public/js" - :verbose true}}]}) + :verbose true}} -(ra/cljs-repl "dev") + #_{:id "preview" + ;; :figwheel {:on-jsload "uxbox.ui/init"} + :source-paths ["src" "vendor"] + :compiler + {:main 'uxbox.core + :asset-path "js" + :parallel-build false + :optimizations :none + ;; :closure-defines {"uxbox.repo.core.url" + ;; "https://test.uxbox.io/api"} + :closure-defines {"uxbox.repo.core.url" + "http://localhost:6060/api"} + :warnings {:ns-var-clash false} + :pretty-print true + :language-in :ecmascript6 + :language-out :ecmascript5 + :output-to "resources/public/preview/js/main.js" + :output-dir "resources/public/preview/js" + :verbose true}} + + +]}) + +(ra/cljs-repl "main") diff --git a/src/uxbox/core.cljs b/src/uxbox/main.cljs similarity index 80% rename from src/uxbox/core.cljs rename to src/uxbox/main.cljs index 08d7e87ec..3deb1dc4e 100644 --- a/src/uxbox/core.cljs +++ b/src/uxbox/main.cljs @@ -5,11 +5,9 @@ ;; Copyright (c) 2015-2016 Andrey Antukh ;; Copyright (c) 2015-2016 Juan de la Cruz -(ns uxbox.core +(ns uxbox.main (:require-macros [uxbox.util.syntax :refer [define-once]]) - (:require [beicon.core :as rx] - [uxbox.state :as st] - [uxbox.router :as rt] + (:require [uxbox.state :as st] [uxbox.rstore :as rs] [uxbox.ui :as ui])) @@ -17,5 +15,5 @@ (define-once :setup (st/init) - (rt/init) + (ui/init-routes) (ui/init)) diff --git a/src/uxbox/router.cljs b/src/uxbox/router.cljs index 2a687b167..a8d578ffe 100644 --- a/src/uxbox/router.cljs +++ b/src/uxbox/router.cljs @@ -14,7 +14,8 @@ (enable-console-print!) -(defonce +router+ (volatile! nil)) +(defonce +router+ nil) +(defonce +routes+ nil) ;; --- Update Location (Event) @@ -42,7 +43,7 @@ (let [loc (merge {:handler id} (when params {:route-params params}))] - (bidi.router/set-location! @+router+ loc)))) + (bidi.router/set-location! +router+ loc)))) (defn navigate ([id] (navigate id nil)) @@ -50,40 +51,15 @@ {:pre [(keyword? id)]} (Navigate. id params))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Router declaration -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(def ^:private page-route - [[bidi/uuid :project-uuid] "/" [bidi/uuid :page-uuid]]) - -(def routes - ["/" [["auth/login" :auth/login] - ["auth/register" :auth/register] - ["auth/recovery/request" :auth/recovery-request] - [["auth/recovery/token/" :token] :auth/recovery] - - ["settings/" [["profile" :settings/profile] - ["password" :settings/password] - ["notifications" :settings/notifications]]] - - ["dashboard/" [["projects" :dashboard/projects] - ["elements" :dashboard/elements] - ["icons" :dashboard/icons] - ["images" :dashboard/images] - ["colors" :dashboard/colors]]] - ["workspace/" [[page-route :workspace/page]]]]]) +;; --- Public Api (defn init - [] + [routes] (let [opts {:on-navigate #(rs/emit! (update-location %)) :default-location {:handler :auth/login}} router (bidi.router/start-router! routes opts)] - (vreset! +router+ router))) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Public Api -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (set! +routes+ routes) + (set! +router+ router))) (defn go "Redirect the user to other url." @@ -94,6 +70,6 @@ "Given a location handler and optional parameter map, return the URI for such handler and parameters." ([id] - (bidi/path-for routes id)) + (bidi/path-for +routes+ id)) ([id params] - (apply bidi/path-for routes id (into [] (mapcat (fn [[k v]] [k v])) params)))) + (apply bidi/path-for +routes+ id (into [] (mapcat (fn [[k v]] [k v])) params)))) diff --git a/src/uxbox/ui.cljs b/src/uxbox/ui.cljs index fd3ecbf61..9164539d7 100644 --- a/src/uxbox/ui.cljs +++ b/src/uxbox/ui.cljs @@ -7,13 +7,14 @@ (ns uxbox.ui (:require [sablono.core :as html :refer-macros [html]] + [bidi.bidi :as bidi] [promesa.core :as p] [beicon.core :as rx] [goog.dom :as gdom] [rum.core :as rum] [lentes.core :as l] [uxbox.state :as st] - [uxbox.router :as r] + [uxbox.router :as rt] [uxbox.rstore :as rs] [uxbox.locales :refer (tr)] [uxbox.data.projects :as dp] @@ -78,7 +79,7 @@ location (:id route) params (:params route)] (if (and (restricted? location) (not auth)) - (do (p/schedule 0 #(r/go :auth/login)) nil) + (do (p/schedule 0 #(rt/go :auth/login)) nil) (case location :auth/login (auth/login-page) :auth/register (auth/register-page) @@ -125,8 +126,34 @@ :name "loader" :mixins [rum/reactive mx/static]})) +;; --- Routes + +(def ^:private page-route + [[bidi/uuid :project-uuid] "/" [bidi/uuid :page-uuid]]) + +(def routes + ["/" [["auth/login" :auth/login] + ["auth/register" :auth/register] + ["auth/recovery/request" :auth/recovery-request] + [["auth/recovery/token/" :token] :auth/recovery] + + ["settings/" [["profile" :settings/profile] + ["password" :settings/password] + ["notifications" :settings/notifications]]] + + ["dashboard/" [["projects" :dashboard/projects] + ["elements" :dashboard/elements] + ["icons" :dashboard/icons] + ["images" :dashboard/images] + ["colors" :dashboard/colors]]] + ["workspace/" [[page-route :workspace/page]]]]]) + ;; --- Main Entry Point +(defn init-routes + [] + (rt/init routes)) + (defn init [] (let [app-dom (gdom/getElement "app")