om

Please ask the channel first, not @dnolen directly!
2017-03-31T08:22:27.537743Z

@baptiste-from-paris I usually use Compojure server side (https://github.com/weavejester/compojure) and Secretary client side (https://github.com/gf3/secretary)

👍 2
2017-03-31T08:31:25.658566Z

for all non-statics using one endpoint(/api) and putting everything in server-side om/parser works very smooth with the front end parser.

2017-03-31T08:51:23.937434Z

How do people merge novelty back into app state after remote mutations? The query that merge receives is the transact! query, which isn't particularly helpful for merging the response back into the db.

2017-03-31T08:52:09.947986Z

Say I have a :card/by-id table and I receive {:name "Card1", :id 1234} from the server after editing the name.

baptiste-from-paris 2017-03-31T11:22:14.867979Z

thanks @symfrog

levitanong 2017-03-31T12:01:27.309616Z

hi, does anyone know of a way to convert om.next components to react components?

2017-03-31T12:05:22.356788Z

@levitanong I used om components recently straight into re-agent. Where are you looking to render the component?

levitanong 2017-03-31T12:08:56.400246Z

@hlolli in react native’s React Navigation.

levitanong 2017-03-31T12:09:18.404685Z

I’ve tried using om components straight, but it complains that it must be a React Component.

2017-03-31T12:09:48.411041Z

did you first pass it into a factory?

levitanong 2017-03-31T12:09:53.412043Z

yup, tried that too

levitanong 2017-03-31T12:09:56.412617Z

so

levitanong 2017-03-31T12:10:04.414322Z

i tried SomeComponent

levitanong 2017-03-31T12:10:25.418649Z

I tried (def some-component (om/factory SomeComponent))

levitanong 2017-03-31T12:10:33.420496Z

passing some-component

2017-03-31T12:13:03.450410Z

I mean, if you can mount it into the dom with reactDOM.render, then it should be a valid react element. But I've never done react-native so not sure if there's some specialities there.

2017-03-31T12:16:40.495640Z

But I think I see where your question is coming from, we are used to mounting om apps with a reference to the reconciler, so its maybe not a valid react-element that's returned there.

levitanong 2017-03-31T12:17:15.502408Z

¯\(ツ)

levitanong 2017-03-31T12:17:36.506827Z

out of desperation i’m doing weird things like set! ing the React Component fields

levitanong 2017-03-31T12:18:14.515089Z

lol

2017-03-31T12:21:53.561669Z

try js/React.createElement and pass om element as the third parameter, sounds stupid and probably is.

2017-03-31T12:23:36.583249Z

(def your-element (js/React.createElement "div" #js {} your-om-element))

levitanong 2017-03-31T12:25:23.606951Z

hmm

levitanong 2017-03-31T12:25:28.608035Z

i’m not sure about createElement

levitanong 2017-03-31T12:25:36.610002Z

maybe createClass is the more appropriate method

2017-03-31T12:27:07.630172Z

then you need to create an instance of that class with an element (trough factory?), so you're back to sqare1 ?

levitanong 2017-03-31T12:27:31.635360Z

but the thing is ReactNavigation isn’t asking for an instance

levitanong 2017-03-31T12:27:35.636422Z

it’s asking for the component

levitanong 2017-03-31T12:28:12.644419Z

or am i misunderstanding and component is the same as an element?

2017-03-31T12:29:12.657792Z

good question https://tylermcginnis.com/react-elements-vs-react-components/ (reading myself)

2017-03-31T12:33:13.713116Z

bad link, here it's stated crystal clear http://stackoverflow.com/questions/30971395/difference-between-react-component-and-react-element react component is a class that can hold state.

levitanong 2017-03-31T12:33:53.722756Z

currently trying createClass

levitanong 2017-03-31T12:36:10.753493Z

i realize it makes no sense to call an om.next component from inside the render function of a react component

levitanong 2017-03-31T12:44:19.868356Z

@hlolli thanks for the help, I will take a nap first. 😜

rgm 2017-03-31T22:42:52.179145Z

can anyone help me out by pointing me to good sample code / explanations for what the :value returned from a mutation parse actually does? Having a lot of trouble grokking it.

rgm 2017-03-31T22:44:13.191593Z

I'm sorta fuzzily thinking it's a hint that components can pick up to know about state invalidation but I think I'm just guessing.

rgm 2017-03-31T22:52:29.266614Z

also, I noticed that the om-next-kanban demo funnels all mutations through the root component: https://github.com/Jannis/om-next-kanban-demo/blob/master/src/kanban/app.cljs#L28-L66

rgm 2017-03-31T22:54:41.285868Z

children get what if I squint look like a form of partially-applied versions of these so the transact! call always happens with the some-component arg set to the root component.

rgm 2017-03-31T22:56:23.300761Z

do transact calls always have to go through the root component? Or is there some other mechanism that lets mutations get called from wherever deeper in the tree. I experimented with that and very quickly found my UI state responding in unexpected ways.

rgm 2017-03-31T22:59:31.327784Z

(apologies in advance if these questions are so newb as to not even be wrong).

drcode 2017-03-31T23:04:34.372242Z

Hi, I've been out of the loop for a couple weeks on the #om slack- Did I miss anything important? 🙂

rgm 2017-03-31T23:12:44.438424Z

oh, cool, thanks.

cjmurphy 2017-03-31T23:13:10.441700Z

:value is not used at all - just documents what gets changed - for humans. You don't need to both with :value.

rgm 2017-03-31T23:13:49.447027Z

ha, guess that'd explain why it didn't fix a problem I was having with a rerender

cjmurphy 2017-03-31T23:14:05.449178Z

Mutations can be called from any event.

cjmurphy 2017-03-31T23:14:39.453886Z

Look up 'follow on reads' for when re-rendering doesn't happen.

rgm 2017-03-31T23:14:58.456337Z

thanks, will do.

cjmurphy 2017-03-31T23:16:07.465669Z

Jannis's code is great, but lots of effort went to taking everything back to root - that was not really necessary.

rgm 2017-03-31T23:17:25.476133Z

OK. It was striking me as some sort of Cocoa responder-chain-esque messaging could be OK. Modulo the usual action-at-a-distance concerns.

rgm 2017-03-31T23:18:02.481025Z

ie. just chuck a mutation message at the reconciler from someplace on the page. Usually not that hard to find where it came from later.

cjmurphy 2017-03-31T23:18:58.488256Z

All mutations will probably be in same namespace. All called through transact!.

rgm 2017-03-31T23:20:01.496641Z

I see the transact! console messages tell me the component ident too.

rgm 2017-03-31T23:20:08.497648Z

(if an ident is set)

rgm 2017-03-31T23:23:27.522248Z

oh, there we go... http://stackoverflow.com/a/39413526/53790 (hi @cjmurphy)

rgm 2017-03-31T23:25:19.536245Z

both q's answered in one: {:value ... } in a mutate is for the humans, the this in (om/transact! this ...) determines where rerenders cascade down from.

cjmurphy 2017-03-31T23:31:22.580644Z

And another thing to think is that your de-normalised tree (your UI) can be whatever shape you want it to be - that can help as well - you can repeat what is the same normalised entity around your tree as much as you like. So there's plenty of flexibility.

rgm 2017-03-31T23:35:13.608214Z

right, yes... just starting to understand that.

rgm 2017-03-31T23:37:44.626160Z

OK, so if I understand right, if I ship off an (om.next/transact! a-subcomponent [(mutate-thing {:a param}) :other-thing-that-is-affected]) from the :action then any subcomponent with :other-thing-that-is-affected in its query will rerender, regardless of location in the UI tree?

cjmurphy 2017-03-31T23:40:52.648324Z

Yes - that looks like a follow on read to me. The only purpose for them being that the key is in an unrelated branch.

cjmurphy 2017-03-31T23:41:27.652428Z

If the key were below where you are calling the mutate from it wouldn't be needed.

rgm 2017-03-31T23:41:38.653624Z

right, cool. OK. Thanks.

rgm 2017-03-31T23:41:47.654552Z

A couple other things just clicked for me.

cjmurphy 2017-03-31T23:41:47.654569Z

Where being this.

rgm 2017-03-31T23:42:30.659412Z

right... so if this is the root and you have a shallow hierarchy, might as well just transact from root that b/c React is gonna no-op most of it out anyway.

rgm 2017-03-31T23:42:54.662129Z

(and presuming you're not triggering a bunch of remote work as part of the mutate).

rgm 2017-03-31T23:43:20.665033Z

wait, no, guess that doesn't really matter.

rgm 2017-03-31T23:44:09.670609Z

obv if a mutation needs remote work then it needs it; nothing to do with the UI hierarchy.

rgm 2017-03-31T23:44:15.671302Z

(ok now I'm just making stuff up).

cjmurphy 2017-03-31T23:44:32.673408Z

Yes. this doesn't have to be the component you are in - doesn't have to actually be this - you could have kept a reference to a component, or even have looked up a component by other means.

cjmurphy 2017-03-31T23:45:04.677001Z

But almost always you don't have to resort to such tricks.

rgm 2017-03-31T23:46:53.689278Z

so for a reasonably shallow hierarchy and learning purposes it seems reasonable to just pass the root down in props and transact against it from leaf components.

cjmurphy 2017-03-31T23:49:07.704235Z

Yes you could do that if your leaf components were changing their parent components, but normally good to have the code in the parent changing the children so they need to be re-rendered. Jannis just took that to the extreme.

rgm 2017-03-31T23:50:05.711001Z

gotcha ... thanks, this really helps.

cjmurphy 2017-03-31T23:50:08.711263Z

So if a child is being deleted, do the transact in the immediate parent, using this.

rgm 2017-03-31T23:54:05.737209Z

so then the computed callback isn't having to zipper its way all the way back up to the root, and if say something somewhere else in the UI tree was displaying a count of children that's maybe a candidate for a follow-on read.

cjmurphy 2017-03-31T23:59:53.774226Z

Certainly sounds like it to me - I'd guess there's an example of exactly that out there somewhere...