This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-08
Channels
- # babashka (9)
- # beginners (43)
- # biff (4)
- # calva (11)
- # cider (6)
- # clerk (1)
- # clj-kondo (4)
- # cljs-dev (6)
- # clojure (82)
- # clojure-berlin (1)
- # clojure-europe (42)
- # clojure-nl (1)
- # clojure-norway (182)
- # clojure-quebec (1)
- # clojure-uk (19)
- # clojurescript (6)
- # datahike (1)
- # emacs (30)
- # fulcro (5)
- # honeysql (6)
- # hyperfiddle (12)
- # lambdaisland (8)
- # malli (11)
- # off-topic (36)
- # pathom (26)
- # pedestal (1)
- # portal (25)
- # practicalli (1)
- # rdf (29)
- # re-frame (17)
- # reitit (1)
- # releases (1)
- # sci (37)
- # shadow-cljs (15)
- # vim (10)
- # xtdb (13)
I’m currently using Datascript with Re-frame (sans re-posh, because I’m still not sure about using Datascript in the long-term) and I have subs that basically query the DS DB like this:
(re-frame/reg-sub
:user/user
(fn [db [_ user-id]]
(datascript/q '[:find (pull ?e [*]) .
:in $ ?user-id
:where [?e :user/id ?user-id]]
@(:app.db/*conn* db) user-id)))
Trouble is, every time I insert new data in the DS DB, the subs don’t really update and I have to click something (ie update app-db
) to make the new info appear. Now, I’ve done some research and found https://github.com/day8/re-frame/blob/master/docs/Subscribing-To-External-Data.md
However, it seems this isn’t the recommended way to do this anymore. If so, what is? Should I introduce an :app.db/updated-at
value and make the subs I want to update depend on that instead? Seems clunky.For someone who isn't sure about Datascript, you seem to be willing to learn about its internals. :) Instead, I would recommend just sticking to re-posh for the time being. In case you change your mind, getting rid of a few helper functions is easier than integrating Datascript yourself.
To answer the actual question - the recommended approach is to have subscriptions fully passive. Events drive changes - subscriptions only react.
Hmm, I did try that approach before, using both a Datascript DB via re-posh (and only putting domain data there) + app-db
(for UI state), but it felt like I was ‘doing it wrong’.
> subs fully passive
So…in this case, would you put queries in a coeffect then? Then store the results in the app-db
?
Just do what re-posh documents. Don't search for the way to do things when you aren't even sure about the tech you're using. First, make sure that Datascript is something that you'll be using. I have no idea how Datascript works, I don't use it myself. It might very well be that its model is incompatible with re-frame's best practices and that you have to make some sacrifices - ones that re-posh has probably already made on your behalf.
Instead of re-posh
@U051MTYAB Thanks, I’ll take a look. Although it might be too late to switch DBs since my architecture is basicaly datalevin on the backend and *a materialised view of that as a datascript DB on the frontend.
Hmm, apparently re-posh has a caching bug that I immediately ran into
Which means I either have to dig in and make a PR (which I’m nowhere near confident enough to do) or look at other options
(ie it has the same behaviour where inserting new data in the Datascript DB doesn’t make the subs update)
My impression of re-posh is that it was a fun experiment but is never quite reached production-ready status. There were performance problems and bugs. But I could be wrong - just the impression I somehow have from some time ago. Hence me recommending doxa and relic.
Seems like adding an :app/tick
event that gets dispatched after every upsert works as a hack. I just have an :app.db/updated-at
value and I assoc the current time to it.
Yeah…got really excited when I first learned about it + DatSync. I figured we’d finally get tonsky’s https://tonsky.me/blog/the-web-after-tomorrow/ but alas
Hmm, apparently re-posh has a caching bug that I immediately ran into