This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-25
Channels
- # beginners (27)
- # boot (49)
- # cider (51)
- # cljs-dev (29)
- # cljsjs (1)
- # cljsrn (19)
- # clojure (59)
- # clojure-austin (2)
- # clojure-belgium (19)
- # clojure-china (1)
- # clojure-dev (14)
- # clojure-dusseldorf (7)
- # clojure-russia (8)
- # clojure-spec (115)
- # clojure-uk (45)
- # clojurescript (118)
- # css (6)
- # cursive (8)
- # datascript (20)
- # datomic (32)
- # emacs (5)
- # events (2)
- # flambo (21)
- # hoplon (58)
- # incanter (8)
- # jobs-rus (1)
- # jobs_rus (1)
- # off-topic (3)
- # om (22)
- # om-next (9)
- # onyx (5)
- # other-languages (79)
- # re-frame (126)
- # reagent (6)
- # ring (7)
- # specter (1)
- # untangled (119)
- # yada (38)
@jasonjckn: I’m working on a project that is half high-level overview of the component technologies, half tutorials for building basic UI that will tie back code samples to those high level concepts. If that’s the thing that you feel may help your team, feel free to ping me with ideas and thoughts https://github.com/egracer/untangled-intro
@ethangracer: Thank you for this, I’ll give it a whirl 🙂...
great, still very much in development — whole sections not finished yet (currently no coding sections). my goal with the sections finished so far is to simplify the high level overview to a point that it makes sense but doesn’t sacrifice technical accuracy or depth. any feedback is definitely appreciated
@ethangracer: wonderful stuff, yah this will help the team, looking forward to seeing you fill it out
are 'links' suppose to work at any depth in the root query? from the docs it sounds like they always bring you back to the root of the database
so I wrote as a root query
{:foobar [{[:todo-list/by-id '_] [:title]}]}
which works as expected, but if its 2 layers deep it doesn't work {:foobar [{:foobar [{[:todo-list/by-id '_] [:title]}]}]}
so, usually you want to use links to access top-level data, because requesting a table with idents will return a lot of data
Yes, any depth.
links should go to a top-level key...e.g. app state might say {:item [:list/by-id 3]}
and then a query joined on [:item '_]
would work
@tony.kay: can you add an ident at any level of the query to get at the data at that ident?
I thought that links were a special query form
Idents point to items in tables. Links point to top-level keys which in turn are linked via idents
i just tried that I have a root query of
{:foobar [{:foobar [{[:todo-list/by-id 1] [:todo/title]}]}]}
and a database of {:foobar {:foobar {}} :todo-list/by-id {...}}
the props passed to Root are :foobar {}Also, I assume your nested table has a key for 1, and a value there that has a :todo/title
i'll query at the REPL the exact data/query i'm working with and paste here to clarify
query
[:ui/support-visible :ui/react-key :ui/locale {:foobar [[:items _] [*]]} {:todos [:db/id {:list/items [:db/id :item/label :item/complete :ui/editing]} :list/title :list/filter]}]
initial state :initial-state {:list (or (get-url-param "list") "main")
:todo/by-id {1 {:db/id 1 :todo/title "got milk?"}
2 {:db/id 2 :todo/title "bar"}}
:todo-list/by-id {1 [[:todo/by-id 1]
[:todo/by-id 2]]}
:items [[:todo/by-id 1]
[:todo/by-id 2]]
;;:main {:dev {:todos [:todo-list/by-id 1]}}
:foobar {:foobar {:foobar {:foobar nil}}}
:todos {:list/title ""
:list/items []
:list/filter :none}}
no errors just
[196.704s] [om.next] RERENDER: NOTE: If your UI doesn't change, make sure you query for :ui/react-key on your Root and embed that as :key in your top-level DOM element
So, remember that the UI query is used for normalization..do you have queries on your UI? If so, are you composing them together? Do you have idents on your UI?
If you plug an app database into untangled without an atom, it tries to use the UI query to normalize it. If you use a raw (non-composed query) then metadata will be missing from the query for normalization.
I mean, you can probably use a link without a join...but you'll get a raw dump of the thing at the location in state
[:ui/support-visible :ui/react-key :ui/locale {:foobar [{:foobar [{[:items _] [*]}]}]} {:todos [:db/id {:list/items [:db/id :item/label :item/complete :ui/editing]} :list/title :list/filter]}]
;(defui ^:once NewComp
static om/Ident
(ident [this props]
[:newcomp 1])
static om/IQuery
(query [this]
[{:foobar [{[:items '_] '[*]}]}])
Object
(render [this]
(dom/div nil
(prn-str (om/props this)))))
(def new-comp (om/factory NewComp))
(defui ^:once Root
static om/IQuery
(query [this] `[:ui/support-visible
:ui/react-key
:ui/locale
#_ {:main [{:dev [{:todos ~'[*]}]}]}
{:foobar ~(om/get-query NewComp)}
#_ {:ui/main [{:dev [{:todos [:db/id :todo/title]}]}]}
{:todos ~(om/get-query TodoList)}])
this code works great though
(defui ^:once NewComp
static om/Ident
(ident [this props]
[:newcomp 1])
static om/IQuery
(query [this]
[{[:items '_] '[*]}])
Object
(render [this]
(dom/div nil
(prn-str (om/props this)))))
(def new-comp (om/factory NewComp))
(defui ^:once Root
static om/IQuery
(query [this] `[:ui/support-visible
:ui/react-key
:ui/locale
#_ {:main [{:dev [{:todos ~'[*]}]}]}
{:foobar ~(om/get-query NewComp)}
#_ {:ui/main [{:dev [{:todos [:db/id :todo/title]}]}]}
{:todos ~(om/get-query TodoList)}])
and if you give a component an Ident, then it has to exist in the app state at that db table location
If you compose in a component that gives an ident, then the data for it better exist in a table at that ident location
I suspect there is a bug right now as well. Afaict you can’t force auto-normalization at all when passing in an atom with the latest alphas; you used to be able to pass in :normalize true
when constructing the reconciler but that seems to have stopped working.
@tony.kay: I think it may have been this commit: https://github.com/omcljs/om/commit/6243eb499b865894ba680cb8e6c56db9d404d8a8
norm?
will be true when passing in an atom and in add root it only normalizes if the :normalize
flag is set and norm?
is falsey.
I don’t understand that. How can you pass in an atom and still get it to normalize since norm?
will always be true and thus it will never normalize during add-root
?
I worked around this by just passing in a map and getting a reference to the atom after the reconciler was created using om/app-state
.
right, but you used to be able to pass in :normalize true
in the reconciler to tell it that your atom is not normalized (and enable normalization for merged etc.) but that no longer works after this change.
you either want normalization ON or OFF in the entire app. Untangled ALWAYS turns it on
that is the more common case...it is trivial to NOT pass an atom to say you didn't normalize it
so, now it is possible to do every case, just the API changed slightly...don't pass an atom if you mean to indicate non-norm data
:normalize does exactly one thing, ever: turns on or off auto-normalization (for merging novelty on server returns, and initial state iff it is not an atom)
I agree, my question is really is it intended that the public api should change in this way.
Discussed it with David and Antonio...there was no way to get the case some people needed with the old behavior
Cases: 1. You want normalization everywhere: pass a map as initial state, and normalize true 2. You want normalization everywhere, except initialization: pass an atom and normalize true 3 and 4. You don't want normalization: pass in whatever the hell you want for initial state and set normalize false
It looks to me that you could handle all cases and allow passing in an atom with normalization turned on by adding another param to reconciler
like skip-initial-normalize?
and instead of :normalized norm?
when creating the reconciler state you’d have :normalized skip-initial-normalize?
. That way it wouldn’t be a breaking change either.