Fork me on GitHub
#om
<
2017-03-31
>
hlolli08:03:25

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

danielstockton08:03:23

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.

danielstockton08:03:09

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

levitanong12:03:27

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

hlolli12:03:22

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

levitanong12:03:56

@hlolli in react native’s React Navigation.

levitanong12:03:18

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

hlolli12:03:48

did you first pass it into a factory?

levitanong12:03:53

yup, tried that too

levitanong12:03:04

i tried SomeComponent

levitanong12:03:25

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

levitanong12:03:33

passing some-component

hlolli12:03:03

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.

hlolli12:03:40

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.

levitanong12:03:36

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

hlolli12:03:53

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

hlolli12:03:36

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

levitanong12:03:28

i’m not sure about createElement

levitanong12:03:36

maybe createClass is the more appropriate method

hlolli12:03:07

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

levitanong12:03:31

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

levitanong12:03:35

it’s asking for the component

levitanong12:03:12

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

hlolli12:03:13

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.

levitanong12:03:53

currently trying createClass

levitanong12:03:10

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

levitanong12:03:19

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

rgm22:03:52

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.

rgm22:03:13

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.

rgm22:03:29

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

rgm22:03:41

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.

rgm22:03:23

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.

rgm22:03:31

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

drcode23:03:34

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

rgm23:03:44

oh, cool, thanks.

cjmurphy23:03:10

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

rgm23:03:49

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

cjmurphy23:03:05

Mutations can be called from any event.

cjmurphy23:03:39

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

rgm23:03:58

thanks, will do.

cjmurphy23:03:07

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

rgm23:03:25

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.

rgm23:03:02

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.

cjmurphy23:03:58

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

rgm23:03:01

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

rgm23:03:08

(if an ident is set)

rgm23:03:19

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.

cjmurphy23:03:22

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.

rgm23:03:13

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

rgm23:03:44

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?

cjmurphy23:03:52

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

cjmurphy23:03:27

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

rgm23:03:38

right, cool. OK. Thanks.

rgm23:03:47

A couple other things just clicked for me.

cjmurphy23:03:47

Where being this.

rgm23:03:30

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.

rgm23:03:54

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

rgm23:03:20

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

rgm23:03:09

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

rgm23:03:15

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

cjmurphy23:03:32

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.

cjmurphy23:03:04

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

rgm23:03:53

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.

cjmurphy23:03:07

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.

rgm23:03:05

gotcha ... thanks, this really helps.

cjmurphy23:03:08

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

rgm23:03:05

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.

cjmurphy23:03:53

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