Fork me on GitHub
#fulcro
<
2021-08-04
>
genekim16:08:06

Inside of a mutation, how does one get a "this" to a RAD report so I can pass it as the one argument required to report/run-report!? I want to send it an event — in lieu of knowing that, I'm using uism/trigger!. Thank you!!!

(m/defmutation run-report [_]
      (action [{:keys [app state]}]
        (println "mutation: next-page: ")
        ;(report/run-report! (comp/get-class (comp/registry-key->class :com.example.ui.trello-list-report/ListCards)))))
        ; TODO: where do I get a "this" for report/run-report!?
        (uism/trigger! app (comp/get-ident (comp/registry-key->class :com.example.ui.trello-list-report/ListCards)
                             {}) :event/run)))

tony.kay16:08:42

Triggering :event/run is what you do in a mutation. You don't have this, nor should you rely on it in a mutation. Also, the ident of a report is well-known, so you also don't need to use the registry...it's just [::report/id :com.example.ui.trello-list-report/ListCards] . I'd make convenience wrappers for these, but not sure what to name them 🙂

tony.kay16:08:54

Actaully, I guess I could just make a second arity

tony.kay17:08:58

Released RAD 1.0.14 with updated functions that accept an app/report key or class.

😍 3
genekim18:08:46

Doh. I already had the ident, and didn’t need to go through all that registry lookup. [facepalm.] Nice. Thx for ergonomic addition!

genekim19:08:03

Another RAD question — in a mutation, I’m noting the strange behavior that further mutations/transactions aren’t being run when called from the ok-action . Is this expected behavior? (See the last line in the ok-action block.) PS: See this neat (and maybe very important) trick that @tony.kay showed me in using m/returning and rc/nc to ensure that all values from the server are returned! (Otherwise, you’ll likely find that it returns nothing, because it wasn’t explicitly satisfied. Very cool, and so much more convenient that having to specify everything in a defsc.)

(m/defmutation archive-card
      [params]
      (action [{:keys [ref app state]}]
      ; ...
      (remote [env]
        (-> env
           ; VERY COOL TRICK!
           ; this rc/nc command: let the resolver let everything return result thru: elide nothing, which
           ; the default result handler will do
           (m/returning (rc/nc ['*]))))
      (ok-action [{:keys [app state result]
                   :as env}]
        (let [mutation-result (-> result :body (get `archive-card) :ui/mutation-result)
              {:keys [message ok?]} mutation-result]
          (println "mutation: archive-card: result: " mutation-result)
          (if ok?
            (delete-card-from-list! app state (:trello-list/id mutation-result) (:trello-card/id mutation-result))
            ; vvv THIS NEVER SHOWS UP IN TRANSACTIONS in Fulcro Inspect
            (comp/transact! app [(run-report {})]))
          nil))
      (error-action [{:keys [app state result env]}]
      ;  ...nil)))))

tony.kay19:08:48

do you mean when? That transact is in the else position of an if

genekim20:08:09

OMG. [facepalm]. I meant to put a do there — argh. Thank you, @tony.kay!!! (And I’m so glad I asked, lest I thought there was something magical about that portion of mutations — which seemed quite unlikely, and very unlike the Fulcro philosophy, but late at night, those are the types of incredibly faulty conclusions you make. 🙂