Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns horizon.domain.reports.dialogs.edit
(:require
[com.rpl.specter :as specter]
[greenpowermonitor.re-om :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)
nil
res))
(re-om/register-sub!
::field-mapping
(fn [db [args]]
(apply (l/pure-view db field-mappings-lens) args)))
;; ...
(re-om/register-sub!
::field
(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