Last active
June 12, 2017 17:30
-
-
Save borkdude/fd61bc806e6c3096551509d22c6a68de to your computer and use it in GitHub Desktop.
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
(ns simple.core | |
(:require [reagent.core :as r] | |
[re-frame.core :as rf])) | |
(rf/reg-event-db | |
:initialize | |
(fn [_ _] | |
{:loading? true})) | |
(rf/reg-event-db | |
:toggle-loading | |
(fn [db _] | |
(println "toggle") | |
(update db :loading? not))) | |
(rf/reg-sub | |
:loading? | |
(fn [db _] | |
(-> db | |
:loading?))) | |
(defn report-iframe | |
[loading?] | |
(r/create-class | |
{:reagent-render (fn [loading?] | |
[:div | |
[:iframe {:src "http://app.klipse.tech" | |
:style {:display (if loading? "none" "block")} | |
}] | |
]) | |
:component-did-mount #(println "report-iframe-did-mount")})) | |
(defn report [loading?] | |
[:div | |
(when loading? | |
[:div "Loading..."]) | |
^{:key "report-iframe"} | |
;; Note that without the key, the iframe component is mounted multiple times... | |
[report-iframe loading?]]) | |
(defn ui | |
[] | |
(let [loading? (rf/subscribe [:loading?])] | |
[:div | |
[:button {:on-click #(rf/dispatch [:toggle-loading])} | |
"Click me"] | |
[report @loading?]])) | |
;; -- Entry Point ------------------------------------------------------------- | |
(defn ^:export run | |
[] | |
(rf/dispatch-sync [:initialize]) | |
(r/render [ui] | |
js/klipse-container)) | |
(run) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment