Fork me on GitHub
#fulcro
<
2020-07-22
>
dvingo14:07:47

Does anyone have suggestions for the pattern where you have an entity view for a single thing with an ident like :task/id but you want to toggle between an editing view and read-only view? The thing I'm struggling with is that the 3 components (the parent container, the edit form, and the read-only view) all would have the same ident - because they represent the same data, but I don't know how to get that to work with the DB. here's a sample - all 3 components have an ident of :task/id but the 2 child components have different queries.

(defsc TaskItemContainer
  [this
   {:keys    [task-item task-form]
    :ui/keys [editing?]
    :as      props}]
  {:query         [:ui/editing?
                   :task/id
                   {:task-item (c/get-query TaskItem)}
                   {:task-form (c/get-query TaskForm)}]
   :ident         :task/id
   :initial-state (fn [task]
                    {:task/id (:task/id task)
                     :task-form (c/get-initial-state TaskForm task)
                     :task-item (c/get-initial-state TaskItem task)})}
  (if editing?
    (ui-task-form task-form)
    (ui-task-item task-item)))
Would this work if I "overload" the :task/id table to allow storing different properties for different components in the same place?

dvingo14:07:15

hmm, I think it's working - rubber duck ftw

duckie 6
tony.kay15:07:00

of course, that’s the point of idents 😄

tony.kay15:07:20

each has its own set of props, and you can load just what you need (using the component that you’re about to show). The load system is designed not to stomp on things you don’t ask for, and to remove those that are there in the client db, are asked for, but do not arrive. That is the whole point of the mark-missing behaviors: more than one component might use the same ident and therefore write over some other prior load, and if both are on-screen it sure would be screwy for a new load to cause an old thing to suddenly look weird.

dvingo16:07:57

It is a beautiful system. My confusion stemmed from not setting up my initial state correctly, but now it's good!