Fork me on GitHub
#om
<
2017-04-07
>
benbot14:04:33

Hey so I just picked up clojure and i’m making a fun little app with it, but I hit a snag in frontend land. I can’t’ figure out exactly what the difference between om and om.next is. So… what’s the difference?

benbot14:04:49

and why would I use old om vs om.next

levitanong14:04:53

@benbot om is a thin wrapper around react, and has a forgiving learning curve. It doesn’t take much to learn om if you already know React. Om.next tries to do a bunch of things like incremental rendering, an async render loop, components that specify what information they need, among a bunch of other bells and whistles.

benbot14:04:13

@levitanong so is om.next to om like re-rame is to reagent?

benbot14:04:18

but… built in?

levitanong14:04:45

I’d like to say it’s sort of re-frame++ to reagent. 😛

levitanong14:04:50

but yes, built in

benbot14:04:08

Do you think I should be using om.next right from the start, or mess around with om by itself first?

benbot14:04:14

Also, if i don’t use om.next

benbot14:04:28

it doesn’t get compiled into the final js right?

levitanong15:04:38

@benbot IMHO Any gains you get from om won’t translate into om.next, so if you intend to pick up om.next at any time in the future, you might as well start with it.

levitanong15:04:52

@benbot not sure what you mean by the final js thing.

benbot15:04:32

@levitanong Since om.next is built into om, if I don’t use anything from om.next, will that code still be in the compiled JS

benbot15:04:05

also I don’t really like how om.next uses objects 😞 avoiding objects is why i started learning clojure in the first place lol

levitanong15:04:14

@benbot ah, i think you’ll have to go on advanced compilation to get rid of the extraneous code. (Will need someone more qualified to confirm this) Ah, you’re talking about the static om/IQuery stuff?

benbot15:04:55

that and the while (defui Object ...) stuff

benbot15:04:34

You can implement methods on objects that were defined with defui it all seems very NOT clojure-y

levitanong15:04:54

@benbot but you have to go through that stuff with om anyway. reify

benbot15:04:10

hrm i didn’t know that

levitanong15:04:57

protocols are a fundamental part of clojure/script, and are a big reason why they interoperate well with java/script. They’re OOP-esque, sure—but they’re constrained to very specific areas of the code you deal with, so it’s manageable.

peeja15:04:48

@carter.andrewj No, the merge doesn't know where the data came from (AFAIK), but typically what you want to do is have your send (which does know the remote) massage the data as necessary into a uniform format before passing it to the send callback.

peeja15:04:32

@carter.andrewj Stay tuned, I've got some work coming that should make it easier. 🙂

carter.andrewj15:04:18

@peeja Thanks, man 🙂 I've got the first bit working now (by precisely the route you're suggesting - so good to know I'm headed in the right direction). Interesting on the coming-soon teaser 😛

carter.andrewj15:04:33

I was literally just typing another question while you replied...

carter.andrewj15:04:47

I'm currently trying to get om.next to create a nested set of similar objects - I don't know how many objects there will be ahead of time, so I structured the data as a hierarchy (that gets built from the results of send, as mentioned above). However, to get om to render these components, I needed to add the following to the query: {:children (om/getQuery ThisComponent)} - which has resulted in the app trying querying itself forever and exceeding the maximum call stack size.

peeja15:04:18

Ah! Have I got syntax for you!

carter.andrewj15:04:19

I was hoping this would be handled lazily behind the scenes and so just work as-is, but it appears that's not the case

peeja15:04:31

{:children ...}

carter.andrewj15:04:35

Ah-ha! I was hoping there was a way to get this sorted 🙂

peeja15:04:59

Actually ...

carter.andrewj15:04:01

Or are you pausing for effect? 🙂

peeja15:04:07

Nope, that's it 🙂

peeja15:04:11

(Quoted, of course)

carter.andrewj16:04:01

Thanks, mate 🙂 I had a moment of "Oh, god - how do I get around this one..." there

peeja16:04:47

So [:foo :bar {:children ...}] will read :foo and :bar off the current thing and then off each of its children, and their children, and so on

peeja16:04:13

You can also limit recursion to a particular depth with a number, like [:foo :bar {:children 5}]

peeja16:04:34

Those come straight from datomic's syntax

peeja16:04:17

A word of warning, though: while that's the syntax to express what you want, there's only so much that Om itself does for you to make that happen (at least for now). Your parser code is going to be responsible for some of it.

peeja16:04:27

So, play with it 🙂

carter.andrewj16:04:02

Yes, there's something not working perfectly currently - but it's not throwing any errors, so presumably I just need to take a closer look at my data structures

carter.andrewj16:04:13

Currently, I build the nested map manually and call tree->db on the full result

carter.andrewj16:04:34

Will that work as expected? Or would I need to call that at a lower-level of the process?

peeja16:04:37

@carter.andrewj tree->db or db->tree?

peeja16:04:51

db->tree will handle the recursion for you. tree->db is for normalizing during merge, and shouldn't care about recursion.

carter.andrewj16:04:49

But all I need it for is normalization of the data, once it's been received/structured, (I think...)

peeja16:04:12

Yep, that should work fine

carter.andrewj19:04:19

@peeja And indeed it does! (after some mis-steps with seqs (that should have been vectors) and malformed idents, etc...)

peeja19:04:13

@carter.andrewj Sweet! Glad to help!