Fork me on GitHub
#untangled
<
2016-04-09
>
vmarcinko05:04:16

hello all, some extreme noob help trying to start with om/untangled...

vmarcinko05:04:36

I read through tutorial, and now I try to play with it, but I'm stuck with working query stuff

vmarcinko05:04:56

anyway, I just initialized untangled client app via simple:

(defonce app (atom (uc/new-untangled-client
                     :initial-state {:my-value   "My value"
                                     :your-value "Your value"}
                     )))

vmarcinko05:04:45

and when I use simple Root component, such as:

(defui Root
  Object
  (render [this]
    (dom/div #js {}
             (str "This are props for this component: " (om/props this)))))
everything displays well (whole state map is displayed in div)

vmarcinko05:04:59

but when I add query fragment in this Root component:

static om/IQuery
  (query [this] `[:my-value])
then error is raised in Chrome console:
A sanity hint for incoming uncaught error:
 return or__26661__auto__;
} else {
return dkey;
}
})();
var by_ident_QMARK_ = om.next.ident_QMARK_ <<< ☢ NULL ☢ <<< .call(null,key);
om_plumbing.cljs:28 Uncaught TypeError: Cannot read property 'call' of undefined

vmarcinko05:04:21

it has to be some stupid thing, but its beyond my newbish reach right now

tomjack06:04:59

om.next/ident? was moved to om.util/ident?

tomjack06:04:19

maybe a newer version of untangled fixed the problem already?

adambrosio06:04:59

if you are using om 32, you might be using a version of untangled that doesnt work with it so unless theres a newer version of untangled out than what you have, you might need to wait till @tony.kay pushes the fix to clojars

vmarcinko07:04:46

@tony.kay: @adambros Thanx guys. Yes, I updated versions of figwheel-sidecar, om and CLJS to newest version, but I thought I won't have any problems with that because I tried that ugprade with whole untangled-todomvc app, and it worked, thus my reasoning

vmarcinko07:04:22

actually, wrong info from me, i ugpraded CLJS and fighweel, but not om next in todomvc, thus it worked there 😞

vmarcinko07:04:41

i guess I should be mroe careful with unstable libs out there

vmarcinko07:04:06

especially because I am total cljs/om newb, so dunno how to decypher these error messages

vmarcinko14:04:50

And another noob question, because I'm totally baffled...Anyway, my app state is following, and I got it dumped by conveniente (log-app-state) function :

{:app-name "My First Untangled App",
 :people
 [{:name "Igor", :address {:city "Osijek", :postcode 31000}}
  {:name "Ante", :address {:city "Zagreb", :postcode 1000}}
  {:name "Mate", :address {:city "Pozega", :postcode 34000}}]}
And I assumed that by using the query:
[:app-name {:people [:name]}]
I would get following:
{:app-name "My First Untangled App",
 :people
 [{:name "Igor"}
  {:name "Ante"}
  {:name "Mate"}]}
but for some reason my component gets this props value:
{:app-name "My First Untangled App", :people [{} {} {}]}

vmarcinko14:04:01

Can somebody enlighten me where I'm wrong at?

cjmurphy15:04:20

Usually you do the queries against a db that is in 'default db format' so you can get db->tree to help. Your app state does not appear to be in in 'default db format'.

ethangracer15:04:32

@vmarcinko: to add to cjmurphy, untangled assumes that your data is in the database format described in the tutorial -- a normalized collection of data and links to that data. If your state is not in that format, we will process it as if it were. That is why you are seeing that value in props -- we are trying to denormalize your database data into a tree, when your data is already in tree format. Lots more information on the normalization process in the untangled and om tutorials, if you're looking for a deeper explanation

vmarcinko19:04:08

@ethangracer: @cjmurphy Thanx again, although in general I udnerstand the idea of normalization, but I thought untangled client would do that for me, when I provide it a initial state map in tree form via (uc/new-untangled-client :initial-state ...) because docs says that Untangled will auto-normalize passed map

vmarcinko19:04:37

so the map I display at the beginning of my previous post is the one I provided as :initial-state option to untangled client constructor

cjmurphy19:04:59

Look at (pprint @my-reconciler) to see if it is normalized (default db format - same thing).

vmarcinko19:04:01

@cjmurphy: Ah, I already manually built normalized version fo this map, passed it to :intiial-state, and noticed it works now, so I guess it does not auto-normalize this map

vmarcinko19:04:28

if I even know what this auto-normalization should do, I never seen it

vmarcinko19:04:53

I'm not even sure how can auto-normalization be perfomed when OM doesn't know what object property has been taken to sserve as identifier - Does it get this information from :keyfn that is set up during factory function creation for that React component or something else?

cjmurphy19:04:28

Close - from the ident method of the component.

vmarcinko19:04:11

ah, ok, thanx, I still haven't researched that bit blush

vmarcinko19:04:32

actually, i don't have that set up in my defui definition

vmarcinko19:04:21

maybe that's why it didn't do auto-normalization, hmmmm...

cjmurphy19:04:40

There's tonnes of examples. I always recommend the Kanban demo - you can see things like {:id 20} being transformed into idents.

vmarcinko19:04:03

yeah, i guess I didnb't do my homerwork well

cjmurphy19:04:48

I like Kanban b/c reading it is a top-down way of learning, where as the tutorials are mostly bottom up.

vmarcinko19:04:08

Kanban is OmNext example, not untangled, right?

cjmurphy20:04:40

Yeah but it will help with this normalization understanding just to look at it and maybe (pprint @its-reconciler) from the browser dev console.

vmarcinko20:04:21

@cjmurphy: OK, as you mentioned, I just had to place (ident ...) on my iterating component (Person), and untangled client constructor perfomed auto-normalization then

vmarcinko20:04:25

so everything works now