Skip to content

Instantly share code, notes, and snippets.

@mattsfrey
Last active July 25, 2016 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsfrey/99c9f26d5b743d08200de780e1e41909 to your computer and use it in GitHub Desktop.
Save mattsfrey/99c9f26d5b743d08200de780e1e41909 to your computer and use it in GitHub Desktop.
Re-Frame Example
;;;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])))
;;;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