Add libra maps example, modify sci config based on @borkdude suggestions.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Oly 2023-08-16 14:05:43 +01:00
parent cb2938c850
commit 00bc690eb4
6 changed files with 48 additions and 37 deletions

View File

@ -12,7 +12,7 @@ steps:
user: root user: root
commands: commands:
#- cp resources/public/rename-me-index.html resources/public/index.html #- cp resources/public/rename-me-index.html resources/public/index.html
- clojure -Mbuild-dev release app - clojure -Mbuild release app
#- clj -A:prod #- clj -A:prod
- name: deploy-site - name: deploy-site

View File

@ -34,8 +34,7 @@
datascript/datascript {:mvn/version "1.5.1"}} datascript/datascript {:mvn/version "1.5.1"}}
:paths ["src" "resources"] :paths ["src" "resources"]
:aliases {:prod {:main-opts ["-m" "figwheel.main" "-bo" "dev"]} :aliases {:build {:extra-deps {thheller/shadow-cljs {:mvn/version "2.23.3"}
:build-dev {:extra-deps {thheller/shadow-cljs {:mvn/version "2.23.3"}
#_#_binaryage/devtools {:mvn/version "1.0.7"}} #_#_binaryage/devtools {:mvn/version "1.0.7"}}
:main-opts ["-m" "shadow.cljs.devtools.cli"]} :main-opts ["-m" "shadow.cljs.devtools.cli"]}
} }

View File

@ -4,6 +4,13 @@ Future Content
- Dynamic html with macro for frontend generation on build. - Dynamic html with macro for frontend generation on build.
- Complete frontend backend example wth ring retit reagent - Complete frontend backend example wth ring retit reagent
clj -m figwheel.main --build dev --repl #+BEGIN_SRC sh
npm install
#+END_SRC
#+BEGIN_SRC sh
clojure -Mbuild-dev watch app
#+END_SRC
https://www.clojuriststogether.org/news/call-for-new-proposals.-june-survey-results./ https://www.clojuriststogether.org/news/call-for-new-proposals.-june-survey-results./

View File

@ -18,8 +18,8 @@ npx shadow-cljs watch app
Alternatively jack into the project from your ide. Alternatively jack into the project from your ide.
#+END_SRC #+END_SRC
* Google Maps
* Google Maps
Below is an example of using google maps, it pulls in the library directly you could alternatively use an npm dependency. Below is an example of using google maps, it pulls in the library directly you could alternatively use an npm dependency.
You will need to provide your own api key, the examples use no api key and render a warning so paste in your google api key to make this work. You will need to provide your own api key, the examples use no api key and render a warning so paste in your google api key to make this work.
@ -80,7 +80,7 @@ You will need to provide your own api key, the examples use no api key and rende
} }
#+END_SRC #+END_SRC
#+BEGIN_SRC clojurescript :exports none :tangle src/clojure_demo/core.cljs #+BEGIN_SRC json :exports none :results output :tangle src/clojure_demo/core.cljs
(ns clojure-demo.core (ns clojure-demo.core
(:require (:require
["react-dom/client" :refer [createRoot]] ["react-dom/client" :refer [createRoot]]
@ -128,7 +128,7 @@ In this example we render google maps using core async, async go blocks drop typ
:title "test marker 2" :title "test marker 2"
:position {:lng 131.031 :lat -25.344}}) "marker 2"))) :position {:lng 131.031 :lat -25.344}}) "marker 2")))
(fn [] (fn []
[:div#google-map-async.m-4 [:div#google-map-async.m-auto
{:style {:width "400px" :height "400px"} :ref #(reset! map-element %)} {:style {:width "400px" :height "400px"} :ref #(reset! map-element %)}
"core async map here"]))) "core async map here"])))
#+END_SRC #+END_SRC
@ -160,7 +160,7 @@ Shadow CLJS has its one js-await macro we can use in the following fashion, here
nil)))) nil))))
(fn [] (fn []
[:div#google-map-js-await.m-4 [:div#google-map-js-await.m-auto
{:style {:width "400px" :height "400px"} :ref #(reset! map-element %)} {:style {:width "400px" :height "400px"} :ref #(reset! map-element %)}
"shadow js-await map here"]))) "shadow js-await map here"])))
@ -173,6 +173,7 @@ Shadow CLJS has its one js-await macro we can use in the following fashion, here
An example using promesa to render a google map. An example using promesa to render a google map.
#+BEGIN_SRC clojurescript :results output :tangle src/clojure_demo/core.cljs #+BEGIN_SRC clojurescript :results output :tangle src/clojure_demo/core.cljs
(defn google-map-promesa [] (defn google-map-promesa []
(let [map-element (reagent/atom nil)] (let [map-element (reagent/atom nil)]
(load-google-maps-script "") (load-google-maps-script "")
@ -196,7 +197,7 @@ An example using promesa to render a google map.
(fn [] (fn []
[:div#google-map-promesa.m-4 [:div#google-map-promesa.m-auto
{:style {:width "400px" :height "400px"} :ref #(reset! map-element %)} {:style {:width "400px" :height "400px"} :ref #(reset! map-element %)}
"promesa map here"]))) "promesa map here"])))
@ -224,6 +225,7 @@ An example using promesa to render a google map.
* LibraMaps * LibraMaps
Create a dummy function to load the js dynamically, this could be imported in other ways like npm.
#+BEGIN_SRC clojurescript :results value :tangle src/clojure_demo/core.cljs #+BEGIN_SRC clojurescript :results value :tangle src/clojure_demo/core.cljs
(defn load-libra-maps [] (defn load-libra-maps []
(let [script (.createElement js/document "script")] (let [script (.createElement js/document "script")]
@ -233,33 +235,23 @@ An example using promesa to render a google map.
(load-libra-maps) (load-libra-maps)
#+END_SRC #+END_SRC
We use =:ref= to grab a reference and call our function when it is created we can then get elements id and construct our map.
To customize see https://maplibre.org/maplibre-gl-js/docs/
https://maplibre.org/maplibre-gl-js/docs/
#+BEGIN_SRC clojurescript :results output :tangle src/clojure_demo/core.cljs #+BEGIN_SRC clojurescript :results output :tangle src/clojure_demo/core.cljs
(defn libra-map-promesa [] (defn libra-map-promesa []
(let [map-element (reagent/atom nil)]
(load-libra-maps) (load-libra-maps)
(let [create-map (fn map-element [element]
(when-let
[lMap (.-id @map-element)
]
(new js/maplibregl.Map (new js/maplibregl.Map
(clj->js {:container "libra-map" (clj->js {:container (.-id element) #_"libra-map"
:style "https://demotiles.maplibre.org/style.json" :style "https://demotiles.maplibre.org/style.json"
:zoom 1})) :zoom 1})))]
)
(fn [] (fn []
[:div#libra-map.m-4 [:div#libra-map.m-auto
{:style {:width "400px" :height "400px"} {:style {:width "400px" :height "400px"}
:ref #(reset! map-element %)} :ref create-map #_(reset! map-element %)}
(str (.-id @map-element)) "libra map here"])))
"libra map here"])
)
)
[libra-map-promesa] [libra-map-promesa]

View File

@ -67,6 +67,7 @@ Reagent is a popular react wrapper in the clojurescript it greatly simplify buil
npx install npx install
* Launch shadow-cljs watch for source code changes * Launch shadow-cljs watch for source code changes
#+BEGIN_SRC sh
npx shadow-cljs watch app npx shadow-cljs watch app
#+END_SRC #+END_SRC
@ -133,6 +134,11 @@ Form two components are used so we can track local state of a component, this is
*** Example Click counter component *** Example Click counter component
#+BEGIN_SRC clojurescript :results output :tangle src/clojure_demo/core.cljs #+BEGIN_SRC clojurescript :results output :tangle src/clojure_demo/core.cljs
(ns example
(:require
[reagent.core :as r]
[reagent.dom.server :as rdom]))
(defn my-component [title starting-value] (defn my-component [title starting-value]
(let [local-state (reagent/atom starting-value)] (let [local-state (reagent/atom starting-value)]
(fn [title] (fn [title]

View File

@ -20,16 +20,17 @@
[clojure.data.xml :as xml] [clojure.data.xml :as xml]
[clojure.string :as str] [clojure.string :as str]
[honey.sql :as sql] [honey.sql :as sql]
[promesa.core :as promesa]
[honey.sql.helpers :as sqlh] [honey.sql.helpers :as sqlh]
[reagent.core :as reagent] [reagent.core :as reagent]
[reitit.coercion.spec :as rss] [reitit.coercion.spec :as rss]
[reitit.frontend :as rf] [reitit.frontend :as rf]
[reitit.frontend.easy :as rfe] [reitit.frontend.easy :as rfe]
[reitit.frontend.history :refer [ignore-anchor-click?]] [reitit.frontend.history :refer [ignore-anchor-click?]]
[sci.core :as sci]
[sci.configs.funcool.promesa :as sci-promesa] [sci.configs.funcool.promesa :as sci-promesa]
[sci.configs.reagent.reagent :as sci-reagent] [sci.configs.reagent.reagent :as sci-reagent]
[sci.configs.tonsky.datascript :as sci-datascript] [sci.configs.tonsky.datascript :as sci-datascript]
[sci.core :as sci]
[clojure-demo.routes :refer [site-data routes]] [clojure-demo.routes :refer [site-data routes]]
[clojure-demo.sitemap :as sm #_#_:refer [spit-pwa-sitemap]] [clojure-demo.sitemap :as sm #_#_:refer [spit-pwa-sitemap]]
[tick.core :as t]) [tick.core :as t])
@ -79,15 +80,21 @@
(sci/init (sci/init
{:classes {'js js/globalThis :allow :all} {:classes {'js js/globalThis :allow :all}
:features #{:cljs} :features #{:cljs}
:aliases {'promesa 'promesa.core
'reagent 'reagent.core}
:namespaces :namespaces
{'reagent sci-reagent/reagent-namespace {'reagent.core sci-reagent/reagent-namespace
'promesa sci-promesa/promesa-namespace 'reagent.ratom sci-reagent/reagent-ratom-namespace
;'reagent.dom.server sci-reagent-server/namespaces
'promesa.core sci-promesa/promesa-namespace
'datascript.core sci-datascript/core-namespace
'datascript.db sci-datascript/db-namespace
;'h {'html (sci/copy-var h/html hc-ns)} ;'h {'html (sci/copy-var h/html hc-ns)}
;'async {'go (sci/copy-var async/go async-ns)} ;'async {'go (sci/copy-var async/go async-ns)}
;'shadow {'js-await (sci/copy-var js-await shadow-ns)} ;'shadow {'js-await (sci/copy-var js-await shadow-ns)}
'shadow {'js-await (sci/copy-var my-js-await shadow-ns)} 'shadow {'js-await (sci/copy-var my-js-await shadow-ns)}
;'async-in {'<p! (sci/copy-var async-in/<p! async-in-ns)} ;'async-in {'<p! (sci/copy-var async-in/<p! async-in-ns)}
'd sci-datascript/core-namespace
'tick {'format (sci/copy-var t/format tick-ns) 'tick {'format (sci/copy-var t/format tick-ns)
'zoned-date-time (sci/copy-var t/zoned-date-time tick-ns)} 'zoned-date-time (sci/copy-var t/zoned-date-time tick-ns)}
'xml {'emit-str (sci/copy-var xml/emit-str xml-ns) 'xml {'emit-str (sci/copy-var xml/emit-str xml-ns)