Fork me on GitHub
#untangled
<
2017-06-12
>
eric.shao08:06:07

The “new Getting Started” is untangled. Looking forward the remaining part.😀

bbktsk13:06:42

How should an ident for a singleton look like? E.g. a session data? Should I just pretend there may be multiple of them, invent some meaningless key, have ident return something like [:session/by_id :_] and let untangled normalize it to {:session/by_id {:_ { ... data ...}}}even though there never will be more than one? Or is there some trick/convention for situations like this? The “fake key” should work just fine, it just feels odd.

claudiu14:06:03

@bbktsk You can take a look at how it's in the untangled template. https://goo.gl/l7Vc6S

tony.kay15:06:46

@bbktsk There is query notation for pulling something from root, so that it can just be at the root

tony.kay15:06:22

[ {[:keyword '_] (om/get-query Session)} ]

tony.kay15:06:59

The underscore (which has to be quoted to keep the compiler from whining) means “singleton at the root”

tony.kay15:06:07

when used in an ident

tony.kay15:06:23

The join isn’t necessary if there isn’t nested normalized state there

bbktsk15:06:33

Exactly what I needed, thanks.

tony.kay15:06:44

you could just say: [ [:keyword '_] ] and that will give you the opaque thing at root

tony.kay15:06:34

when you use these link queries to root, you’ll get :keyword in props, so destructuring is easy

tony.kay15:06:54

if you join on a real ident, the thing you’ll get in props will be (of course) keyed by that ident.

tony.kay15:06:00

which of course is how you could pull a specific item from a table: [ {[:person/by-id 1] (om/get-query Person)} ]

tony.kay15:06:08

@bbktsk One word of warning. If a component queries for nothing but a thing from root, then you still must include some initial state for that component (or the query won’t even try to walk to that node)

tony.kay15:06:19

just an empty map is enough

tony.kay15:06:46

@eric.shao Thanks. working on it now, actually.

tony.kay19:06:24

OK, the new Getting Started Guide is nearly complete. I’d love any proofreading feedback. REST stuff is still coming.

bbktsk19:06:43

Stuck again, this time on routing. Is it possible to have a single router with some routes that have a parameter and some that do not? The example in https://untangled-web.github.io/untangled/guide.html#!/untangled_devguide.M15_Routing_UI has top_router with all routes without param and report-router with all routes with a param. Also, how’d I pass multiple params to a route? :route-params in route-to takes a map, but route-instructions takes an ident and there’s place for only one param… Also, I do not understand the role of ident method of a router. A router has the map of keyword->component, so what does it need the ident for?

tony.kay19:06:52

ok, let’s start with the ident question

tony.kay19:06:10

You’re routing over various sub-components, each which needs an ident, and query

tony.kay19:06:36

the router, however, uses what’s called a Union query, so that only one component’s query is processed (for speed): the one that is on-screen

tony.kay19:06:02

it figures that our from the TABLE (type) of the ident that is pointing to the current thing on the screen

tony.kay19:06:14

So, the router (union query component) gets the ident function

tony.kay19:06:22

and it must work for all sub-screens

tony.kay19:06:48

and furthermore it must generate the correct first-element of the ident (one of the keywords that names you screen)

tony.kay19:06:16

It’s a lot of little gotcha’s, but such is the price of performance on the queries in a large UI 🙂

tony.kay19:06:02

The params are intended to become the “ID” of the ident (generally), thus potentially routing you to specific instances of screens

tony.kay19:06:33

Ofcourse, your mutation that triggers the route, should also make sure the newly-targeted screen data exists

tony.kay19:06:28

It is expected that a given router (route instruction) will be setting one and only one ident in the app state (pointing to that particular UI switch in the routing tree)…so there is no place for another param to go

tony.kay19:06:10

The implication is that an HTML5 route of /accounts/4/child/5 would map to a tree that has an account and child router. The account router would receive 4 as a parameter, and child 5.

tony.kay19:06:30

so, two routers to switch, two routing instructions, but ONE event trigger to do the routing

tony.kay19:06:55

so route-to is meant to switch multiple routers at once, via your routing tree.

tony.kay19:06:23

which is why it needs possibly multiple parameters

bbktsk19:06:48

I see. So yes, I can mix parameter-less and parameter-having routes in a single router, but it’s ident must be smart enough to generate correct value depending on current route?

tony.kay21:06:12

(defrouter X :x (ident ...) :screen-1 Screen1 :screen-2 Screen2)

tony.kay21:06:28

the ident better generate idents of the form [:screen-1 ???] or [:screen-2 ???]

tony.kay21:06:35

the ??? are up to you @bbktsk

tony.kay21:06:17

and your state of Screen1 and 2 better have some way of letting the ident function figure that out

tony.kay21:06:01

Anyone trying out the getting started: I refer to the developer’s guide. I have not updated the dev guide to the latest cleanup of the lib yet, so names may be wrong.

tony.kay23:06:36

OK, the REST example is in the GettingStarted.adoc guide now.