This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-24
Channels
- # arachne (1)
- # aws (1)
- # beginners (43)
- # boot (67)
- # cider (7)
- # cljs-dev (14)
- # cljsjs (6)
- # clojure (215)
- # clojure-czech (2)
- # clojure-dev (12)
- # clojure-dusseldorf (2)
- # clojure-italy (1)
- # clojure-russia (22)
- # clojure-spec (2)
- # clojure-uk (33)
- # clojurescript (85)
- # cryogen (2)
- # cursive (1)
- # datascript (22)
- # datomic (18)
- # dirac (8)
- # hoplon (9)
- # klipse (1)
- # lein-figwheel (5)
- # leiningen (126)
- # off-topic (1)
- # om (57)
- # onyx (159)
- # pedestal (33)
- # planck (2)
- # re-frame (52)
- # reagent (3)
- # ring (2)
- # ring-swagger (16)
- # test-check (12)
- # testing (5)
- # untangled (86)
- # vim (6)
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???
The render refresh story for mutations would still be follow-on local reads, of course.
We have not required anything like that yet, when would it be useful?
'[(add-item ...)]
--> {'add-item {:failed ...}}
--> calls return handler (rh app-state sym value)
(or something similar)
Ah as an alternative to the fallback mutations?
[(am-logged-in?)]
on start -> {'am-logged-in? {:user-id 33 :name "Sam"}}
-> (rh app-state 'am-logged-in {:user-id ...})
Gotcha, thats very interesting.
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 <…>})]
I definitely see where you’re approach would be useful though
throwing an exception on mutation and including a fallback works well, and stops the processing
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)
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.
https://github.com/awkay/untangled-template-workspace/blob/master/src/client/template/core.cljs#L8
":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."
but what does :action
return
yah ok, I guess this would be too confusing, but technically feasible:
{:value {:keys [...]}
:action (fn [] ... {:tempids .. :value ...})}
yah I had no idea until you said that, i thought you added this feature fresh to untangled
@arohner right. one thing I forgot to mention is that whatever you return from the :action thunk will be assoced to the returning response under :result
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.
@gardnervickers nothing we can really do about it. It's your naming convention and state
Alright cool, figured as much 😄
@jasonjckn fixing that delta....and the proj file was wrong on the template
@tony.kay great stuff, mutation results have been frequently talked about for non-optimistic updates, good checkbox to tick
would it be useful to see the real ids part of :tempids
in case you wanted to something with/on them?
@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