Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns horizon.domain.reports.dialogs.edit
[com.rpl.specter :as specter]
[ :as re-om]
[horizon.common.macros :refer [defstate]]
[horizon.common.state.lens :as l]
;; ...
(defstate reports-dialogs-edit
{:field-mappings {}
:options-mappings {}
:validators {}
:active-tab nil
:tabs []
:fields {} 1
:infractions {}
:configuration-fields {}
:original-fields {}
:loaded? false
:editing? false
:options {}})
;; ...
(def ^:private field-mappings-lens reports-dialogs-edit-field-mappings-lens)
(def ^:private options-lens reports-dialogs-edit-options-lens)
(def ^:private loaded?-lens reports-dialogs-edit-loaded?-lens)
(def ^:private fields-lens reports-dialogs-edit-fields-lens)
(def active-tab-lens reports-dialogs-edit-active-tab-lens)
(def ^:private tabs-lens reports-dialogs-edit-tabs-lens)
;; ...
(defn- maybe-result [res]
(if (= res :form/empty)
(fn [db [args]]
(apply (l/pure-view db field-mappings-lens) args)))
;; ...
(fn [db args]
(let [res (if-let [path (re-om/get [::field-mapping args] db)]
(specter/select-one path (l/pure-view db fields-lens))
(get (l/pure-view db fields-lens) (first args) :form/empty))]
(maybe-result res))))
;; ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment