This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-15
Channels
- # adventofcode (46)
- # announcements (3)
- # aws (7)
- # babashka (47)
- # beginners (86)
- # calva (40)
- # cider (8)
- # clj-kondo (22)
- # clojure (63)
- # clojure-europe (16)
- # clojure-hungary (3)
- # clojure-nl (1)
- # clojure-norway (46)
- # clojure-sweden (1)
- # clojure-uk (3)
- # clojuredesign-podcast (2)
- # conjure (4)
- # datalevin (1)
- # events (1)
- # fulcro (5)
- # graalvm (4)
- # honeysql (8)
- # hyperfiddle (15)
- # music (1)
- # off-topic (5)
- # pathom (7)
- # pedestal (1)
- # polylith (3)
- # portal (19)
- # quil (1)
- # re-frame (36)
- # releases (1)
- # specter (3)
- # sql (3)
- # timbre (11)
- # tools-deps (4)
- # xtdb (55)
I am working on firebase/firestore app., but I have js/Promise related question. I don't know a lot about promises, just how to chain them and that js code is full of awaits and js async code looks elegant.
In the mutation I am removing marker two early, otherwise code works . To maintain consistent state, all data is mutated on the backend and then fetched again.
1. I need a proper transaction to optimistically change frontend before backed?
2. Which lib is preferred for promise handling, promesa?
(defmutation next-program*
"increment program"
[{:keys [tasks] :as params}]
(action [{:keys [state app] :as env}]
;; send to database and read it back - suboptimal but DRY!!!!
(df/set-load-marker! app fbase/login-marker :loading)
(-> (fbase/user-doc)
(.update (clj->js {:program-number fbase/fld-inc-1
:tasks (map :topic tasks)}))
(.then (fn [result](fbase/<-users-db))) ;; !!! another promise inside
(.catch (fn [error]
(log/error "next-program*" error))))
(df/remove-load-marker! app fbase/login-marker)))
By design firebase should be a remote. All asynchronous behavior can be handled there more elegantly, and the mutation will then be more natural. Promesa is nice for promises. You can also adapt a promise into core async fairly easily. Personally I would probably also make a rad database adapter for saves that runs on the front end.
Ok, I will implement the remote, in my case, for the basic stuff I should just in :transact! look into ast and then call firebase api? I was looking Chapter 14. and I really don't know what should, to cause rollback of the transaction.
This is my another "I'am not smart enough moment":
{:body some-edn
:original-transaction original-tx-or-query
:status-code n}
I was looking for rad adapters in another project, saving in postgres, but implementing updates with preserving the history, so basically converting updates into inserts.
at the end i just created a new formsafe mutation (in cljs is a copy of yours) and in the backed was like, for this tables, create this updates in inserts, and return this. not very generic. :)
(end of confession, expecting frogs from the sky)
While watching https://www.youtube.com/watch?v=bqA250jqMTg I got an idea, that would be nice to create a Fulcro response. but i still on wax on, wax off 🙂
So there are a number of ways you could create a cljs “remote”. One would be to use pathom to make resolvers and “firebase mutations” (it has a cljs async parser that can deal with the read async) and then just pass the query/mutation through to that. Otherwise, yes, you have to look at the AST (or convert it to a query/mutation) and figure out what to do.