Fork me on GitHub
#om
<
2015-12-15
>
chris-andrews00:12:22

Also, (om/get-query MyComponent) works, but (om/get-unbound-query MyComponent) returns the same error. Are these meant to be used on instantiated components only?

chris-andrews00:12:01

All work correctly on instantiated components, so I will assume that’s the expected usage

dnolen00:12:12

@chris-andrews: yes those are only for instantiated components currently

chris-andrews00:12:52

@dnolen: thanks for clearing that up for me!

chris-andrews00:12:17

The docs page for get-query and get-unbound-query list MyComponent for the argument, as opposed to get-params, which lists x. set-query! lists some-component as an argument. Would it make sense for me to update the docs so they all list some-component, so it is hopefully clear that they should be used this way?

dnolen00:12:38

@chris-andrews: hrm, I’ll need to think about whether the current behavior should be relaxed

dnolen00:12:43

so no don’t change the docs

chris-andrews00:12:54

ok, sounds good

adamfrey01:12:46

is there an om project online that uses tempids other than the om-tutorial?

jannis01:12:55

It's not the prettiest piece of code but perhaps it can give some ideas

rgbboy10:12:27

Just started learning clojure and om and have come across something that hurts my brain a little. I have been working through the wiki page on [Normalization](https://github.com/omcljs/om/wiki/Components,-Identity-&amp;-Normalization).

rgbboy10:12:33

If you run the last example without the om/add-root! call and you call (deref reconciler) you get the same value as init-data. Once you add the om/add-root! call the derefed value becomes a normalized view of the data. I don't understand if the reconciler is immutable? If so, how does the deref value change by calling om/add-root!?

jetmind11:12:24

@rgbboy: reconciler internally keeps an atom with a state in it, which can change

rgbboy11:12:13

@jetmind: Ahhh ok. I am very new to all this. I just found out about the bang convention for functions that mutate.

anmonteiro11:12:20

@rgbboy: when you add-root! with a map as :state or an atom and set :normalization true, the reconciler will normalize the data

txus14:12:05

@anmonteiro: regarding the normalization

txus14:12:02

I can’t seem to reproduce what’s in the example — partial information with just the idents

anmonteiro14:12:22

@txus: sorry what are you referring to? simple_smile

txus14:12:24

as in, having somewhere {:user/id 1 :user/name “bar”} and somewhere {:user/id 1}

txus14:12:00

I don’t think I understand how the reconciler finds out they are the same thing, because I have a defui User with an om/Ident of [:user/by-id (:id user)] but the reconciler doesn’t seem to pick it up

txus14:12:14

I’m wondering how would it know at all — through the tree of components, checking if any has an ident?

anmonteiro14:12:58

@txus: could you provide more context? I don't remember what you're talking about

txus14:12:22

hm, so, my real case: I have :app/users and :app/sections, which are lists. Then I have an :app/current-user and an :app/current-section, and they have respectively [:user/by-id :foo] and [:section/by-id :bar]. There exists a User component with an om/Ident and a Section component as well, and they are both rendered through a RootView (indirectly, through more components). Now, for some reason the :app/current-section gets normalized to :app/current-section [[:section/by-id nil] [:section/by-id nil]]

txus14:12:44

but the :app/current-user gets normalized correctly

anmonteiro14:12:03

do you have this code somewhere?

anmonteiro14:12:30

have you tried om/tree->db with your init-data and your root component to test normalization?

txus14:12:50

yeah, the value of :app/current-section is [[:section/by-id nil] [:section/by-id nil]] there already @anmonteiro

txus14:12:04

so I figured it’s normalization that goes wrong in the first place

anmonteiro14:12:58

I'd say if normalization goes wrong in the first place

anmonteiro14:12:04

your queries might be wrong

anmonteiro14:12:13

or it is a bug in Om (unlikely)

anmonteiro14:12:45

if you could post the component tree w/ respective queries somewhere

anmonteiro14:12:55

I could take a look

txus14:12:50

hmmm I found what was different

txus14:12:15

the root query queried for [:app/current-user {:app/current-section [:section/id :section/name]}]

txus14:12:30

but changing it to [:app/current-user :app/current-section] made it work uhm

txus14:12:45

@anmonteiro: I’m getting another no queries exist for etc… https://gist.github.com/txus/4b421085c2c922dbc687

txus14:12:27

that’s the component tree with their queries. I scoped everything to {:root because I thought that was the way to avoid this — making the extra step so that the RootView is actually scoped to :root

txus14:12:09

but I feel scoping everything is not really getting me anything, as I still seem to get wrong the query paths?

anmonteiro14:12:47

give me a moment

anmonteiro14:12:54

I haven't tried it yet

anmonteiro14:12:01

but it seems that your queries don't match your data

anmonteiro14:12:07

so there could be something right there

txus14:12:57

hm in which way don’t they match? I can’t see it :S

txus15:12:15

(I think 99% of my problems is not really seeing when my queries match my data heh)

anmonteiro15:12:15

RootView is doing something odd

anmonteiro15:12:26

with the unquote splicing

anmonteiro15:12:46

wait, actually that's not wrong

anmonteiro15:12:26

it's just complected

anmonteiro15:12:33

what's wrong with [{:root ~(om/get-query UserProfilesView)}]

anmonteiro15:12:17

@txus: everything looks OK with queries & data for me

anmonteiro15:12:32

where are you getting this error?

jetmind15:12:42

I tried code from your gist and everything is ok:

(cljs.pprint/pprint (om/tree->db RootView init-data init-data))
{:root {:app/users [[:user/by-id :guest]]},
 :user/by-id {:guest {:user/name "guest", :user/id :guest}},
 :om.next/tables #{:user/by-id}}

anmonteiro15:12:33

@jetmind: you are aware that the 3rd arg to tree->db should be true or false right?

anmonteiro15:12:47

it's working for you because a map is truthy

jimmy15:12:47

yeah, the last param should be boolean

txus15:12:08

@anmonteiro: I used the unquote splicing because in practice there are more queries there so it’s easier to stack them simple_smile

jetmind15:12:36

@anmonteiro: yeah, right, thanks for clarification. I guess I have confused what tree->db vs db->tree takes

anmonteiro15:12:58

@txus: so your problem might be right there

anmonteiro15:12:08

stealing queries again

anmonteiro15:12:20

can't be sure though

txus15:12:38

ag now I’m getting a problem in query_template. With this root query: [{:root [{:app/users [:user/id :user/name :user/authenticated]} :app/current-section]}]

txus15:12:42

does this look wrong?

dnolen15:12:10

@txus I do not recommend grabbing at straws with queries

dnolen15:12:24

you really should be able to test this stuff just by writing some parses

dnolen15:12:36

as in actually write some tests verifying the behavior of query

dnolen15:12:23

if these work then you can isolate the issue to something about your components

txus15:12:57

@dnolen: you’re right. I’ll start testing normalization and then build on that

wilkerlucio19:12:57

nice podcast with @dnolen talking about Om.next http://blog.cognitect.com/cognicast/093, good one David simple_smile

pletcher20:12:30

I’m having a bit of a problem with local state. I’m not sure I understand why a call to set-state! is failing and throwing the same error as above (`“No queries exist..”`)

pletcher20:12:53

Coming from vanilla React, I’m confused by how set-state! is supposed to work — I would have thought that it completely ignored the reconciler

pletcher20:12:11

(I guess it does — that’s probably part of my confusion)

dnolen20:12:16

@pletcher: that’s probably not a state problem

dnolen20:12:42

also Om set state has absolutely no connection to React facilities

dnolen20:12:50

other than we ride on the state map

pletcher20:12:24

I see — thanks

dnolen20:12:20

@pletcher: all API originated state transitions involve the reconciler in some way

dnolen20:12:34

set-state!, set-query!, transact!, merge!

pletcher20:12:25

Hmm, cool — I think I’m having to get rid of some of the assumptions that I brought in from React simple_smile And (this is probably a dumb question) it’s taken as given that the component hierarchy mirrors the query hierarchy? i.e., there’s no more reaching into a flat(-ish) map from anywhere in the component tree — it’s all about passing parts of the query hierarchy down through components?

dnolen20:12:55

@pletcher: in Om Next components are dumb

dnolen20:12:05

they don’t do anything - no control logic at all

dnolen20:12:13

beyond the most simple reacting to user events

dnolen20:12:42

the app state is flat (via normalization or custom storage)

dnolen20:12:55

queries create the ui data tree which simply fed into dumb components

dnolen20:12:48

the whole thing is designed to be incremental

dnolen20:12:07

so we can run queries and recompute any subtree

dnolen20:12:27

so this erases any need to cache stuff yourself in the component tree with local state

pletcher20:12:18

cool — I think I’m starting to wrap my head around it — thanks!

pletcher22:12:09

Finally had a chance to figure out the problem I was having: I have a router that swaps in a different view in my Root component. When that component updates, it updates its query with the view’s query by calling om/set-query!, but Root’s static query stays the same — just [:view]. Pretty sure that’s the wrong way to go about it

thosmos22:12:27

@pletcher: my latest iteration was that as well, but called [:route]. The only downside to that I can see is that the client is refetching from the server on each view change and isn't specifying what fields it wants, but is just receiving what the server gives it. Now I'm doing something like [{:route {:index [:content ] :contact [:content] :etc [:content]}}] and then changing that in (defmethod read :route) to only send one of those to the server at a time. I'm unsure if this is much better, but at least the client is describing what it needs and the root query has the full map to start with.

iwillig22:12:02

Is the om.next TodoMVC Example https://github.com/swannodette/om-next-demo still the best place to look for example of om.next integration with Datomic?

dnolen22:12:30

@iwillig: it’s out of date but it does gives the basic idea yes

dnolen22:12:49

not sure when I’ll have any time to update it, too busy with other more pressing Om Next things now

blissdev23:12:27

om.previous question: I’m rendering of set of ordered child components, and then I reorder them and that updates fine, but the state that I pass to them does not get updated, any ideas why that might be? I tried moving it from init-state to just state but still no luck. Looks like: https://gist.github.com/blissdev/218641072d7e915d1e3b

blissdev23:12:00

the :render-position does not seem to update upon re-render in the new order

blissdev23:12:13

if it helps i’m using set-state! to set the new element-sort

blissdev23:12:08

tried using get-render-state but I think I’m probably attacking the wrong problem

dnolen23:12:04

@blissdev: you must supply React ref correctly

pletcher23:12:13

@thosmos interesting — I might try something like what you’re doing now. Thanks for the tip!

blissdev23:12:01

@dnolen I’m not sure I understand, do you mean the react-key?

dnolen23:12:14

@blissdev: oops yeah React key

blissdev23:12:22

@dnolen Correctly? I thought it needed to be a unique string? Does it need to be globally unique? Something else?

blissdev23:12:07

I’ll reread the docs and see where I’m going wrong. Thanks for the pointer.