Skip to content

Commit

Permalink
Add a re-frame example application option
Browse files Browse the repository at this point in the history
Includes a useful pattern for tracing the execution of a re-frame
application.

Fixes martinklepsch#43
  • Loading branch information
RadicalZephyr committed Oct 18, 2017
1 parent d147f98 commit 3adb2f8
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ project will contain:
- `+reagent` provides a basic
[Reagent](https://github.com/reagent-project/reagent) application
and adds relevant dependencies
- `+re-frame` provides a basic
[Reframe](https://github.com/Day8/re-frame) application and adds
relevant dependencies
- `+rum` provides a basic
[Rum](https://github.com/tonsky/rum) application
and adds relevant dependencies
Expand Down
71 changes: 71 additions & 0 deletions resources/leiningen/new/tenzing/re-frame-app.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
(ns {{name}}.app
(:require [reagent.core :as reagent :refer [atom]]
[clairvoyant.core :refer-macros [trace-forms]]
[re-frame-tracer.core :refer [tracer]]
[re-frame.core :as re-frame]))

(defn setup! []
;; Cofx Registrations
(trace-forms {:tracer (tracer :color "purple")}
(re-frame/reg-cofx
:thing
(fn thing-cofx [cofx _]
))

)

;; Fx Registrations
(trace-forms {:tracer (tracer :color "gold")}
(re-frame/reg-fx
:thing
(fn thing-fx [calls]
))

)

;; Events Registrations
(trace-forms {:tracer (tracer :color "green")}
(re-frame/reg-event-db
:init-db
(fn init-db-event [db [_ error]]
{:page-key ::main}))

)

;; Subscriptions Registrations
(trace-forms {:tracer (tracer :color "brown")}
(re-frame/reg-sub
:page-key
(fn page-key-sub [app-db _]
(:page-key app-db)))

))

(defn four-oh-four []
[:div
[:h1 "Sorry!"]
"There's nothing to see here. Try checking out the "
[:a {:href "/#"} "root"]
"."])

(defn hello-world []
[:h1 "Hello, Re-frame!"])

(defn main-panel [page-key]
(case page-key
::main [hello-world]
[four-oh-four]))

(defn main-panel-container []
(let [page-key (re-frame/subscribe [:page-key])]
[#'main-panel @page-key]))

(defn render-root []
(if-let [node (.getElementById js/document "container")]
(reagent/render-component [#'main-panel-container] node)))

(defn ^:export init []
(re-frame.core/clear-subscription-cache!)
(setup!)
(re-frame/dispatch [:init-db])
(render-root))
32 changes: 22 additions & 10 deletions src/leiningen/new/tenzing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@
(wrap-indent identity n list))

;; -------------------------------------------------------------------------
;; Options - currently: reagent, om, om-next, sass, garden, devtools, dirac
;; Options - currently: reagent, re-frame, om, om-next, sass, garden, devtools, dirac
;; -------------------------------------------------------------------------

(defn reagent? [opts]
(some #{"+reagent"} opts))

(defn re-frame? [opts]
(some #{"+re-frame"} opts))

(defn om? [opts]
(some #{"+om"} opts))

Expand Down Expand Up @@ -100,6 +103,9 @@
(om-next? opts) (conj "org.omcljs/om \"1.0.0-alpha47\"")
(rum? opts) (conj "rum \"0.10.7\"")
(reagent? opts) (conj "reagent \"0.6.0\"")
(re-frame? opts) (conj "re-frame \"0.10.2\""
"day8/re-frame-tracer \"0.1.1-SNAPSHOT\""
"org.clojars.stumitchell/clairvoyant \"0.2.0\"")
(garden? opts) (conj "org.martinklepsch/boot-garden \"1.3.2-0\" :scope \"test\"")
(sass? opts) (conj "deraen/boot-sass \"0.3.0\" :scope \"test\"")
(sass? opts) (conj "org.slf4j/slf4j-nop \"1.7.21\" :scope \"test\"")
Expand Down Expand Up @@ -167,7 +173,12 @@
(defn development-task-opts [opts]
;FIXME: change to if
(cond-> []
(less? opts) (conj (str "less {:source-map true}"))))
(less? opts) (conj (str "less {:source-map true}"))
(re-frame? opts) (conj (str "cljs {:optimizations :none"
" :source-map true"
" :compiler-options {:devcards true"
" :closure-defines {\"clairvoyant.core.devmode\" true}}}\n"
"reload {:on-jsload '{{sanitized}}.app/dev-reload}"))))

(defn index-html-head-tags [opts]
(letfn [(style-tag [href] (str "<link href=\"" href "\" rel=\"stylesheet\" type=\"text/css\" media=\"screen\">"))]
Expand Down Expand Up @@ -215,9 +226,9 @@

(defn mute-implicit-target-warning [boot-props]
(let [line-sep (System/getProperty "line.separator")]
(string/join line-sep
(conj (string/split (render-boot-properties)
(re-pattern line-sep))
(string/join line-sep
(conj (string/split (render-boot-properties)
(re-pattern line-sep))
(str "BOOT_EMIT_TARGET=no" line-sep)))))

(defn tenzing
Expand All @@ -236,11 +247,12 @@

(if (less? opts) ["less/less.main.less" (render "less.main.less" data)])

(cond (reagent? opts) [app-cljs (render "reagent-app.cljs" data)]
(om? opts) [app-cljs (render "om-app.cljs" data)]
(om-next? opts) [app-cljs (render "om-next-app.cljs" data)]
(rum? opts) [app-cljs (render "rum.cljs" data)]
:none [app-cljs (render "app.cljs" data)])
(cond (reagent? opts) [app-cljs (render "reagent-app.cljs" data)]
(re-frame? opts) [app-cljs (render "re-frame-app.cljs" data)]
(om? opts) [app-cljs (render "om-app.cljs" data)]
(om-next? opts) [app-cljs (render "om-next-app.cljs" data)]
(rum? opts) [app-cljs (render "rum.cljs" data)]
:none [app-cljs (render "app.cljs" data)])

["resources/js/app.cljs.edn" (render "app.cljs.edn" data)]
["resources/index.html" (render "index.html" data)]
Expand Down

0 comments on commit 3adb2f8

Please sign in to comment.