mirror of
https://github.com/status-im/pluto.git
synced 2025-02-24 00:18:16 +00:00
make element properties optional
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
7bd37d5021
commit
95e44c9eee
@ -27,10 +27,12 @@
|
||||
{:data m}))
|
||||
|
||||
(defn hiccup-with-properties [h properties]
|
||||
(if (vector? h)
|
||||
(let [[tag props & children] h
|
||||
{:keys [data]} (inject-properties props properties)]
|
||||
(apply conj [tag data]
|
||||
(if (vector? h)
|
||||
(let [[tag & properties-children] h
|
||||
[props children] (views/resolve-properties-children properties-children)
|
||||
{:keys [data]} (when properties
|
||||
(inject-properties props properties))]
|
||||
(apply conj (if data [tag data] [tag])
|
||||
(map #(hiccup-with-properties % properties) children)))
|
||||
h))
|
||||
|
||||
|
@ -70,6 +70,12 @@
|
||||
:errors []}
|
||||
properties))
|
||||
|
||||
(defn resolve-properties-children [[properties? & children]]
|
||||
[(and (map? properties?) properties?)
|
||||
(if (map? properties?)
|
||||
children
|
||||
(cons properties? children))])
|
||||
|
||||
(defn parse-hiccup-element [{:keys [capacities] :as opts} o]
|
||||
(let [explain (spec/explain-data ::form o)]
|
||||
(cond
|
||||
@ -80,13 +86,17 @@
|
||||
(or (symbol? o) (utils/primitive? o)) {:data o}
|
||||
(vector? o)
|
||||
|
||||
(let [[element properties & children] o
|
||||
component (resolve-element capacities element)
|
||||
{:keys [data errors]} (resolve-element-properties capacities properties)]
|
||||
(let [[element & properties-children] o
|
||||
[properties children] (resolve-properties-children properties-children)
|
||||
component (resolve-element capacities element)
|
||||
{:keys [data errors]} (when properties
|
||||
(resolve-element-properties capacities properties))]
|
||||
(cond-> (let [m (parse-hiccup-children opts children)]
|
||||
;; Reduce parsed children to a single map and wrap them in a hiccup element
|
||||
;; whose component has been translated to the local platform
|
||||
(update m :data #(apply conj [(or component element) data] %)))
|
||||
(update m :data #(apply conj (if data [(or component element) data]
|
||||
[(or component element)])
|
||||
%)))
|
||||
(nil? component) (errors/accumulate-errors [(errors/error ::errors/unknown-component element)])
|
||||
(seq errors) (errors/accumulate-errors errors))))))
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
(is (= {:data [:text {} "Hello"]}
|
||||
(views/parse {:capacities {:components {'text :text}}} ['text {} "Hello"])))
|
||||
(is (= {:data [:view
|
||||
{}
|
||||
[:text {} "Hello"]
|
||||
[blocks/let-block
|
||||
{:env {'cond? '@queries/random-boolean}}
|
||||
@ -38,7 +37,7 @@
|
||||
[:text {:style {:color "red"}} "World?"]]]]}
|
||||
(views/parse {:capacities {:components {'text :text
|
||||
'view :view}}}
|
||||
'[view {}
|
||||
'[view
|
||||
[text {} "Hello"]
|
||||
(let [cond? @queries/random-boolean]
|
||||
(if cond?
|
||||
|
Loading…
x
Reference in New Issue
Block a user