mirror of
https://github.com/status-im/re-frame-10x.git
synced 2025-01-11 22:54:14 +00:00
Refactor jsonml parsing
This commit is contained in:
parent
910483dd53
commit
8c1d39b006
@ -456,6 +456,9 @@
|
||||
color: #8f8f8f;
|
||||
content: "}";
|
||||
}
|
||||
#--re-frame-trace-- .re-frame-trace--object {
|
||||
display: block;
|
||||
}
|
||||
#--re-frame-trace-- .re-frame-trace--object .toggle {
|
||||
color: #8f8f8f;
|
||||
cursor: pointer;
|
||||
|
@ -575,6 +575,7 @@
|
||||
}
|
||||
}
|
||||
.re-frame-trace--object {
|
||||
display: block;
|
||||
.toggle {
|
||||
color: @text-color-muted;
|
||||
cursor: pointer;
|
||||
|
@ -11,17 +11,9 @@
|
||||
(reduce (fn [acc [property value]]
|
||||
(assoc acc (keyword property) value)) {})))
|
||||
|
||||
(defn str->hiccup
|
||||
[string]
|
||||
(cond (= string "span") :span
|
||||
(= string "style") :style
|
||||
(= string ", ") " "
|
||||
:else string))
|
||||
|
||||
(declare jsonml->hiccup)
|
||||
|
||||
(defn data-structure
|
||||
[jsonml]
|
||||
(defn data-structure [jsonml]
|
||||
(let [expanded? (r/atom true)]
|
||||
(fn [jsonml]
|
||||
[:span
|
||||
@ -38,17 +30,22 @@
|
||||
(.-object (get jsonml 1))
|
||||
(.-config (get jsonml 1)))))])))
|
||||
|
||||
(defn jsonml->hiccup
|
||||
[jsonml]
|
||||
(cond
|
||||
(and (array? jsonml)
|
||||
(= "object" (first jsonml))) [data-structure jsonml]
|
||||
(array? jsonml) (mapv jsonml->hiccup jsonml)
|
||||
(object? jsonml) {:style (string->css (js->clj jsonml))}
|
||||
(or (string? jsonml)
|
||||
(integer? jsonml)) (str->hiccup jsonml)))
|
||||
(defn jsonml->hiccup [jsonml]
|
||||
(if (number? jsonml)
|
||||
jsonml
|
||||
(let [[head & args] jsonml
|
||||
tagnames #{"span" "ol" "li" "div"}]
|
||||
(cond
|
||||
(contains? tagnames head) (let [[style & children] args]
|
||||
[(keyword head) {:style (string->css (js->clj style))}
|
||||
(into [:div {:style {:display "inline-block"}}]
|
||||
(mapv jsonml->hiccup children))])
|
||||
(= head "object") [data-structure jsonml]
|
||||
(= jsonml ", ") " "
|
||||
:else jsonml))))
|
||||
|
||||
|
||||
(defn tab [data]
|
||||
[:div {:style {:flex "1 0 auto" :width "100%" :height "100%" :display "flex" :flex-direction "column"}}
|
||||
[:div.panel-content-scrollable
|
||||
(jsonml->hiccup (cljs-devtools/header-api-call data))]])
|
||||
(jsonml->hiccup (cljs-devtools/header-api-call data))]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user