-
Notifications
You must be signed in to change notification settings - Fork 52
/
demo_3_system_properties.cljc
36 lines (33 loc) · 1.38 KB
/
demo_3_system_properties.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(ns user.demo-3-system-properties
(:require
[clojure.string :as str]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]
[hyperfiddle.electric-ui4 :as ui]))
; A web view that queries the backend JVM environment and writes it to the
; frontend dom, all in a single composed expression.
; The p/for is stabilized with a "react key" for efficient DOM maintenance.
#?(:clj
(defn system-properties [?s]
(->> (System/getProperties)
(filter (fn [[k v]] (str/includes? (str/lower-case (str k)) (str/lower-case (str ?s)))))
(into {}))))
(e/defn App []
(e/client
(dom/h1 (dom/text "JVM System Properties search"))
(let [!search (atom "")
search (e/watch !search)]
(e/server
(let [system-props (e/offload #(sort-by key (system-properties search)))
matched-count (count system-props)]
(e/client
(dom/div (dom/props {:style {:color "gray"}}) (dom/text matched-count " matches"))
(ui/input search (e/fn [v] (reset! !search v))
(dom/props {:type "search" :placeholder "java.home"}))
(dom/table
(e/server
(e/for-by first [[k v] system-props]
(e/client
(dom/tr
(dom/td (dom/text k))
(dom/td (dom/props {:style {:white-space :nowrap}}) (dom/text v)))))))))))))