Hi all, idiom question: Is it a bad idea to have a read
that doesnโt reflect any part of the app-state/schema?
i.e. if your app state is:
{:school/students []
:school/address โโ}
Is the following an acceptable thing to do?
(defmethod read :student-grades โฆ)
Not a bad idea, and the read key doesn't have to represent a key in the app state.
Oh hello again @hlolli! I remember you ๐ Thanks for the advice!
I have another question though: Is it at all possible to append the result of a remote fetch into a position that isnโt top-level in the app state?
yes, just add a function to merge. So in the reconciler do: {:state blabla :merge mergefn} and define above (defn mergefn [reconciler state res query] (om/default-merge reconciler state (.. here you put the merge logic from res parameter..) query)))
oh, this is perfect! thank you ๐
No problem, I'm still getting the touch for om.next, getting help can be diffucult, so I try my best in situations I can be of any help.
This makes me want to update the wiki (it seems the documentation is out of date) but there seems to be a hold on it
yes, the wiki has improved, but its slow. Yes, an article about :merge would be helpful I think. Just all blogs and articles we are willing to take time to write wil generally improve om.next.
indeed, om.next is one of the most challenging libraries Iโve used to date. ๐ต
Iโm thinking it would make sense to make mergefn a multimethod that dispatches on query. What do you think?
(at least, in the case wherein I expect to merge differently a lot)
Not a bad idea, but that comes to the question of why you don't structure the app state better, are you merging mutations or reads?
merge reads.
as for why I donโt structure the app better, I guess itโs a lack of experience ๐
no, actually, even with good structured data I think doing dispatch on merge is not that bad idea.
but the idea of thinking with links and using normalized data, vectors instead of maps, may be good to get used to, so nested data wont be a problem. But I mostly use denormalized data like a beginner so I can't say much.
Yeah, a lot to study. Thanks, friend! ๐บ
no problem, best of luck with the battle ๐
๐
Whatโs the difference between merge, merge-tree and merge-ident? ๐ฎ
merge is clojure.core fn, merge! is om.next fn, I believe the latter two are just internal library functions, when you use idents or read, there's probably some merge-ing going on under the hood. I assume you understand this (clojure.core/merge {:a {:b 1 :c 2} :d 3} {:a {:b 6 }}) => {:a {:b 6} :d 3}, if so, then you understand what merge is doing.
ah, sorry, i meant the reconciler configs
https://github.com/omcljs/om/blob/master/src/main/om/next.cljs#L2001
these are a lot of configs ๐
didnt know this existed, interesting
Indeed! Anyway, gtg! later man.
@hlolli It looks like the correct config to set is the :merge-tree
, because it is the function that is used for mutating the state. :merge
eventually calls :merge-tree
to do its job.
ok, I will check it out, but I did function for :merge today and it behaved just like I wanted it. Also a remainder for me to read the sources more touroughly. @levitanong please post if you discover something, kind of dead channel here. (of course more activity on #om).