This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-10-22
Channels
- # announcements (11)
- # babashka (4)
- # beginners (98)
- # calva (18)
- # chlorine-clover (1)
- # cider (44)
- # clj-kondo (6)
- # clojure (61)
- # clojure-australia (4)
- # clojure-dev (4)
- # clojure-europe (132)
- # clojure-italy (5)
- # clojure-nl (4)
- # clojure-uk (31)
- # clojurescript (40)
- # community-development (8)
- # conjure (20)
- # data-science (1)
- # datomic (42)
- # defnpodcast (6)
- # emacs (3)
- # events (1)
- # fulcro (9)
- # graphql (2)
- # hugsql (1)
- # jobs (1)
- # malli (4)
- # off-topic (28)
- # pathom (27)
- # rdf (1)
- # re-frame (10)
- # reagent (4)
- # remote-jobs (1)
- # reveal (32)
- # sci (5)
- # shadow-cljs (18)
- # spacemacs (1)
- # tools-deps (62)
- # xtdb (4)
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.
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 https://gist.github.com/olivergeorge/29f189ab794527c3692e3160b0232246#file-authfsm-clj-L39. Need to flesh it out. Love how easy the machine is to reason about.
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.
https://www.youtube.com/watch?v=VU1NKX6Qkxc 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 https://lucywang000.github.io/clj-statecharts/docs/integration/re-frame/ 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.
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
::load-datoms.resolve
::load-token.resolve
::init-outbox.resolve
::init-sentry.resolve]
:dispatch [::bootstrap.succeeded]
:halt? true}
{:when :seen-any-of?
:events [::log-exception ::report-anomaly-to-user ::bootstrap.timeout]
:dispatch [::bootstrap.failed]
:halt? true}]}]]}))
Hello! Maybe its a frequent question but how can i run backend in re-frame template?
What re-frame template are you referring to?
lein re-frame
This link says lein watch
: https://github.com/day8/re-frame-template#run-application I am used to lein run
myself.