Fork me on GitHub
#fulcro
<
2023-03-07
>
tony.kay02:03:12

The field is just the attribute in your data model. You can make a mutation that can update the lot of them on a single call. You just change the data in the entity. Fulcro uses the active entity as the edited content, and saves the pristine original data in form config.

Eric Dvorsak16:03:04

indeed that was much easier, thanks! one issue though is that apply-on-change/apply-derived-calculations is not called anymore so the on-change/derived-fields are not updated

tony.kay19:03:44

correct. You asked how to change a group of fields. If you also want RAD form behavior, then you have to at least send an event to the UISM that is controlling the form so it does that logic.

tony.kay19:03:09

e.g. call at least one input-changed! or read the low-level UISM and figure out something better

Eric Dvorsak09:03:26

is it safe to call trigger!! in a mutation? on the surface it looks like it works, I ended up triggering the :event/attribute-changed event directly for the :many attribute, but if I use trigger! instead of trigger!! the event is handled too late

(defmutation on-drop [{:keys [dragged-ident
                              dragged-parent-ident
                              dropped-ident
                              dropped-parent-ident
                              parent-relation
                              parent-key
                              asm-id
                              ordering-attribute]}]
  (action [{:keys [state]}]
          (let [from-path (conj dragged-parent-ident parent-relation)
                to-path (conj dropped-parent-ident parent-relation)
                to-children (get-in @state to-path)]
            (uism/trigger!! app asm-id :event/attribute-changed
                            {::attr/qualified-key parent-relation
                             :form-ident          dropped-parent-ident
                             :form-key            parent-key
                             :old-value           to-children
                             :value               (move-child to-children dropped-ident dragged-ident)})
            (when-not (= from-path to-path)
              (let [from-children (get-in @state from-path)]
                (uism/trigger!! app asm-id :event/attribute-changed
                                {::attr/qualified-key parent-relation
                                 :form-ident          dragged-parent-ident
                                 :form-key            parent-key
                                 :old-value           from-children
                                 :value               (remove-child from-children dragged-ident)})))
            (swap! state
                   (fn [state]
                     (cond->
                         (-> state
                             (update-children to-path ordering-attribute)
                             (dissoc :ui/dragged-component nil))
                       (not= from-path to-path)
                       (update-children from-path ordering-attribute)))))))

Eric Dvorsak12:03:31

So I ended up finding a satisfying solution by extending the state machine

tony.kay20:03:29

it is correct that extending the state machine is a better idea, in that relying on timing semantics of transaction processing in nested contexts does not provide guarantees.

tony.kay02:03:33

There’s nothing special about RAD, really. It’s just autogeneration of Fulcro stuff for you, and meant to be extensible and is written using nothing more than the core primitives that Fulcro provides.