diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml index cd8cddf..8208402 100644 --- a/.gitlab-ci.yaml +++ b/.gitlab-ci.yaml @@ -16,7 +16,7 @@ pages: image: clojure:tools-deps-alpine script: - cd ./reagent-reitit-demo/ - - clj -m figwheel.main --build dev --repl + - clj -M -m figwheel.main --build dev --repl # script: # - python setup.py develop diff --git a/deps.edn b/deps.edn index e1b285f..20671a4 100644 --- a/deps.edn +++ b/deps.edn @@ -1,5 +1,6 @@ {:deps {org.clojure/clojure {:mvn/version "1.10.0"} - org.clojure/clojurescript {:mvn/version "1.10.764"} + ;; version updates seem to break the code eval. + org.clojure/clojurescript {:mvn/version "1.10.740"} com.github.seancorfield/honeysql {:mvn/version "2.2.891"} olymk2/cl-org {:git/url "https://gitlab.com/olymk2/cl-org.git" :sha "9f29b9a3989bbd0f843e2f025d91cc7b92e818a4"} diff --git a/dsl-demo/readme.org b/dsl-demo/readme.org index 1e7af17..1821781 100644 --- a/dsl-demo/readme.org +++ b/dsl-demo/readme.org @@ -81,6 +81,7 @@ In this example we create a select but with no from format will still give you a You use multiple functions to combine the parts, below we add the missing from. #+BEGIN_SRC clojure + (sql/format (sqlh/from (sqlh/select :first_name :last_name :email) :users)) diff --git a/readme.org b/readme.org new file mode 100644 index 0000000..06a82a2 --- /dev/null +++ b/readme.org @@ -0,0 +1 @@ +clj -m figwheel.main --build dev --repl \ No newline at end of file diff --git a/reagent-reitit-demo/deps.edn b/reagent-reitit-demo/deps.edn index 3c0105e..7893f09 100644 --- a/reagent-reitit-demo/deps.edn +++ b/reagent-reitit-demo/deps.edn @@ -1,14 +1,16 @@ {:deps {org.clojure/clojure {:mvn/version "1.10.0"} - org.clojure/clojurescript {:mvn/version "1.10.764"} + ;; version updates seem to break the code eval. +;; org.clojure/clojurescript {:mvn/version "1.10.740"} + org.clojure/clojurescript {:mvn/version "1.11.60"} ;;ajax requests - cljs-ajax {:mvn/version "0.8.1"} + cljs-ajax/cljs-ajax {:mvn/version "0.8.1"} ;; react - reagent {:mvn/version "0.9.1"} - reagent-utils {:mvn/version "0.3.3"} + reagent/reagent {:mvn/version "1.1.1"} + reagent-utils/reagent-utils {:mvn/version "0.3.3"} olymk2/cl-org {:git/url "https://gitlab.com/olymk2/cl-org.git" - :sha "2bb6f41b317749ea3467987ea57ee7807b59d921"} + :sha "528e8125afcac5d7664aac80f7fbba12dd0f5d98"} ;;routing metosin/reitit {:mvn/version "0.5.10"} metosin/reitit-spec {:mvn/version "0.5.10"} @@ -16,10 +18,16 @@ ;; interactive code snippets ;;viebel/klipse {:mvn/version "7.10.4"} - viebel/klipse {:mvn/version "7.9.1"} - datascript {:mvn/version "1.0.0"} + com.github.seancorfield/honeysql {:mvn/version "2.4.1026"} + + viebel/klipse {:mvn/version "7.11.4"} + org.babashka/sci {:mvn/version "0.7.39"} + org.babashka/sci.configs {:git/url "https://github.com/babashka/sci.configs" + :sha "33bd51e53700b224b4cb5bda59eb21b62f962745"} + datascript/datascript {:mvn/version "1.3.15"} - com.bhauman/figwheel-main {:mvn/version "0.2.11"}} + com.bhauman/figwheel-main {:mvn/version "0.2.18"}} :paths ["src" "resources"] - :aliases {:prod {:main-opts ["-m" "figwheel.main" "-bo" "dev"]}}} + :aliases {:prod {:main-opts ["-m" "figwheel.main" "-bo" "dev"]} + :dev {:extra-deps {thheller/shadow-cljs {:mvn/version "2.23.3"}}}}} diff --git a/reagent-reitit-demo/dev.cljs.edn b/reagent-reitit-demo/dev.cljs.edn index c0903fa..41f5db4 100644 --- a/reagent-reitit-demo/dev.cljs.edn +++ b/reagent-reitit-demo/dev.cljs.edn @@ -1,8 +1,17 @@ ^{:watch-dirs ["src"]} -{:output-to "resources/public/cljs-out/dev-main.js" +{;:output-to "resources/public/cljs-out/dev-main.js" + :output-dir "resources/public/cljs-out/" + :output-to "resources/public/cljs-out/main.js" :optimizations :none :pretty-print true + :target :bundle + :infer-externs true + :bundle-freq :smart + :auto-bundle :webpack :source-map true :source-map-timestamp true :devcards true + :bundle-cmd {:none ["npx" "webpack" "--mode=development" "--entry" :output-to + "--output-path" :final-output-dir + "--output-filename" :final-output-filename]} :main clojure-demo.core} diff --git a/reagent-reitit-demo/package.json b/reagent-reitit-demo/package.json new file mode 100644 index 0000000..4f04ada --- /dev/null +++ b/reagent-reitit-demo/package.json @@ -0,0 +1,17 @@ +{ + "dependencies": { + "@codemirror/commands": "^6.2.4", + "@codemirror/matchbrackets": "^0.19.4", + "@codemirror/state": "^6.2.0", + "@codemirror/theme-one-dark": "^6.1.2", + "@codemirror/view": "^6.10.1", + "@nextjournal/lang-clojure": "^1.0.0", + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "shadow-cljs": "^2.23.3", + "webpack": "^5.74.0", + "webpack-cli": "^4.10.0" + } +} diff --git a/reagent-reitit-demo/resources/public/documents/clojure-basics.org b/reagent-reitit-demo/resources/public/documents/clojure-basics.org index 25ea3f7..9fe8a09 100644 --- a/reagent-reitit-demo/resources/public/documents/clojure-basics.org +++ b/reagent-reitit-demo/resources/public/documents/clojure-basics.org @@ -20,10 +20,10 @@ Basic data \a \b \c \e \t \c ;;Symbols (named things like function & variable) are just text ;;these are quoted with a ' to stop evaluation, we have not actually defined them yet -;;this stops evaluation +;;this stops evaluation 'my-var-name 'my-fn-name 'my-second-var-etc 'my-second-fn-etc ;;hash map or dictonary keys are prefixed with a colon, no need to quote -:key1 :key2 :key3 +:key1 :key2 :key3 ;;booleans true false ;; Null or None is just nil @@ -35,7 +35,6 @@ nil Collections of data #+BEGIN_SRC clojure :tangle src/core.cljc ;; List are wrapped in brackets, space or comma act as seerators -(1 2 3 4 5 6 7 8 9) ;; Lists are special in that they need to be escaped to be treated as data ;; using the list function or the quote symbol, which is short hand and explained later. (list 1 2 3 4 5 6 7 8 9) diff --git a/reagent-reitit-demo/resources/public/documents/dsl-demo.org b/reagent-reitit-demo/resources/public/documents/dsl-demo.org index 1e7af17..1a6a6b7 100644 --- a/reagent-reitit-demo/resources/public/documents/dsl-demo.org +++ b/reagent-reitit-demo/resources/public/documents/dsl-demo.org @@ -172,7 +172,7 @@ We can also do joins to other table's (def base-join-sql (-> base-sql - (sqlh/join [:address] [:= :users.address_id address.id]))) + (sqlh/join [:address] [:= :users.address_id :address.id]))) (sql/format base-join-sql) #+END_SRC @@ -183,7 +183,7 @@ or group by's and sql functions like =count= =max= =min= these can be used by ap (def base-group-sql (-> base-sql (sqlh/select :first_name [:%count.first_name :count_name]) - (sqlh/group :first_name))) + (sqlh/group-by :first_name))) (sql/format base-group-sql) #+END_SRC @@ -200,16 +200,16 @@ This is how I like to compose queries, and shows a larger query being generated. (defn big-base-filters [filters] (-> big-base-sql - (sqlh/merge-where + (sqlh/where (when (:first_name filters) [:= :first_name (:first_name filters)])) - (sqlh/merge-where + (sqlh/where (when (:last_name filters) [:= :last_name (:last_name filters)])) - (sqlh/merge-where + (sqlh/where (when (:product_name filters) [:= :product.name (:product_name filters)])) - (sqlh/merge-where + (sqlh/where (when (:active filters) [:= :active (:active filters)])))) @@ -236,8 +236,8 @@ Say we want to get people added in the last 14 days this is a bit more tricky (def base-last-14-days-sql (-> base-sql (sqlh/where [:> - (sql/raw "created") - (sql/raw "CURRENT_DATE - INTERVAL '14' DAY")]))) + [:raw "created"] + [:raw "CURRENT_DATE - INTERVAL '14' DAY"]]))) (sql/format base-last-14-days-sql) diff --git a/reagent-reitit-demo/resources/public/documents/reagent-reitit.org b/reagent-reitit-demo/resources/public/documents/reagent-reitit.org index 21c1919..d770c54 100644 --- a/reagent-reitit-demo/resources/public/documents/reagent-reitit.org +++ b/reagent-reitit-demo/resources/public/documents/reagent-reitit.org @@ -20,6 +20,7 @@ You can control how reloading works by using meta data in your project, usually #+BEGIN_SRC clojurescript +;;(require '[reagent.core :as r]) (ns ^:figwheel-hooks core.demo) #+END_SRC @@ -55,6 +56,8 @@ In form two we can track local state inside a component a click counter being a This form of component give's you full access to the react life cycle methods, so render did-mount did-unmount etc usually this form of component is only needed when rendering graphics or things like graphs, it's also useful for capturing errors and handling them as in the example below, which renders your components but if =component-did-catch= is trigger the error is caught and displayed instead. #+BEGIN_SRC clojurescript +;;(require '[reagent.core :as reagent]) +;;(require '[reitit.frontend.easy :as rfe]) (defn err-boundary [& children] (let [err-state (reagent/atom nil)] @@ -81,22 +84,24 @@ These are a few simple routes, the last takes parameters and does validation che (def routes [["/" {:name ::frontpage - :view home-page-function}] + :view 'home-page-function}] ["/about" {:name ::about - :view about-page-function}] + :view 'about-page-function}] ["/item/:id" {:name ::item - :view item-page-function + :view 'item-page-function :parameters {:path {:id int?} - :query {(ds/opt :foo) keyword?}}}]]) + :query {:foo keyword?}}}]]) #+END_SRC You need to connect your routes data structure to =ref/start!= this function take's your own function where you can handle what should happen on route change, in this example an atom is updated causing react to render the new page. #+BEGIN_SRC clojurescript +(def site-state (reagent/atom nil)) + (rfe/start! (rf/router routes {:data {:coercion rss/coercion}}) (fn [m] (swap! site-state assoc :current-route m)) @@ -107,5 +112,5 @@ You need to connect your routes data structure to =ref/start!= this function tak To create a link to a route, you can use the =rfe/href= function which takes a lookup key which you specified in your routes, in this instance the key is name spaced to the current namespace. #+BEGIN_SRC clojurescript - [:a {:href (rfe/href ::frontpage)} "example link"] +[:a {:href (rfe/href ::frontpage)} "example link"] #+END_SRC diff --git a/reagent-reitit-demo/resources/public/index.html b/reagent-reitit-demo/resources/public/index.html index 0423534..74707f6 100644 --- a/reagent-reitit-demo/resources/public/index.html +++ b/reagent-reitit-demo/resources/public/index.html @@ -91,7 +91,7 @@