Fork me on GitHub
#fulcro
<
2022-08-05
>
Dean Hayes12:08:44

Hello. I hope it's OK to cross post, just in case any of you Fulcro types are looking for a job atm, we're hiring... https://clojurians.slack.com/archives/C05006WDW/p1659701329745959

❤️ 1
🎉 1
Jeeves19:08:38

Is there a recommended way to create views in the client-side database? E.g. let's say I have a game, and multiple UI components need to know who the current leader is. The current leader is a function of who has the highest score, and instead of having each component query the DB for all players and then finding the one with the max score, I'd like the DB to expose this value and have UI components just query for it directly. I'd prefer not to have to manually update the value in the DB for each mutation that might touch players' scores (error prone and verbose). I tried searching through the Fulcro book, and I might have missed it, but I didn't see a recommended way for handling views like this.

Björn Ebbinghaus12:08:12

You would have to build this yourself. The Client DB is just an atom you can watch. BUT if multiple mutations mutate the player scores you should think about abstracting this action. You don‘t have to put all your logic into a mutation. You can put the update logic for the scores in a simple defn, which does your highscore calculation.

Jakub Holý (HolyJak)20:08:46

As Bjorn writes, Fulcro has nothing like subscriptions in Re-frame. Though they're is an external library offering it - see https://github.com/matterandvoid-space/subscriptions/blob/mainline/examples/fulcro_example.cljs (via https://fulcro-community.github.io/main/awesome-fulcro/README.html) You could also make a memoized fn that computes the score from the players. And I am sure there are other possible solutions.