From 2e429bb5c0aa6aa000b51448eb554ce7ab9f4be8 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 23 May 2016 13:53:36 -0400 Subject: [PATCH] update example todomvc app --- examples/todomvc/README.md | 41 ++++++ examples/todomvc/project.clj | 92 ++++++------ examples/todomvc/resources/html/app.html | 15 +- examples/todomvc/src/todomvc/client.cljs | 108 +++++++++++--- examples/todomvc/src/todomvc/server.clj | 170 ++++++++++++++--------- 5 files changed, 293 insertions(+), 133 deletions(-) create mode 100644 examples/todomvc/README.md diff --git a/examples/todomvc/README.md b/examples/todomvc/README.md new file mode 100644 index 0000000..598377e --- /dev/null +++ b/examples/todomvc/README.md @@ -0,0 +1,41 @@ +# Reagent Data Views Example - Todo MVC + +This is a modification of the Todo MVC app for Reagent [demonstrated here][1]. +This version of the app has been modified to use a PostgreSQL database +to store the Todos and to provide realtime synchronization of changes +to that data to any number of users currently viewing the app. + +[1]: http://reagent-project.github.io/ + +## Running + +Since Reagent Data Views and the Views library it depends on are all +currently in somewhat of an experimental / pre-beta state right now, +you will need to first clone the following repositories and manually +install the libraries via `lein install`: + +* [views](https://github.com/gered/views) +* [views-sql](https://github.com/gered/views-sql) +* [reagent-data-views](https://github.com/gered/reagent-data-views) + +As well, you can install [views-honeysql](https://github.com/gered/views-honeysql) +if you want to try out using HoneySQL instead of SQL with views. But +this example app does not use it so it's not required. + +Once these libraries are install, you can simply build the ClojureScript: + + $ lein cljsbuild once + +And then start up a REPL and run: + + (-main) + +And a new browser window should open to the app. + +Alternatively, to build and run in one go: + + $ lein rundemo + +Open up a second browser and make changes by adding or deleting a Todo, +or marking them as completed, etc. and see that the changes are +instantly propagated to all clients. diff --git a/examples/todomvc/project.clj b/examples/todomvc/project.clj index 613d7a3..5705734 100644 --- a/examples/todomvc/project.clj +++ b/examples/todomvc/project.clj @@ -1,50 +1,56 @@ (defproject todomvc "0.1.0-SNAPSHOT" - :dependencies [[org.clojure/clojure "1.6.0"] - [org.clojure/clojurescript "0.0-2371"] - [compojure "1.2.1"] - [ring "1.3.1"] - [ring/ring-defaults "0.1.3" :exclusions [javax.servlet/servlet-api]] - [net.thegeez/clj-browserchannel-jetty-adapter "0.0.6"] - [clj-browserchannel-messaging "0.0.4"] - [clj-pebble "0.2.0"] - [cljs-ajax "0.3.3"] - [reagent "0.5.0-alpha"] - [reagent-data-views "0.1.0-SNAPSHOT"] - [views "0.5.0"] - [org.clojure/java.jdbc "0.3.5"] - [org.postgresql/postgresql "9.2-1003-jdbc4"] - [honeysql "0.4.3"] - [environ "1.0.0"]] + :dependencies [[org.clojure/clojure "1.8.0"] + [org.clojure/clojurescript "1.8.51"] + [ring "1.4.0"] + [ring/ring-defaults "0.2.0" :exclusions [javax.servlet/servlet-api]] + [compojure "1.4.0"] + [org.immutant/web "2.1.4"] - :plugins [[lein-cljsbuild "1.0.3"]] + [org.clojure/java.jdbc "0.6.1"] + [org.postgresql/postgresql "9.4.1208.jre7"] + [gered/clj-browserchannel "0.3.1"] + [gered/clj-browserchannel-immutant-adapter "0.0.3"] + [gered/views "1.5-SNAPSHOT"] + [gered/views-sql "0.1.0-SNAPSHOT"] + [reagent-data-views "0.2.0-SNAPSHOT"] + [reagent-data-views-browserchannel "0.1.0-SNAPSHOT"] - :main todomvc.server + [clj-pebble "0.2.0"] + [reagent "0.6.0-alpha2"] + [cljs-ajax "0.5.4"] + ; only being used to get a tag value with the CSRF token in it + [prismatic/dommy "1.1.0"] - :cljsbuild {:builds - {:main - {:source-paths ["src"] - :compiler - {:preamble ["reagent/react.js"] - :output-to "resources/public/cljs/client.js" - :source-map "resources/public/cljs/client.js.map" - :output-dir "resources/public/cljs/client" - :optimizations :none - :pretty-print true}}}} + [environ "1.0.3"]] - :profiles {:dev {:env {:dev true}} + :plugins [[lein-cljsbuild "1.1.3"] + [lein-environ "1.0.3"]] - :uberjar {:env {:dev false} - :hooks [leiningen.cljsbuild] - :cljsbuild - {:jar true - :builds - {:main - {:compiler - ^:replace - {:output-to "resources/public/cljs/client.js" - :preamble ["reagent/react.min.js"] - :optimizations :advanced - :pretty-print false}}}}}} + :main todomvc.server - :aliases {"uberjar" ["do" "clean" ["cljsbuild clean"] "uberjar"] - "cljsdev" ["do" ["cljsbuild" "clean"] ["cljsbuild" "once"] ["cljsbuild" "auto"]]}) + :clean-targets ^{:protect false} [:target-path + [:cljsbuild :builds :main :compiler :output-dir] + [:cljsbuild :builds :main :compiler :output-to]] + :cljsbuild {:builds {:main + {:source-paths ["src"] + :compiler {:output-to "resources/public/cljs/app.js" + :output-dir "resources/public/cljs/target" + :source-map true + :optimizations :none + :pretty-print true}}}} + + :profiles {:dev {:env {:dev "true"}} + + :uberjar {:env {} + :aot :all + :hooks [leiningen.cljsbuild] + :cljsbuild {:jar true + :builds {:main + {:compiler ^:replace {:output-to "resources/public/cljs/app.js" + :optimizations :advanced + :pretty-print false}}}}}} + + :aliases {"rundemo" ["do" ["clean"] ["cljsbuild" "once"] ["run"]] + "uberjar" ["do" ["clean"] ["uberjar"]]} + + ) diff --git a/examples/todomvc/resources/html/app.html b/examples/todomvc/resources/html/app.html index 0e31c8b..7792a9c 100644 --- a/examples/todomvc/resources/html/app.html +++ b/examples/todomvc/resources/html/app.html @@ -5,12 +5,19 @@ todomvc with reagent + + + -

This will become todomvc when the ClojureScript is compiled

- {% if dev %}{% endif %} - {% if dev %}{% endif %} - +
+

This will become todomvc when the ClojureScript is compiled

+
+ {% if dev %}{% endif %} + {% if dev %}{% endif %}