Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a re-frame example application option #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
65 changes: 65 additions & 0 deletions resources/leiningen/new/tenzing/re-frame-app.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
(ns {{name}}.app
(:require [reagent.core :as reagent]
[re-frame.core :as re-frame]))

(defn setup! []
;; Cofx Registrations
(re-frame/reg-cofx
:thing
(fn thing-cofx [cofx _]
))


;; Fx Registrations
(re-frame/reg-fx
:thing
(fn thing-fx [calls]
))


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


;; Subscriptions Registrations
(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 []
(setup!)
(re-frame/dispatch [:init-db])
(render-root))

(defn dev-reload []
(re-frame.core/clear-subscription-cache!)
(setup!)
(render-root))
34 changes: 24 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,10 @@
(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.5\""
"reagent \"0.7.0\""
"org.clojure/tools.reader \"1.3.0-alpha3\""
"day8.re-frame/re-frame-10x \"0.3.3\" :scope \"test\"")
(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 +174,13 @@
(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 { "
" :closure-defines {\"re_frame.trace.trace_enabled_QMARK_\" true}"
" :preloads '[day8.re-frame-10x.preload]}}"
" 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 +228,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 +249,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