datomics pull-api actually goes both ways with reverse-lookup [1]
by using reverse lookups you could have the dashboard query look something
like
[{:dashboard/items [:item :name {:_cart [:id]}]
(minus om/get-query things). Such a data-structure would make highlighting
easy, just look if the attribute :_cart is non-nil.
{:books [{:item 1 :name "Joy of Clojure" :_cart {:id "cart-id-1"}
{:item 2 :name "Domain driven design"}
{:item 3 :name "Thinking fast and slow"}]}
I don't know exactly how to do this in om-next, but in Datomic this works
quite well.
[1] http://docs.datomic.com/pull.html#reverse-lookup
/Linus
2016-03-29 13:29 GMT+02:00 Serzh Nechyporchuk <[email protected]>:
> Hi to everyone,
>
> I'm am very excited about the new version of Om. It really moves front-end
> developing to the new level, so you can deal with much bigger complexity.
>
> But I have one concern about it, that I can't resolve by myself.
> David talks all the time that client must have an ability to ask data and
> shape of that data from the server. So you have one API endpoint with
> datomic-pull like API to work this problem out. With this approach
> hierarchy of your components must always follow the hierarchy in your data.
> You can't change the "shape", you only can change keys you want in
> resulting map. Data flows only from top to the bottom and not in any other
> way. For example
>
> I have app data looks like this:
>
> {:books [{:item 1 :name "Joy of Clojure"}
> {:item 2 :name "Domain driven design"}
> {:item 3 :name "Thinking fast and slow"}]
> :cart [{:item 1 :name "Joy of Clojure"}]}
>
>
> And I have components:
>
> (defui Item
> static om/Ident
> (ident [this {:keys [id]}]
> [:item/by-id id])
> static om/IQuery
> (query [this]
> [:id :name]))
>
> (defui Dashboard
> static om/IQuery
> (query [this]
> `[{:dasboard/items ~(om/get-query Item)}]))
>
> (defui Cart
> static om/IQuery
> (query [this]
> [{:cart/items ~(om/get-query Item)}]))
>
> (defui RootView
> static om/IQuery
> (query [this]
> `[{:dashboard ~(om/get-query Dashboard)}
> {:cart ~(om/get-query Cart)}]))
>
>
> so I have Cart and Dashboard reuse same Item component.
>
> The task is to add Item to the Cart from Dashboard on click and highlight
> it as added. There are no problems with adding, but there is one problem
> with highlighting. So, there are two options:
> * just add flag to the Item that it is added
> * look at the cart/items when rendering items to see if it is added
> The first option adds some redundancy to the data, so the second is more
> preferable. For second option Item component should have :dashboard map as
> prop.
>
> So the whole problem that I can’t figure out how to do this, how to
> describe this in a query. So this, datomic-like, API allows you to create
> element hierarchy that can only follow the hierarchy in the data.
>
> Thank you.
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/clojurescript.
>
--
Note that posts from new members are moderated - please be patient with your
first post.
---
You received this message because you are subscribed to the Google Groups
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/clojurescript.