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 6cf1cb0306
6 changed files with 52 additions and 30 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

@ -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]]
@ -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 "")
@ -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,34 +235,35 @@ An example using promesa to render a google map.
(load-libra-maps) (load-libra-maps)
#+END_SRC #+END_SRC
Get a references to the element and store in =map-element= add a watch to detect when the value changes, we can then create the map using the elements id.
When using =:ref= you need to remember this is an atom not a reagent atom, else you will get extra renders.
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)] (let [map-element (atom nil)]
(load-libra-maps) (load-libra-maps)
(add-watch
(when-let map-element
[lMap (.-id @map-element) :create-map
] (fn [key atom old-state new-state]
(new js/maplibregl.Map (when @map-element
(clj->js {:container "libra-map" (let [lMap (.-id @map-element)]
:style "https://demotiles.maplibre.org/style.json" (new js/maplibregl.Map
:zoom 1})) (clj->js {:container (.-id @map-element) #_"libra-map"
) :style "https://demotiles.maplibre.org/style.json"
:zoom 1}))))))
(fn []
(fn [] [:div#libra-map.m-4
[:div#libra-map.m-4 {:style {:width "400px" :height "400px"}
{:style {:width "400px" :height "400px"} :ref #(reset! map-element %)}
:ref #(reset! map-element %)} (str @map-element)
(str (.-id @map-element)) "libra map here"])
"libra map here"])
) )
) )
[libra-map-promesa] [libra-map-promesa]
#+END_SRC #+END_SRC

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)