Fork me on GitHub

I've often seen it recommended to separate code that updates/gets app-db, into their own functions so they can be re-used instead of encoding the same app-db path into many different event handlers. Has anyone come up with a good name for this? I have separate namespaces for events and subs, and I'm considering putting these functions into their own namespace if I find a good name.


Right now I'm considering crud. I think our subs and effect handlers would be much cleaner if we had an own crud namespace for every subpart of app-db.

Oliver George22:10:44

Today I'm in a hammock considering if statecharts-clj can improve the maintainablilty of my re-frame app.  Seems like it could orchestrate but there's some friction in fitting with the re-frame event loop. Love @wxitb2017's work (especially after discovering the :exec false flag). Gist with a  Need to flesh it out.  Love how easy the machine is to reason about.

👍 3
Lucy Wang01:10:16

I decided to use state machines to model the state of web apps after I find myself repeating the same pattern over and over again: a bunch of boolean flags like "loading", "load-failed", "saving", etc, and always performing some actions when these flags are toggled on and off in the code. This is exactly what FSM and StateCharts are designed for. given by the creator of xstate summarizes it really well. It takes some time to shift the mindset from "using a bunch of boolean flags" to "using a state machine". But once one gets familiar with it, the huge payback is definitely worth the time invested. And the more complex the application states are, the more one benefits from it. > but there's some friction in fitting with the re-frame event loop you can use the provided by clj-statecharts, so that you can update the state machine just using re-frame events and no need to call fsm/transition yourself. This almost feels "seamless" because after you defines the state machine, you never need to call it again, just dispatch regular events, and process the events data in the actions.

Lucy Wang08:10:13

there is a #statecharts channel for discussing fsm related topics

Oliver George01:10:24

I'd be interested to see some code doing some bootstrapping stuff. It's not immediately obvious how to do a re-frame async flow seen-all-of? check for multiple independent loading actions. For example, I considered how this might translate...

(defn bootstrap
  [{:keys [db]}]
  (let []
    {:db {:ddb/state    data/empty-db
          :app/loading? true
          :app/online?  false}
     :fx [[:dispatch [::init-db]]
          [:dispatch [::init-outbox]]
          [:dispatch [::init-netinfo]]
          [:dispatch [::init-appstate]]
          [:dispatch [::load-token]]
          [:dispatch-later [{:ms 5000 :dispatch [::bootstrap.timeout]}]]
          [:async-flow {:id    ::bootstrap-flow
                        :rules [{:when     :seen?
                                 :events   [::init-db.resolve]
                                 :dispatch [::load-datoms]}
                                {:when     :seen?
                                 :events   [::load-datoms.resolve]
                                 :dispatch [::init-sentry]}
                                {:when     :seen-all-of?
                                 :events   [::netinfo-connection-status-update
                                 :dispatch [::bootstrap.succeeded]
                                 :halt?    true}
                                {:when     :seen-any-of?
                                 :events   [::log-exception ::report-anomaly-to-user ::bootstrap.timeout]
                                 :dispatch [::bootstrap.failed]
                                 :halt?    true}]}]]}))

Александр Стоянов23:10:20

Hello! Maybe its a frequent question but how can i run backend in re-frame template?

Endre Bakken Stovner18:10:50

What re-frame template are you referring to?

Endre Bakken Stovner20:10:03

This link says lein watch: I am used to lein run myself.