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