untangled

NEW CHANNEL: #fulcro
eric.shao 2017-06-12T08:50:07.950104Z

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

2017-06-12T13:57:42.223854Z

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.

claudiu 2017-06-12T14:09:03.481743Z

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

tony.kay 2017-06-12T15:04:46.788630Z

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

tony.kay 2017-06-12T15:05:22.803039Z

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

tony.kay 2017-06-12T15:05:59.817611Z

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

tony.kay 2017-06-12T15:06:07.820950Z

when used in an ident

tony.kay 2017-06-12T15:06:23.827401Z

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

2017-06-12T15:06:33.831398Z

Exactly what I needed, thanks.

tony.kay 2017-06-12T15:06:44.835620Z

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

tony.kay 2017-06-12T15:07:34.854479Z

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

tony.kay 2017-06-12T15:07:54.861749Z

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

tony.kay 2017-06-12T15:09:00.887603Z

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

tony.kay 2017-06-12T15:10:08.913559Z

@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.kay 2017-06-12T15:10:19.917665Z

just an empty map is enough

tony.kay 2017-06-12T15:10:46.927508Z

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

tony.kay 2017-06-12T19:35:24.623472Z

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

2017-06-12T19:37:43.668158Z

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.kay 2017-06-12T19:38:52.691115Z

ok, let’s start with the ident question

tony.kay 2017-06-12T19:39:10.696386Z

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

tony.kay 2017-06-12T19:39:36.705096Z

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.kay 2017-06-12T19:40:02.713465Z

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

tony.kay 2017-06-12T19:40:14.717446Z

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

tony.kay 2017-06-12T19:40:22.720099Z

and it must work for all sub-screens

tony.kay 2017-06-12T19:40:48.728735Z

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

tony.kay 2017-06-12T19:41:16.737424Z

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

tony.kay 2017-06-12T19:42:02.752557Z

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

tony.kay 2017-06-12T19:42:33.762198Z

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

tony.kay 2017-06-12T19:43:28.777589Z

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.kay 2017-06-12T19:44:10.791414Z

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.kay 2017-06-12T19:44:30.798688Z

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

tony.kay 2017-06-12T19:44:55.807083Z

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

tony.kay 2017-06-12T19:45:23.816761Z

which is why it needs possibly multiple parameters

2017-06-12T19:52:48.961025Z

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.kay 2017-06-12T21:20:33.667097Z

correct

tony.kay 2017-06-12T21:21:12.678166Z

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

tony.kay 2017-06-12T21:21:28.682769Z

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

tony.kay 2017-06-12T21:21:35.684825Z

the ??? are up to you @bbktsk

tony.kay 2017-06-12T21:22:17.696621Z

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

tony.kay 2017-06-12T21:24:01.725478Z

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.kay 2017-06-12T23:44:36.422248Z

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