Last active
July 25, 2016 19:04
-
-
Save mattsfrey/99c9f26d5b743d08200de780e1e41909 to your computer and use it in GitHub Desktop.
Re-Frame Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;DATA | |
(ns data | |
(:require [re-frame.db :refer [app-db]] | |
[reagent.atom :as ra :include-macros true] | |
[re-frame.core :as rf])) | |
(defn show-box?- [] | |
(ra/reaction (get-in @app-db [:show-box?]))) | |
(rf/register-handler | |
:show-box middleware | |
(fn [db] | |
(assoc-in db [:show-box?] true]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;VIEW | |
(ns view | |
(:require [data :as data] | |
[re-frame.core :as rf])) | |
(defn component [] | |
(let [show-box?- data/show-box?-] | |
(fn [] | |
[:div | |
[:span {:on-click #(rf/dispatch [:show-box])} | |
"Click to show red box."] | |
(when @show-box?- [:div {:style {:width 40 | |
:height 40 | |
:background-color "red"}}])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment