Make todomvc example use figwheel

This commit is contained in:
Dan Holmsand 2015-02-09 12:25:12 +01:00
parent 3e9b42a92b
commit 73281cdd16
8 changed files with 69 additions and 70 deletions

View File

@ -1,20 +0,0 @@
PROF = dev
# PROF = dev,test,srcmap
# PROF = prod,test
# PROF = prod
CLJSBUILD = client
all: autocompile
run: openbrowser autocompile
openbrowser:
(sleep 1 && open todomvc.html) &
autocompile:
lein with-profile $(PROF) cljsbuild auto $(CLJSBUILD)
clean:
lein -o clean

View File

@ -0,0 +1,7 @@
# Reagent example app
Run "`lein figwheel`" in a terminal to compile the app, and then open example.html.
Any changes to ClojureScript source files (in `src`) will be reflected in the running page immediately (while "`lein figwheel`" is running).
Run "`lein clean; lein with-profile prod compile`" to compile an optimized version.

View File

@ -0,0 +1,6 @@
(ns devsetup
(:require [todomvc :as example]
[figwheel.client :as fw]))
(fw/start {:on-jsload example/run
:websocket-url "ws://localhost:3449/figwheel-ws"})

View File

@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<link rel="stylesheet" href="todos.css">
</head>
<body>
<div id="app">
<h1>Reagent example app see README.md</h1>
</div>
<script src="target/client.js"></script>
<script>
todomvc.run();
</script>
</body>
</html>

View File

@ -1,28 +1,31 @@
(defproject todomvc-reagent "0.5.0-alpha" (defproject todomvc-reagent "0.5.0-alpha"
:dependencies [[org.clojure/clojure "1.6.0"] :dependencies [[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2342"] [org.clojure/clojurescript "0.0-2760"]
[reagent "0.5.0-alpha"]] [reagent "0.5.0-alpha2"]
:plugins [[lein-cljsbuild "1.0.3"]] [figwheel "0.2.3-SNAPSHOT"]]
:plugins [[lein-cljsbuild "1.0.4"]
[lein-figwheel "0.2.3-SNAPSHOT"]]
:hooks [leiningen.cljsbuild] :hooks [leiningen.cljsbuild]
:profiles {:prod {:cljsbuild
{:builds :profiles {:dev {:cljsbuild
{:client {:compiler {:builds {:client {:source-paths ["devsrc"]
{:optimizations :advanced :compiler
:preamble ^:replace ["reagent/react.min.js"] {:main devsetup
:pretty-print false}}}}} :optimizations :none
:srcmap {:cljsbuild :source-map true
{:builds :source-map-timestamp true}}}}}
{:client {:compiler
{:source-map "target/client.js.map" :prod {:cljsbuild
:source-map-path "client"}}}}}} {:builds {:client {:compiler
:source-paths ["src"] {:optimizations :advanced
:cljsbuild :elide-asserts true
{:builds :pretty-print false}}}}}}
{:client {:source-paths ["src"]
:compiler :figwheel {:repl false}
{:preamble ["reagent/react.js"]
:output-dir "target/client" :cljsbuild {:builds {:client {:source-paths ["src"]
:output-to "target/client.js" :compiler
:pretty-print true}}}}) {:output-dir "target/client"
:output-to "target/client.js"}}}})

View File

@ -1,10 +1,9 @@
(ns todomvc (ns todomvc
(:require [reagent.core :as reagent :refer [atom]])) (:require [reagent.core :as reagent :refer [atom]]))
(def todos (atom (sorted-map))) (defonce todos (atom (sorted-map)))
(def counter (atom 0)) (defonce counter (atom 0))
(defn add-todo [text] (defn add-todo [text]
(let [id (swap! counter inc)] (let [id (swap! counter inc)]
@ -18,11 +17,12 @@
(defn complete-all [v] (swap! todos mmap map #(assoc-in % [1 :done] v))) (defn complete-all [v] (swap! todos mmap map #(assoc-in % [1 :done] v)))
(defn clear-done [] (swap! todos mmap remove #(get-in % [1 :done]))) (defn clear-done [] (swap! todos mmap remove #(get-in % [1 :done])))
(add-todo "Rename Cloact to Reagent") (defonce init (do
(add-todo "Add undo demo") (add-todo "Rename Cloact to Reagent")
(add-todo "Make all rendering async") (add-todo "Add undo demo")
(add-todo "Allow any arguments to component functions") (add-todo "Make all rendering async")
(complete-all true) (add-todo "Allow any arguments to component functions")
(complete-all true)))
(defn todo-input [{:keys [title on-save on-stop]}] (defn todo-input [{:keys [title on-save on-stop]}]
(let [val (atom title) (let [val (atom title)
@ -104,4 +104,5 @@
[:p "Double-click to edit a todo"]]])))) [:p "Double-click to edit a todo"]]]))))
(defn ^:export run [] (defn ^:export run []
(reagent/render-component [todo-app] (.-body js/document))) (reagent/render [todo-app]
(js/document.getElementById "app")))

View File

@ -1,15 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>todomvc with reagent</title>
<link rel="stylesheet" href="todos.css">
</head>
<body>
<h1>This will become todomvc when the ClojureScript is compiled</h1>
<script type="text/javascript" src="target/client.js"></script>
<script type="text/javascript">
todomvc.run();
</script>
</body>
</html>

View File

@ -107,7 +107,7 @@ input[type="checkbox"] {
background: -webkit-gradient(linear, left top, left bottom, from(rgba(132, 110, 100, 0.8)),to(rgba(101, 84, 76, 0.8))); background: -webkit-gradient(linear, left top, left bottom, from(rgba(132, 110, 100, 0.8)),to(rgba(101, 84, 76, 0.8)));
background: -webkit-linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8)); background: -webkit-linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8));
background: linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8)); background: linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670'); /* filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670'); */
border-top-left-radius: 1px; border-top-left-radius: 1px;
border-top-right-radius: 1px; border-top-right-radius: 1px;
} }