untangled

NEW CHANNEL: #fulcro
2016-09-12T22:16:42.000044Z

defui SearchTable [{[:search :tab] [:es-type :es-sort-fields :sort-ascending?]}
                    {:hits (get-query SearchTableRow)}
                    :total]

2016-09-12T22:16:52.000045Z

(defui SearchTab [{:hits (get-query SearchTable)}

2016-09-12T22:17:38.000046Z

i do load-field-action on :hits in SearchTab, and this causes the props to have not-found

2016-09-12T22:18:17.000048Z

so far I haven't noticed any issues in production with this, and everything still works as expected

2016-09-12T22:18:34.000049Z

but it would be nice if load-field-action excluded [:search :tab] like it would exclude :ui/foobar

tony.kay 2016-09-12T22:18:51.000050Z

load field should narrow the query to JUST the field

2016-09-12T22:19:00.000051Z

it does

2016-09-12T22:19:04.000052Z

i'm loading :hits on SearchTab

tony.kay 2016-09-12T22:19:17.000053Z

yeah, so [:search :tab] should not be affected

2016-09-12T22:19:32.000054Z

this is the behaviour i'm seeing

tony.kay 2016-09-12T22:20:15.000055Z

are you right at a union?

tony.kay 2016-09-12T22:20:23.000056Z

the ident might be confused?

2016-09-12T22:20:30.000057Z

so the api-read is going to see a query like [:search [{:hits [:hits :total [:search :tab]]}]]

2016-09-12T22:20:40.000058Z

notice I have 2 :hits in my example so it's confusing

tony.kay 2016-09-12T22:20:50.000059Z

why is :search :tab there?

tony.kay 2016-09-12T22:21:04.000060Z

remember that that is an ident

2016-09-12T22:21:13.000061Z

yes I need access to that data in SearchTable

2016-09-12T22:21:28.000062Z

i was hoping idents would be stripped out like ui/foobar is stripped out

2016-09-12T22:21:35.000063Z

putting an ident in a query is valid om.next syntax

2016-09-12T22:21:39.000064Z

but it shouldn't be sent to the server

tony.kay 2016-09-12T22:21:47.000065Z

it is, but you're saying the SERVER should return it

tony.kay 2016-09-12T22:21:54.000066Z

by putting it in load-field's query

tony.kay 2016-09-12T22:22:00.000067Z

which overwrites it

tony.kay 2016-09-12T22:22:27.000068Z

totally valid thing to ask for, but you're unintentionally asking for it

tony.kay 2016-09-12T22:22:34.000069Z

no way to automatically elide that

tony.kay 2016-09-12T22:22:58.000070Z

load-field has a :without option for this kind of case, but not sure we tested an ident case

2016-09-12T22:23:06.000071Z

i agree the case is contrived a bit, but sticking with my analogy on ui/foobar, if I load-field-action on :hits, and the query was [:search [{:hits [:hits :ui/foobar]}]] that would not be sent to the server

tony.kay 2016-09-12T22:23:25.000072Z

:ui prefix is defined to always be elided...separate issue

tony.kay 2016-09-12T22:23:30.000073Z

an ident is valid query syntax

2016-09-12T22:23:36.000074Z

oh ok

tony.kay 2016-09-12T22:23:37.000075Z

(to server)

2016-09-12T22:23:55.000076Z

i guess that's my confusion I thought an joining on an ident has no meaning server side

tony.kay 2016-09-12T22:24:01.000077Z

in fact, load-field sends and ident-based join to the server 🙂

2016-09-12T22:24:15.000078Z

i'll try without 🙂

tony.kay 2016-09-12T22:24:22.000079Z

[:type-of-thing id] makes total sense to a server 🙂

tony.kay 2016-09-12T22:24:28.000080Z

if it is a persistent thing

2016-09-12T22:24:28.000081Z

Yah I see now

2016-09-12T22:24:37.000082Z

nods okay, i'll use computed props or something

tony.kay 2016-09-12T22:24:51.000083Z

try :without. We should make that support idents

2016-09-12T22:24:58.000084Z

k

tony.kay 2016-09-12T22:25:10.000085Z

it may "just work". Have not looked at the impl

tony.kay 2016-09-12T22:25:20.000086Z

but it should just work 😉

2016-09-12T22:25:35.000087Z

so in this case, when the server returns data for the ident, do you automatically merge it into [:search :tab] ?

tony.kay 2016-09-12T22:25:40.000088Z

:without #{[:type :id]}

tony.kay 2016-09-12T22:26:13.000089Z

merge is recursive on return value, and since you asked for it but didn't return it: not-found

tony.kay 2016-09-12T22:26:50.000090Z

though technically the sweep step should turn not-found into literally nothing...that's a minor bug too

2016-09-12T22:27:30.000091Z

it's weird to see anything at all in the global state at [:search :tab :hits [:search :tab]] for the ident [:search :tab], because if I actually returned a value from the server for [:search :tab] it would not exist in the global state at the path [:search :tab :hits ...] the data would be merged into [:search :tab], and then when om.next computes the props for the query [... [:search :tab]] it would fill it in

2016-09-12T22:27:42.000092Z

but as it stands I see [:search :tab] not found in the global state under hits

2016-09-12T22:28:14.000094Z

yah "into literally nothing" i guess we're on the same page 🙂

tony.kay 2016-09-12T22:28:19.000095Z

oh right. that's a little screwy

tony.kay 2016-09-12T22:30:00.000096Z

it should have totally "wiped" your :tab entry of the :search table

tony.kay 2016-09-12T22:30:20.000097Z

that's another ident-related merge bug, I'd say

tony.kay 2016-09-12T22:30:28.000098Z

when the ident isn't in a join (perhaps)

2016-09-12T22:32:18.000100Z

https://github.com/untangled-web/untangled-client/issues/29 here's the first bug

tony.kay 2016-09-12T22:32:29.000102Z

thanks

2016-09-12T22:35:58.000103Z

fyi i'm starting to write a series of little addons to our untangled project, i'm not sure they're suitable for mass adoption, but they work in all our use cases and simplify the API

2016-09-12T22:36:22.000104Z

so i'll entertain you with the list of addons fyi 🙂

2016-09-12T22:36:46.000105Z

1) i wrote my own transact! to never require an apostrophe on the query

2016-09-12T22:37:10.000106Z

(defmacro transact!
  ([txs]
   `(transact! (:reconciler @admin.core/app) ~txs))

  ([reconciler txs]
   (let [txs (->> txs
                  (mapv (fn [xf]
                          (if (list? xf)
                            (let [[mutation-sym & args] xf]
                              (assert (symbol? mutation-sym))
                              `(list (quote ~mutation-sym) ~@args))
                            xf))))]

2016-09-12T22:39:00.000107Z

wrote my own defui macro that returns a factory when you do @MyComponent, and also expects query as 2nd argument

2016-09-12T22:39:12.000108Z

(defmacro defui [name q & forms]
  {:pre [(symbol? name)
         (or (map? q) (vector? q) (list? q))]}
  `(let [factory-fn# (atom nil)]
     (om.next/defui ~(with-meta name {:once true})

         ~'static cljs.core/IDeref
         (~'-deref [this#]
          @factory-fn#)

         ~'static om.next/IQuery
         (~'query [this#]
          ~q)

         ~@forms)

     (reset! factory-fn#
             (om.next/factory ~name {:keyfn (framework.core/mk-defui-keyfn ~name)}))))

2016-09-12T22:39:32.000109Z

it also uses ident as the react-key by default

2016-09-12T22:39:41.000110Z

if no idents, then it uses GUID

2016-09-12T22:39:47.000111Z

good enough for our purposes

2016-09-12T22:41:40.000114Z

in our mutations you can bind a mutation namespace to an ident, so that the 'ref' is always set to the binding for any mutation that begins with myns/foobar

2016-09-12T22:41:53.000115Z

(m/bind-ns-to-singleton-ref! 'search admin.ui.search.core/SearchTab [:search :tab])

2016-09-12T22:42:21.000116Z

this let's us transact! from anywhere on (search/...) and still have the mutation implementation leverage 'ref'

2016-09-12T22:42:45.000117Z

you can also bind namespaces to ComponentType

2016-09-12T22:44:03.000118Z

(m/bind-ns-to-component! 'search-row admin.ui.search.table/SearchTableRow)
in this case when transacting on this, (presumably a child of SearchTableRow such as SearchTableRowColumnXYZ ) any mutation that that has namespace search-row/xxx will find the nearest parent with component type SearchTableRow

2016-09-12T22:44:24.000119Z

so the idea here is to use computed props less

2016-09-12T22:44:35.000120Z

and just have transact! be applied to relevant parent

2016-09-12T22:44:48.000121Z

hope that's useful

2016-09-12T22:48:24.000122Z

i guess another would be I have swap-this! swap-global!

2016-09-12T22:48:31.000123Z

swap-global! is just swap! on app state

2016-09-12T22:48:38.000124Z

swap-this! is swap! on app state + ref

2016-09-12T22:48:59.000125Z

(defmethod m/mutation 'search-row/activate-listing [env _ params]
  {:action (fn []
             (m/swap-this! env assoc :status "ACTIVATED"))})

tony.kay 2016-09-12T23:03:42.000126Z

Yeah, I like the swap helpers. Not quite following what the bind things are doing. I'm a little tired today...not thinking very fast 😕

tony.kay 2016-09-12T23:04:04.000127Z

The deref trick for factories is an interesting twist

tony.kay 2016-09-12T23:09:20.000128Z

ah, I see on your binding. Interesting. A bit more convoluted on the ref bit. Harder to trace what's going wrong when things bubble like that, but tractable.

tony.kay 2016-09-12T23:19:33.000129Z

I can see how that reduces some of the boilerplate

2016-09-12T23:24:33.000130Z

@tony.kay fyi the deref trick code I wrote doesn't work in :advanced mode yet 😞

2016-09-12T23:24:52.000131Z

i think 'static' has some issues in advanced that i'm not appreciating

tony.kay 2016-09-12T23:25:07.000132Z

you using the latest Om/UC?

2016-09-12T23:25:10.000133Z

yes

tony.kay 2016-09-12T23:25:19.000134Z

I think there was a static fix, but perhaps it didn't get merged yet

2016-09-12T23:25:23.000135Z

hm interesting

2016-09-12T23:25:30.000136Z

i'll try it out i haven't tested advanced in 2 months