om-next

levitanong 2016-08-30T11:43:25.000003Z

Hi all, idiom question: Is it a bad idea to have a read that doesnโ€™t reflect any part of the app-state/schema?

levitanong 2016-08-30T11:44:45.000004Z

i.e. if your app state is:

{:school/students []
 :school/address โ€œโ€}
Is the following an acceptable thing to do?
(defmethod read :student-grades โ€ฆ)

2016-08-30T12:24:51.000005Z

Not a bad idea, and the read key doesn't have to represent a key in the app state.

levitanong 2016-08-30T12:29:58.000006Z

Oh hello again @hlolli! I remember you ๐Ÿ˜„ Thanks for the advice!

levitanong 2016-08-30T12:30:52.000007Z

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?

2016-08-30T12:33:07.000008Z

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)))

levitanong 2016-08-30T12:33:51.000010Z

oh, this is perfect! thank you ๐Ÿ˜„

2016-08-30T12:34:46.000011Z

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.

levitanong 2016-08-30T12:34:48.000012Z

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

2016-08-30T12:36:25.000013Z

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.

levitanong 2016-08-30T12:37:59.000014Z

indeed, om.next is one of the most challenging libraries Iโ€™ve used to date. ๐Ÿ˜ต

levitanong 2016-08-30T12:38:22.000015Z

Iโ€™m thinking it would make sense to make mergefn a multimethod that dispatches on query. What do you think?

levitanong 2016-08-30T12:39:17.000016Z

(at least, in the case wherein I expect to merge differently a lot)

2016-08-30T12:39:18.000017Z

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?

levitanong 2016-08-30T12:39:31.000018Z

merge reads.

levitanong 2016-08-30T12:40:07.000019Z

as for why I donโ€™t structure the app better, I guess itโ€™s a lack of experience ๐Ÿ˜›

2016-08-30T12:40:11.000020Z

no, actually, even with good structured data I think doing dispatch on merge is not that bad idea.

2016-08-30T12:41:43.000022Z

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.

levitanong 2016-08-30T12:42:56.000023Z

Yeah, a lot to study. Thanks, friend! ๐Ÿบ

2016-08-30T12:43:54.000024Z

no problem, best of luck with the battle ๐Ÿ™‚

levitanong 2016-08-30T12:48:10.000025Z

๐Ÿ˜„

levitanong 2016-08-30T12:53:38.000026Z

Whatโ€™s the difference between merge, merge-tree and merge-ident? ๐Ÿ˜ฎ

2016-08-30T12:59:27.000027Z

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.

levitanong 2016-08-30T13:00:23.000028Z

ah, sorry, i meant the reconciler configs

levitanong 2016-08-30T13:00:42.000031Z

these are a lot of configs ๐Ÿ˜›

2016-08-30T13:01:09.000032Z

didnt know this existed, interesting

levitanong 2016-08-30T13:01:45.000033Z

Indeed! Anyway, gtg! later man.

levitanong 2016-08-30T17:34:28.000034Z

@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.

2016-08-30T18:53:46.000035Z

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).