untangled

NEW CHANNEL: #fulcro
tony.kay 2016-10-24T15:13:00.002874Z

So, due to an oversight on my part, I missed the fact that there was a pretty easy way to get return values to work on mutations from the server (instead of requiring a follow-on remote read). The latter is a great and viable way to leverage the normal mechanisms of Untangled to get the desired effect; however, I think it would be pretty easy to inject a step in the merge phase that could collect results of mutations and dispatch them to a function of your choosing (configured at startup). I'm assuming there would be interest in that???

tony.kay 2016-10-24T15:13:52.002875Z

The render refresh story for mutations would still be follow-on local reads, of course.

gardnervickers 2016-10-24T15:52:16.002876Z

We have not required anything like that yet, when would it be useful?

tony.kay 2016-10-24T15:54:25.002877Z

'[(add-item ...)] --> {'add-item {:failed ...}} --> calls return handler (rh app-state sym value) (or something similar)

gardnervickers 2016-10-24T15:55:18.002881Z

Ah as an alternative to the fallback mutations?

tony.kay 2016-10-24T15:55:30.002882Z

yes, that is one use

tony.kay 2016-10-24T15:56:34.002883Z

[(am-logged-in?)] on start -> {'am-logged-in? {:user-id 33 :name "Sam"}} -> (rh app-state 'am-logged-in {:user-id ...})

tony.kay 2016-10-24T15:56:54.002884Z

e.g. user reloaded page and your session is still good

tony.kay 2016-10-24T15:57:22.002885Z

instead of (load [:current-user])

tony.kay 2016-10-24T15:57:54.002887Z

everything can be done without it, but in some cases it is easier to think abt

tony.kay 2016-10-24T15:58:03.002888Z

and less to implement

gardnervickers 2016-10-24T15:58:24.002889Z

Gotcha, thats very interesting.

tony.kay 2016-10-24T15:58:47.002890Z

then your rh can be a multimethod or whatever you find easy .... just a function

tony.kay 2016-10-24T15:59:39.002891Z

might make sense to ahve the signature match parser read/mutate for consistency

tony.kay 2016-10-24T15:59:42.002892Z

[env k p]

gardnervickers 2016-10-24T16:01:58.002893Z

We’ve benefited quite a bit from separating things out into multiple small mutations. For example our login form might look like this

[(log-in {:username <..>})
 (fetch-profile {:token <…>})]
While our on-page-load callback just calls
[(fetch-profile {:token <…>})]

gardnervickers 2016-10-24T16:02:08.002894Z

I definitely see where you’re approach would be useful though

tony.kay 2016-10-24T16:04:52.002895Z

Same here. It would reduce network chatter to detect problems

tony.kay 2016-10-24T16:05:04.002896Z

well, depending on how you implement

tony.kay 2016-10-24T16:05:53.002897Z

throwing an exception on mutation and including a fallback works well, and stops the processing

tony.kay 2016-10-24T18:11:30.002898Z

OK, return values supported from server mutations now: on 0.6.0-SNAPSHOT. Example in the untangled-template-workspace on master (https://github.com/awkay/untangled-template-workspace)

tony.kay 2016-10-24T18:12:36.002900Z

was easy enough to add. I tend to prefer the follow-on reads, but I can see targeted use cases. I am a little worried that it will weaken ppls designs.

2016-10-24T18:14:45.002901Z

any docs on this? where do the return values get loaded in app state?

tony.kay 2016-10-24T18:14:51.002902Z

they don't

tony.kay 2016-10-24T18:15:04.002903Z

they trigger a return handler. See the template example

2016-10-24T18:15:10.002904Z

k

2016-10-24T18:16:58.002909Z

interesting

2016-10-24T18:17:02.002910Z

thanks

tony.kay 2016-10-24T18:17:15.002911Z

sure. Trivial to use. State atom is in env

tony.kay 2016-10-24T18:17:59.002912Z

also fixes the bug of mutation symbols ending up in app state

2016-10-24T18:18:10.002913Z

nice

2016-10-24T18:22:14.002914Z

@tony.kay ":result" made more sense than ":value" used everywhere else?

tony.kay 2016-10-24T18:22:24.002915Z

I think that is the Om standard

tony.kay 2016-10-24T18:22:30.002916Z

if it isn't, I should fix it

2016-10-24T18:22:37.002917Z

i see :value a ton in OM

2016-10-24T18:22:40.002918Z

never seen :result yet

tony.kay 2016-10-24T18:22:48.002919Z

that's beacuse default merge throws it away

2016-10-24T18:23:01.002920Z

k

tony.kay 2016-10-24T18:23:40.002923Z

Yeah, :result

2016-10-24T18:24:39.002924Z

it doesn't show up in the OM next docs though? it's an internal key?

2016-10-24T18:24:48.002925Z

:value shows up in the OM next docs for reads

2016-10-24T18:25:45.002926Z

":mutate - a function of three arguments [env key params] that should return a valid parse mutation result map. This map should contain a :value and an :action entry."

adambros 2016-10-24T18:26:31.002930Z

but what does :action return

tony.kay 2016-10-24T18:27:07.002931Z

mutation :value must be nil or a map with structure {:keys [...]}")))

tony.kay 2016-10-24T18:27:24.002932Z

on mutations, value is about advertising updated data

tony.kay 2016-10-24T18:27:27.002933Z

not returning a result.

2016-10-24T18:29:24.002934Z

yah ok, I guess this would be too confusing, but technically feasible:

{:value {:keys [...]}
 :action (fn [] ... {:tempids .. :value ...})}

tony.kay 2016-10-24T18:32:15.002936Z

Chat about :result

tony.kay 2016-10-24T18:32:30.002937Z

see #om around this timestamp

2016-10-24T18:34:00.002938Z

gotcha

tony.kay 2016-10-24T18:34:15.002939Z

I had forgotten that Om even supported it

tony.kay 2016-10-24T18:35:48.002940Z

that discussion is what spurred me to make the addition

2016-10-24T18:36:09.002941Z

yah I had no idea until you said that, i thought you added this feature fresh to untangled

tony.kay 2016-10-24T18:36:13.002942Z

technically, though, I'm realizing I changed it a bit

tony.kay 2016-10-24T18:36:45.002943Z

any value you return gets assoc'd to :result by Om

tony.kay 2016-10-24T18:37:06.002944Z

so I might want to change that

2016-10-24T18:37:20.002945Z

@arohner right. one thing I forgot to mention is that whatever you return from the ⁠⁠⁠⁠:action⁠⁠⁠⁠ thunk will be ⁠⁠⁠⁠assoc⁠⁠⁠⁠ed to the returning response under ⁠⁠⁠⁠:result⁠⁠⁠⁠

2016-10-24T18:37:25.002946Z

yes you did something slightly different

tony.kay 2016-10-24T18:37:33.002947Z

yep

gardnervickers 2016-10-24T18:37:43.002948Z

I’m not sure how much protection Untangled would want to provide around this, but we learned the hard way that data-fetch/load will break tab unions where the server-property argument is the same as the top level client-db key.

tony.kay 2016-10-24T18:38:24.002949Z

@gardnervickers nothing we can really do about it. It's your naming convention and state

gardnervickers 2016-10-24T18:38:53.002950Z

Alright cool, figured as much 😄

tony.kay 2016-10-24T18:50:41.002951Z

@jasonjckn fixing that delta....and the proj file was wrong on the template

2016-10-24T18:51:49.002952Z

@tony.kay great stuff, mutation results have been frequently talked about for non-optimistic updates, good checkbox to tick

tony.kay 2016-10-24T18:52:09.002953Z

that too

tony.kay 2016-10-24T18:52:47.002954Z

with that cahnge the return handler gets the tempids remap map...I guess that's ok

2016-10-24T18:53:03.002955Z

seems okay to me

tony.kay 2016-10-24T18:53:05.002956Z

don't remember when the migrate happens

tony.kay 2016-10-24T18:53:08.002957Z

before or after

tony.kay 2016-10-24T18:53:11.002958Z

so that might be useful

tony.kay 2016-10-24T18:53:26.002959Z

should check that order and doc it

tony.kay 2016-10-24T18:53:59.002960Z

migrate is first, as I'd expect

tony.kay 2016-10-24T18:56:10.002961Z

done and pushed. On clojars 0.6.0-SNAPSHOT

👍 1
tony.kay 2016-10-24T18:56:14.002962Z

template updated too

tony.kay 2016-10-24T19:07:52.002963Z

I kinda feel like we should elide tempids, since they're already handled

👍 1
tony.kay 2016-10-24T19:08:01.002964Z

might be confusing when debugging?

adambros 2016-10-24T19:08:49.002965Z

would it be useful to see the real ids part of :tempids in case you wanted to something with/on them?

2016-10-24T19:09:06.002966Z

i'm agnostic on the subject

tony.kay 2016-10-24T19:10:07.002967Z

@adambros not that I can think of. You'd need to know more, whch you'd have to include in the rv from your mutation, at which point you can include the specific id(s) there

tony.kay 2016-10-24T19:10:21.002968Z

if you remapped 6 things, it would just be confusing

tony.kay 2016-10-24T19:10:46.002970Z

cause you would not know what the tempids meant (they've lready been migrated out of existence in your app state)

tony.kay 2016-10-24T19:20:13.002972Z

done and pushed. tempids not passed through