This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-01-24
Channels
- # adventofcode (1)
- # announcements (22)
- # babashka (30)
- # beginners (69)
- # calva (53)
- # cider (17)
- # cljfx (1)
- # clojure (2)
- # clojure-australia (1)
- # clojure-europe (1)
- # clojurescript (36)
- # code-reviews (10)
- # conjure (3)
- # cursive (2)
- # datomic (4)
- # fulcro (13)
- # graalvm (261)
- # luminus (2)
- # malli (1)
- # nrepl (13)
- # off-topic (19)
- # rdf (3)
- # reveal (1)
- # ring (3)
- # sci (66)
- # shadow-cljs (14)
- # spacemacs (1)
- # specmonstah (1)
- # test-check (1)
- # vim (2)
- # xtdb (14)
Hey guys if I have my client state as
{ :list/id {:accounts { :list/accounts [ [:account/id 1] [:account/id 2] ....] } } }
I was trying to query for it w/ the following:
(db->tree [{:list/id [:accounts]}] {} (current-state SPA))
I'm getting {}
returned, I was wondering what would be the appropriate query to retrieve the list of accounts@alexander.890 (db->tree [{[:list/id :accounts] [{:list/accounts [*]}]}] (current-state SPA) (current-state SPA)) This should solve your question. The second arg to db->tree is the starting-entity which should not be an empty map. In most cases, querying from the root, you can use state-map i.e. (current-state SPA) as the starting-entity as well. Using the query shown by Tony, you use join to "drill down" into the subquery, where [*] is determined by your data design, for example [:account/name :account/status].
Just read Tony's new chapter on Core API and learnt something new. Turns out @U0CKQ19AQ has already given you the full answer. By using ident [:list/id :account]
as a query element, you can indeed put an empty map as the starting-entity because the ident already provides the starting-entity. So, this works too:
(db->tree [{[:list/id :accounts] [{:list/accounts [*]}]}] {} (current-state SPA))
P.S. There are many ways to make this work. Long story short, check out Tony's new chapter, especially the section on denormalization: https://book.fulcrologic.com/#_denormalization
So, I’ve added a new chapter, targeted at semi-beginners, to the book: https://book.fulcrologic.com/#_core_api
It encourages you to explore the core API of Fulcro with a simple CLJ REPL, and I hope it will help beginners gain an understanding of the very simple concepts at the center of Fulcro.
I know there’s a lot of material out there, and I keep trying to find a way to narrow people’s focus on what is truly core to understanding Fulcro. This chapter is my attempt at that.
The new chapter is more than helpful. Full of gems, simply outstanding. Many thanks @U0CKQ19AQ for sharing your knowledge and wisdom with us.