-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
helpers.cljs
49 lines (41 loc) · 1.4 KB
/
helpers.cljs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns fulcro.inspect.ui.helpers
(:require [fulcro-css.css :as css]
[clojure.string :as str]
[goog.object :as gobj]
[fulcro.client.primitives :as fp]))
(defn js-get-in [x path]
(gobj/getValueByKeys x (clj->js path)))
(defn html-attr-merge [a b]
(cond
(map? a) (merge a b)
(string? a) (str a " " b)
:else b))
(defn props->html
[attrs & props]
(->> (mapv #(dissoc % :react-key) props)
(apply merge-with html-attr-merge (dissoc attrs :react-key))
(into {} (filter (fn [[k _]] (simple-keyword? k))))
(clj->js)))
(defn expand-classes [css classes]
{:className (str/join " " (mapv css classes))})
(defn props
[comp defaults]
(props->html defaults (fp/props comp)))
(defn props+classes [comp defaults]
(let [props (fp/props comp)
css (-> comp fp/react-type css/get-classnames)]
(props->html defaults
(expand-classes css (:fulcro.inspect.ui.core/classes props))
props)))
(defn computed-factory
([class] (computed-factory class {}))
([class options]
(let [factory (fp/factory class options)]
(fn real-factory
([props] (real-factory props {}))
([props computed]
(factory (fp/computed props computed)))))))
(defn react-display-name [element]
(or
(some-> element (gobj/get "displayName") symbol)
(some-> element fp/react-type (gobj/get "displayName") symbol)))