Skip to content

Commit

Permalink
cljs-services added
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Apr 18, 2024
1 parent 26cf7ce commit 96be97d
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 96 deletions.
20 changes: 1 addition & 19 deletions demo/resources/demo.edn
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
{:build {:disabled-extensions #{; extensions using sci-configs will not work in webly.
"reagent" "re-frame"
"funcool-promesa"
"applied-science.js-interop"
; webly2 is now in webly. needs to be removed from ui-repl.
"webly2"
"ui-repl"
"cljs-ajax"
"goog.string"
"clojure.walk"
"clojure.string"
"goog.object"
}}
{:build {:disabled-extensions #{}}

:spa {:title "Webly Demo"
:start-user-app [:demo/start]
Expand All @@ -21,12 +9,6 @@

:google-analytics {:enabled false} ; set to false to disable google-analytics tracking.

:timbre/cljs {:min-level [[#{"org.eclipse.jetty.*"} :info]
[#{"modular.ws.*"} :info]
[#{"webly.user.*"} :info]
[#{"webly.*"} :info]
[#{"*"} :debug]]}

:timbre/clj {:min-level [[#{"org.eclipse.jetty.*"} :warn]
[#{"*"} :info]]
:appenders {:default {:type :console-color}
Expand Down
1 change: 1 addition & 0 deletions demo/resources/ext/demo-webly-lazy.edn
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
;demo.time
;demo.events
]
:depends-on #{:ui-repl}
:cljs-ns-bindings {'demo.page {;'main demo.page.main/main
'party demo.page.party/party-page
'job demo.page.job/job
Expand Down
2 changes: 1 addition & 1 deletion demo/resources/ext/demo-webly.edn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"save" :demo/save-non-existing ; there is no handler defined for this on purpose
}

:cljs-service {:init-fn demo.service/start}
:cljs-service {:start-fn demo.service/start}


:theme {:available {:emoji {true ["@icon/fontisto-emoji/fontisto-emoji.css"]
Expand Down
2 changes: 1 addition & 1 deletion demo/resources/ext/hello.edn
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
snippets.bye]
:cljs-ns-bindings {'snippets.hello {'hello snippets.hello/hello
'start snippets.hello/start}}
:cljs-service {:init-fn snippets.hello/start}}
:cljs-service {:start-fn snippets.hello/start}}
4 changes: 2 additions & 2 deletions demo/src/demo/service.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
(:require
[taoensso.timbre :as timbre :refer [info warn]]))

(defn start [mode]
(info "demo.service/start mode: " mode)
(defn start [config]
(info "demo.service/start config: " config)
nil)
4 changes: 2 additions & 2 deletions demo/src/snippets/hello.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
(defn hello []
[:p "hello, world!"])

(defn start [mode]
(println "starting snippets.hello service mode: " mode)
(defn start [config]
(println "starting snippets.hello service mode: " config)
nil)
2 changes: 1 addition & 1 deletion spa/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
org.pinkgorilla/permission {:mvn/version "0.0.15"}
org.pinkgorilla/ui-tailwind {:mvn/version "0.0.5"}
org.pinkgorilla/ui-bidi {:mvn/version "0.1.33"}
org.pinkgorilla/ui-dialog-keybindings {:mvn/version "0.1.8"}
org.pinkgorilla/ui-dialog-keybindings {:mvn/version "0.1.10"}
org.pinkgorilla/css-theme {:mvn/version "0.1.5"}}
:aliases
{:cljfmt {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
Expand Down
9 changes: 2 additions & 7 deletions spa/src/webly/spa.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
[frontend.page]
[webly.spa.service.config :refer [start-config]]
[webly.spa.service :refer [start-cljs-services]]
[webly.spa.service.keybindings :refer [start-keybindings]]
[webly.spa.service.theme :refer [start-theme]]
[webly.spa.service.ga :refer [start-ga]]
[webly.spa.service.bidi :refer [start-bidi]]
[webly.spa.service.ws :refer [start-ws]]
[webly.spa.service.timbre :refer [timbre-config!]]
;[webly.spa.service.timbre :refer [timbre-config!]]
; webly
[webly.build.lazy]
[webly.module.build :refer [webly-resolve]]
Expand Down Expand Up @@ -76,19 +75,15 @@
cljs-services (get-in db [:config :cljs-services])
start-user-app (-> spa :start-user-app)
frontend-routes (get-in db [:config :frontend-routes])
theme (get-in db [:config :theme])
keybindings (get-in db [:config :keybindings])
timbre-cljs (get-in db [:config :timbre/cljs])]
theme (get-in db [:config :theme])]
(info "webly config after-load")
(remove-spinner)
(dispatch [:webly/status :configuring-app])

; services
(start-cljs-services cljs-services)
(timbre-config! timbre-cljs)
(start-bidi frontend-routes)
(start-ga)
(start-keybindings keybindings)
(start-theme theme)
(if static?
(warn "websockets are deactivated in static mode.")
Expand Down
10 changes: 3 additions & 7 deletions spa/src/webly/spa/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,21 @@
{:api (get-api-routes exts)
:app (get-cljs-routes exts)})

(defn configure [{:keys [spa google-analytics prefix keybindings settings]
(defn configure [{:keys [spa google-analytics prefix settings]
:or {spa {}
keybindings default/keybindings
settings default/settings
google-analytics default/google-analytics
prefix default/prefix}
:as config} exts]
(let [timbre-cljs (or (:timbre/cljs config) default/timbre-cljs)
routes (get-routes exts)
(let [routes (get-routes exts)
theme (theme/get-theme-config exts)
spa (merge default/spa spa)
frontend-config {:prefix prefix
:spa spa
:frontend-routes (:app routes)
:theme theme
:keybindings keybindings
:settings settings
:timbre/cljs timbre-cljs
:cljs-services (cljs-services exts)
:cljs-services (cljs-services config exts)
:google-analytics google-analytics}]
{:routes routes
:frontend-config frontend-config}))
Expand Down
15 changes: 0 additions & 15 deletions spa/src/webly/spa/default.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@
{:enabled false ; set to false to disable google-analytics tracking.
:id "UA-154548494-1" ; not a secret
})

(def keybindings
[; https://github.com/piranha/keybind
; shift, ctrl, alt, win, cmd, defmod, "left" "right"
; "meta-shift-l" "alt-shift-p" "ctrl-shift-left" "ctrl-shift-right"
{:kb "alt-g k" :handler [:palette/show] :desc "Keybindings dialog"}
{:kb "esc" :handler [:modal/close] :desc "Dialog Close"} ; for ALL dialogs!
{:kb "alt-g t" :handler [:reframe10x-toggle] :desc "10x visibility toggle"}])

(def timbre-cljs
{:min-level [[#{"pinkgorilla.nrepl.client.connection"} :info]
[#{"org.eclipse.jetty.*"} :info]
[#{"webly.*"} :info]
[#{"*"} :info]]})

(def settings {:use-localstorage false})

(def shadow
Expand Down
26 changes: 21 additions & 5 deletions spa/src/webly/spa/service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
(:require
[extension :refer [write-service get-extensions]]))

;; Extension config
;; discovery

(defn cljs-service? [{:keys [cljs-service]}]
cljs-service)

(defn select-service [{:keys [cljs-service name]}]
{:name name
:cljs-service cljs-service})
(assoc cljs-service :name name))

(defn- get-cljs-services [exts]
(->> (get-extensions exts {:name "unknown"
Expand All @@ -18,7 +17,24 @@
(map select-service)
(into [])))

(defn cljs-services [exts]
(let [services (get-cljs-services exts)]
;; config

(defn service-config [config exts {:keys [name config-fn default-config] :as service}]
(if config-fn
(let [configure (requiring-resolve config-fn)]
(assoc service :config (configure name config exts default-config)))
(assoc service :config nil)))

(defn cljs-services [config exts]
(let [services (->> (get-cljs-services exts)
(map #(service-config config exts %)))]
(write-service exts :cljs-services services)
services))

;; simple-config

(defn cljs-config-simple [module-name config _exts default-config]
(let [module-name (if (string? module-name)
(keyword module-name)
module-name)]
(or (get config module-name) default-config)))
21 changes: 9 additions & 12 deletions spa/src/webly/spa/service.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@
(:require
[taoensso.timbre :refer-macros [info warn]]
[promesa.core :as p]
[webly.spa.mode :refer [get-mode]]
[webly.spa.resolve :refer [get-resolver]]))

(defn start-cljs-service [resolver mode {:keys [name cljs-service]}]
(let [{:keys [init-fn]} cljs-service
init-p (resolver init-fn)]
(warn "starting cljs-service name: " name " init-fn: " init-fn)
(-> init-p
(p/then (fn [init]
(init mode))))))
(defn start-cljs-service [resolver {:keys [name config start-fn]}]
(let [start-p (resolver start-fn)]
(warn "starting cljs-service name: " name "start-fn: " start-fn)
(-> start-p
(p/then (fn [start]
(start config))))))

(defn start-cljs-services [services]
;[{:name "demo-webly", :cljs-service {:init-fn demo.service/start}}
; {:name "hello", :cljs-service {:init-fn snippets.hello/start}}]
(let [resolver (get-resolver)
mode (get-mode)]
(warn "starting cljs services: " services " mode: " mode)
(doall (map #(start-cljs-service resolver mode %) services))))
(let [resolver (get-resolver)]
(warn "starting cljs services: " (map :name services))
(doall (map #(start-cljs-service resolver %) services))))

13 changes: 0 additions & 13 deletions spa/src/webly/spa/service/keybindings.cljs

This file was deleted.

7 changes: 0 additions & 7 deletions spa/src/webly/spa/service/timbre.cljs

This file was deleted.

2 changes: 1 addition & 1 deletion webly/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
org.pinkgorilla/websocket {:mvn/version "0.0.9"}
org.pinkgorilla/spa {:local/root "../spa" :deps/manifest :deps}
org.pinkgorilla/permission {:mvn/version "0.0.15"}
org.pinkgorilla/timbre {:mvn/version "0.0.4"}}
org.pinkgorilla/timbre {:mvn/version "0.0.6"}}
:aliases
{; https://github.com/weavejester/cljfmt
:cljfmt {:extra-deps {cljfmt/cljfmt {:mvn/version "0.9.2"}}
Expand Down
5 changes: 2 additions & 3 deletions webly/src/webly/module/build.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@
(defn add-lazy-modules
;"adds modules to the build. Needs to be called from the cljs-app."
[]
(println "add-lazy-modules .....")
;(println "add-lazy-modules .....")
(let [modules (get-lazy-modules)
modules-map (module-list->map modules)
ns-list (get-lazy-ns)
;loadable-spec
]
(reset! lazy-modules-a modules-map)
(reset! lazy-ns-a ns-list)
(println "compile-time lazy-ns-a: " @lazy-ns-a)

;(println "compile-time lazy-ns-a: " (sort @lazy-ns-a))
:ok))

(defn print-build-summary []
Expand Down

0 comments on commit 96be97d

Please sign in to comment.