mirror of https://github.com/status-im/pluto.git
Improved view-fn handing
This commit is contained in:
parent
d51c14c70a
commit
1b0633585b
|
@ -41,6 +41,10 @@
|
|||
(re-frame/subscribe data)
|
||||
(log/fire! ctx ::log/error :query/resolve data)))
|
||||
|
||||
(defn view-fn [parent-ctx data]
|
||||
[:div {}
|
||||
data])
|
||||
|
||||
(def ctx
|
||||
{:env {:id "Extension ID"}
|
||||
:capacities {:components components/all
|
||||
|
@ -60,7 +64,8 @@
|
|||
:data :alert
|
||||
:arguments {:value :string}}}}
|
||||
:event-fn dispatch-events
|
||||
:query-fn resolve-query})
|
||||
:query-fn resolve-query
|
||||
:view-fn view-fn})
|
||||
|
||||
(def payload
|
||||
{:name "Test Extension"
|
||||
|
|
|
@ -192,6 +192,17 @@
|
|||
(when (map? o)
|
||||
(set (keys o))))) ;; TODO extract all bindings props, not only first level
|
||||
|
||||
|
||||
(defn- wrap-view [parent-ctx {:keys [view-fn] :as ctx} {:keys [data errors] :as m}]
|
||||
(if (and (not errors) view-fn)
|
||||
(let [view (view-fn parent-ctx data)]
|
||||
(if (vector? view)
|
||||
{:data view}
|
||||
(do
|
||||
(log/fire! ctx ::log/error :view/fn view)
|
||||
m)))
|
||||
m))
|
||||
|
||||
;; TODO normalize to always have a props map
|
||||
(defn parse
|
||||
([ctx ext o]
|
||||
|
@ -204,8 +215,8 @@
|
|||
(fn [o]
|
||||
[error-boundary ctx
|
||||
(inject-properties data o)])}))))
|
||||
([{:keys [view-fn] :as ctx} ext {:keys [path] :as parent-ctx} o]
|
||||
((if view-fn #(view-fn parent-ctx %) identity)
|
||||
([ctx ext {:keys [path] :as parent-ctx} o]
|
||||
(wrap-view parent-ctx ctx
|
||||
(if (list? o)
|
||||
(let [{:keys [data errors]} (blocks/parse ctx ext parent-ctx o)]
|
||||
(if errors
|
||||
|
|
Loading…
Reference in New Issue