Skip to content

Instantly share code, notes, and snippets.

Last active March 4, 2017 23:08
What would you like to do?
react-select using reagent and klipse
(ns zap.core
"Demonstrate react-select in KLIPSE"
(:require [reagent.core :as r]
(defonce value (r/atom nil))
(defn select-ui []
[:> js/window.Select {:value @value
:options #js [#js {:value "a" :label "alpha"}
#js {:value "b" :label "beta"}
#js {:value "c" :label "gamma"}]
:onChange #(reset! value (aget % "value"))}])
(defn root-ui []
[:div {:style {:width 400}}
[:h3 "Select test"]
;; the purpose of the rest is just to load the css
;; in KLIPSE
(defn load-many [cb x & rst]
(let [cntn (fn [] (if (seq rst)
(apply load-many cb rst)
(if (.endsWith x ".css")
(let [head (aget (js/document.getElementsByTagName "head") 0)
node (doto (js/document.createElement "link")
(aset "type" "text/css")
(aset "rel" "stylesheet")
(aset "href" x)
(aset "onload" (fn []
(js/console.log "loaded css:" x)
(.append head node))
( x
(fn [e]
(js/eval (-> e .-target .getResponseText))
(js/console.log "loaded js:" x)
(defn unpkg-many [cb & xs]
(apply load-many cb (map #(str "" %) xs)))
(defonce initialized? (atom nil))
(defn init [cb]
(let [cb (or cb identity)]
(if @initialized?
(unpkg-many (fn []
(reset! initialized? true
(init #(r/render [root-ui] js/klipse-container))
Copy link

pesterhazy commented Mar 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment