Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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
You can’t perform that action at this time.