Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active June 12, 2017 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save borkdude/fd61bc806e6c3096551509d22c6a68de to your computer and use it in GitHub Desktop.
Save borkdude/fd61bc806e6c3096551509d22c6a68de to your computer and use it in GitHub Desktop.
(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