Fork me on GitHub
#om
<
2016-06-05
>
ag20:06:41

anyone using om.next with datascript? aside obvious benefits, what pitfalls should be avoided?

whistlerbrk20:06:13

Having a simple problem I can’t seem to solve. Building a demo app of a shopping carts. Products and a cart. When you click “add to cart” from a product in the listing the item appears in a cart. I have all this working except when I push an item into cart_items I’m not sure how I’m suppose to do this — I need to keep track of count since you can say purchase more than one of same product. So my initial idea was: {:products [{id: 1 name: “Foo”}] :cart {1: {count: 3 product: [:product/by-id 1]}}}

whistlerbrk20:06:35

so I’ve made my :cart db-style (a map whose keys are the product ids) so I can easily update the count. Is this bad? Should I consider a different way, most importantly, I need to get that product info when I’m rendering a CartItem and I don’t know how to do it

tomjack21:06:22

it seems easier to make cart just be a vector

tomjack21:06:16

updating the count may look weird, but probably will be fast enough anyway?

whistlerbrk21:06:19

@tomjack: yeah, I can’t seem to figure out how to get the data for the product into the cart item doing it the way I am right now

whistlerbrk21:06:24

so I might as well try that

tomjack21:06:03

it seems maybe doable with the map if you write some custom read logic, but I'm not sure what to do about ui->props

tomjack21:06:41

I'm thinking default-ui->props with path-meta might be confused

whistlerbrk21:06:18

@tomjack so, I’m trying the other route. https://gist.github.com/whistlerbrk/c003125f605bbfae6dadb6ec3ca630a2 you’ll see in my init data I’ve primed the cart, but I still can’t get that product ref to work, I’m assuming the issue is in my defui for CartItem

tomjack21:06:10

It seems to me that your CartItem query should be something like [:id :count {:product (om/get-query ...)}]

tomjack21:06:24

Have you deref'd the reconciler to see what your normalized data looks like?