Fork me on GitHub
#fulcro
<
2021-08-09
>
genekim06:08:57

In the continuing quest to modify RAD Reports to lazily load, I tried to modify the UI State Machine (UISMs), as per @tony.kay’s suggestion. And it definitely is as straightforward to as suggested, although I’m running into strange problems. My goal was to modify the function that :event/run calls, to add a :without #{:trello-cards/comments} . I first modified the state machine, as follows:

(uism/defstatemachine custom-machine
  (-> com.fulcrologic.rad.report/report-machine
      (assoc-in
        [:com.fulcrologic.fulcro.ui-state-machines/states
         :state/gathering-parameters
         :com.fulcrologic.fulcro.ui-state-machines/events
         :event/run
         ::uism/handler]
        ;report/load-report!)))
        my-load-report!)
But when I run a function that is an exact copy of report/load-report!, it
(defn load-report! [env]
  (let [Report         (uism/actor-class env :actor/report)
        report-ident   (uism/actor->ident env :actor/report)
        {::keys [BodyItem source-attribute]} (comp/component-options Report)
        current-params (report/current-control-parameters env)
        path           (conj report-ident :ui/loaded-data)]
    (println "*** my-report-load! ")
    (println "  path: " path)
    (println "  current-params: " current-params)
    (println "  BodyItem: " BodyItem)
    (println "  source-attribute: " source-attribute)

    (log/debug "Loading report" source-attribute (comp/component-name Report) (comp/component-name BodyItem))
    (-> env
      (uism/load source-attribute BodyItem {:params            current-params
                                            ::uism/ok-event    :event/loaded
                                            ::uism/error-event :event/failed
                                            :marker            report-ident
                                            :target            path})
      (uism/activate :state/loading))))
The JavaScript engine hangs upon entering this.. BodyItems and source-attribute are both nil…. I’m a bit baffled, because the only thing that nothing is different than report/load-report! except the namespace it’s in? (And the report will load as expected if I change the function in this state machine to report/load-report!) The last error in console is:
BodyItem:  nil
core.cljs:200   source-attribute:  nil
react_devtools_backend.js:2574 WARN [com.example.ui.trello-list-report:185] -  Loading report null com.example.ui.trello-list-report/ListCards null
Any ideas on what could be going wrong? (Thx to @holyjak for helping me think thru this!)

2
Jakub Holý (HolyJak)06:08:30

I guess the uism/actor-class returns nil? Look at the env, does it look OK?

Jakub Holý (HolyJak)06:08:25

Oh wait, change ::keys to ::report/keys (provided you required rad report ns as that)

genekim16:08:29

Namespaced keywords! Thank you! That’s working now — now trying to get that :without working…

🎉 2