This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-28
Channels
- # admin-announcements (1)
- # beginners (33)
- # boot (35)
- # braveandtrue (1)
- # cider (6)
- # cljs-dev (59)
- # cljsrn (24)
- # clojure (44)
- # clojure-austin (3)
- # clojure-china (1)
- # clojure-russia (13)
- # clojure-spec (63)
- # clojurescript (71)
- # community-development (1)
- # core-async (2)
- # cursive (6)
- # datomic (1)
- # editors-rus (2)
- # emacs (3)
- # hoplon (47)
- # jobs-discuss (3)
- # keechma (1)
- # lein-figwheel (2)
- # om (38)
- # om-next (4)
- # onyx (2)
- # other-languages (63)
- # parinfer (3)
- # planck (4)
- # re-frame (3)
- # reagent (2)
- # slack-help (4)
- # specter (26)
- # tmp-json-parsing (7)
- # uncomplicate (66)
- # yada (7)
(no rush on this — but I feel like I’m going crazy and could use a pointer or two when someone gets a chance) — is it normal to pull out the result of a remote mutation explicitly in the associated read
?
for example, there’s a remote function
(defmethod mutate ‘item/change
[{:keys [ast state] :as env} _ _]
{:action #(swap! state assoc-in [:item :loading] true)
:remote ast
:value {:keys [:item]}})
this goes through send
, changes an item on the server, and then adds a {‘item/change {:result {…}}
map to state. The only way I’ve found to merge in the changes in :result
has been with the read method
(defmethod read :item
[{:keys [query state] :as env} k _]
(let [st @state]
{:value (get-in st [‘item/change :result]
{:id :temp
:hearted false
:link “img/default.jpg"
:loading false})}))
but this feels wrong — there has to be a better way to merge in the changes from the server, right? I just can’t quite figure it out from the docs and examples that I’ve come across, but I’m probably missing something basic@pletcher: post-processing the response from the server, is kind of tricky atm.
What you could be doing, is modifying the send function. When the send
function has access to the reconciler, you can run mutations
after the result has been merged back in
to avoid circular dependencies between the send
& reconciler
, you'll have to write something like this:
(defn make-reconciler
[{:keys [state parser merge merge-tree migrate id-key]}]
(let [escape-hatchet (atom nil)
config {:state state
:parser parser
:migrate migrate
:id-key id-key
:merge merge
:merge-tree merge-tree
:send (transit-post "/api" (assoc {} :reconciler escape-hatchet))}
reconciler (om/reconciler config)]
(reset! escape-hatchet reconciler)
reconciler))
Hmm, that being said. Send might be the wrong place to do post-processing stuff.
Maybe, you'll need to modify the
(defn default-merge [reconciler state res query]
{:keys (into [] (remove symbol?) (keys res))
:next (merge-novelty! reconciler state res query)
:tempids (->> (filter (comp symbol? first) res)
(map (comp :tempids second))
(reduce merge {}))})
You'll have to find a system, where you stick mutations in the app-state & when the response arrives/has been merged, you can automatically run those mutations
Thanks, @iwankaramazow! I really like the second example. tempid
s still seem a bit magical to me, and I'm not quite sure how/where to use them (despite having read through a few examples); but changing the default merge feels a lot cleaner than what I've been doing. I'll play around with that
@pletcher: tempid
s are only relevant if you create new data on the client, persist it on the server and want to swap that 'temporary' id on the client with the real id from the server
sweet, makes sense — thanks again! That seems intuitive now that you’ve worded it that way, but seeing it written out is very helpful 🙂
has anyone been able to extend bidi to support om tempids?
has anyone ran over "Encountered two children with the same key, .$undefined
"?
I'm trying to render two of my components, and om.next sets the key = "undefined"
An obvious way to workaround is to give a key by myself.
@imaximix: yeah happens a lot, and yeah either give it a :keyfn in the factory opts or a :key attr for om.dom
ah yea, found the github issue https://github.com/omcljs/om/issues/673
@currentoor: what do you mean by bidi supporting tempids?
@iwankaramazow: for example in a bidi route you can have [bidi/uuid:id]
and it will automatically encoded and decode id’s for you
i believe it’s possible by extending their protocol, but i was just wondering if someone has done it already
I don't think anyone has done that
I implemented a router, let me check if tempids work in url
so then i could do something like [om/tempid :id]
hmm just tried it out in, tempids in urls might take some extra work
I mean (om/tempid)
gives you #om/id["c62d156a-2a0c-4625-a29a-be93de888e99"]
@currentoor: (subs (str (om/tempid)) 8 44)
😇
works this way
probably not the right solution though
Given the current implementation, is there a way to take out the id as string?
can anyone help me to understand what I’m doing wrong? I’ve created simple repo to explain what I’m struggling with. Pretty please… https://github.com/agzam/om-basic-app