om

Please ask the channel first, not @dnolen directly!
benbot 2017-04-07T14:27:33.938932Z

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?

benbot 2017-04-07T14:27:49.945069Z

and why would I use old om vs om.next

levitanong 2017-04-07T14:44:53.328195Z

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

benbot 2017-04-07T14:50:13.449517Z

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

benbot 2017-04-07T14:50:18.452011Z

but… built in?

levitanong 2017-04-07T14:50:45.462444Z

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

levitanong 2017-04-07T14:50:50.464024Z

but yes, built in

benbot 2017-04-07T14:54:08.538904Z

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

benbot 2017-04-07T14:54:14.541314Z

Also, if i don’t use om.next

benbot 2017-04-07T14:54:28.546797Z

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

levitanong 2017-04-07T15:19:38.124593Z

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

levitanong 2017-04-07T15:19:52.129775Z

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

benbot 2017-04-07T15:20:32.145180Z

@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

benbot 2017-04-07T15:21:05.157382Z

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

levitanong 2017-04-07T15:23:14.206125Z

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

benbot 2017-04-07T15:23:55.221487Z

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

benbot 2017-04-07T15:24:34.236200Z

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

benbot 2017-04-07T15:24:40.238411Z

idk

levitanong 2017-04-07T15:25:54.266062Z

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

benbot 2017-04-07T15:26:10.271683Z

hrm i didn’t know that

levitanong 2017-04-07T15:27:57.312047Z

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.

peeja 2017-04-07T15:52:48.860429Z

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

peeja 2017-04-07T15:53:32.876367Z

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

carter.andrewj 2017-04-07T15:54:18.893081Z

@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.andrewj 2017-04-07T15:54:33.898027Z

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

peeja 2017-04-07T15:54:45.903026Z

🙂

carter.andrewj 2017-04-07T15:57:47.969364Z

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.

peeja 2017-04-07T15:58:18.981071Z

Ah! Have I got syntax for you!

carter.andrewj 2017-04-07T15:58:19.981557Z

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

peeja 2017-04-07T15:58:31.985779Z

{:children ...}

carter.andrewj 2017-04-07T15:58:35.987127Z

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

carter.andrewj 2017-04-07T15:58:53.994092Z

actually ...?

peeja 2017-04-07T15:58:59.996031Z

Actually ...

carter.andrewj 2017-04-07T15:59:01.997033Z

Or are you pausing for effect? 🙂

peeja 2017-04-07T15:59:07.998906Z

Nope, that's it 🙂

carter.andrewj 2017-04-07T15:59:11.000312Z

Nice!

peeja 2017-04-07T15:59:11.000347Z

(Quoted, of course)

carter.andrewj 2017-04-07T16:00:01.019559Z

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

peeja 2017-04-07T16:00:47.038651Z

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

peeja 2017-04-07T16:01:13.048380Z

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

peeja 2017-04-07T16:01:34.056470Z

Those come straight from datomic's syntax

peeja 2017-04-07T16:02:17.072439Z

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.

peeja 2017-04-07T16:02:27.076497Z

So, play with it 🙂

carter.andrewj 2017-04-07T16:04:02.111350Z

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.andrewj 2017-04-07T16:05:13.136438Z

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

carter.andrewj 2017-04-07T16:05:34.143979Z

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

peeja 2017-04-07T16:23:37.513046Z

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

peeja 2017-04-07T16:24:51.537272Z

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

carter.andrewj 2017-04-07T16:26:10.562964Z

tree-db

carter.andrewj 2017-04-07T16:26:49.576405Z

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

peeja 2017-04-07T16:27:12.583715Z

Yep, that should work fine

carter.andrewj 2017-04-07T19:20:19.018947Z

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

2👍
carter.andrewj 2017-04-07T19:20:28.021867Z

Thanks again

peeja 2017-04-07T19:56:13.651135Z

@carter.andrewj Sweet! Glad to help!