Improved view-fn handing

This commit is contained in:
Julien Eluard 2019-04-01 16:34:42 +02:00
parent d51c14c70a
commit 1b0633585b
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
2 changed files with 19 additions and 3 deletions

View File

@ -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"

View File

@ -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