om

Please ask the channel first, not @dnolen directly!
sova-soars-the-sora 2017-04-04T00:22:20.044396Z

So in that example query the :comment/reply would also have all the same attributes as a :comment/by-id ?

wilkerlucio 2017-04-04T02:08:51.858343Z

@sova yes, correct

wilkerlucio 2017-04-04T02:09:29.862798Z

also, if your parser is being called, the query will be just that, the same attributes, it kind makes the implementation go automatically for it

thosmos 2017-04-04T05:28:29.781439Z

@wilkerlucio Wow! Great article!

2017-04-04T10:14:13.041672Z

I'm at a loss how to re-run a query after a remote mutation. I had the idea for my backend to return {:reads! [:some/read]} and I would detect this special :reads! key in my merge function and call (transact! reconciler reads) but it doesn't really work because it's actually a specific join query I want to re-run, not the bare key. I don't really understand how to integrate novelty into the state after a remote mutation, it seems the query passed to merge is useless for this.

wilkerlucio 2017-04-04T12:04:38.352897Z

thank you @thosmos ๐Ÿ™‚

wilkerlucio 2017-04-04T12:06:02.370994Z

@danielstockton it's part of Om.next design for the UI (the transaction caller) to be responsible about doing that, can feel weird at first, but try it, usually it's not that much to keep that responsability there

2017-04-04T12:07:16.386537Z

Trouble is, I'm not sure how. Merge seems to be the only place where I can do something after a remote response.

2017-04-04T12:07:31.390090Z

If I pass reads to the transaction caller, they'll happen too early.

2017-04-04T12:07:34.390823Z

Won't they?

2017-04-05T07:21:27.436081Z

I tried it, they get fired immediately (which means if it's a remote call, it is sent in the same request as the mutation itself).

2017-04-05T07:22:38.448663Z

Not sure about the indexer indexing transacts but the indexer will update components that have queries reading keys that are merged in, or keys returned by :keys from merge.

2017-04-04T12:07:53.394943Z

It doesn't wait for the remote call, it will fire the reads immediately.

wilkerlucio 2017-04-04T12:07:56.395549Z

hum, you are using Om.next pure? or with some framework on top of it?

2017-04-04T12:08:16.399891Z

Om.next pure on the client side, custom parser (python django) on the back.

wilkerlucio 2017-04-04T12:08:36.404192Z

got it, so, on this case I don't know much =/

wilkerlucio 2017-04-04T12:08:39.404838Z

if you use Untangled it actually waits for it, and otherwise there is the after-mutation things you can do

2017-04-04T12:09:02.409733Z

Yeah, I wonder how that mechanism works.

wilkerlucio 2017-04-04T12:09:06.410573Z

but Untangled does a different process, using 2 reconcilers for it

wilkerlucio 2017-04-04T12:10:06.423896Z

it triggers remotes on a secondary reconciler, that's more managed and controlled, this contrasts with Om.next pure approach that asks for remote whenever it tries to fetch something not present on local state

wilkerlucio 2017-04-04T12:10:21.427306Z

in Untangled this is explicit instead of implicit

wilkerlucio 2017-04-04T12:10:39.431463Z

but they are just different approaches, I'm sure it must be a way to handle this on Om.next pure too

2017-04-04T12:12:54.461377Z

I was thinking to pass the query/component as parameters to the mutation, just to have them available in merge.

2017-04-04T12:13:40.471686Z

That way, the transactor could control what is re-read rather than the server and I can pass through the complete query rather than just a key.

wilkerlucio 2017-04-04T12:16:47.515018Z

try it, and please let us know if it worked ๐Ÿ˜‰

2017-04-04T12:21:28.579477Z

Did you learn about the 2 reconcilers untangled uses from reading the source or is this documented?

petterik 2017-04-04T12:22:28.593500Z

I used to pass a "mutation-uuid" parameter with each mutation, so I could identify it later.

petterik 2017-04-04T12:25:43.640671Z

But it got tedious to sprinkle the uuid with every mutation. Now instead I've wrapped my mutate with a function that takes the uuid generated with om/transact! and puts it in my mutation's parameters (by modifying the ast).

petterik 2017-04-04T12:26:02.645379Z

I can parse the mutation's uuid in send and pass it to merge

2017-04-04T12:28:50.685968Z

This sounds similar to what I had in mind:

(om/transact this `[(some/mutation {:param1 "a parameter" :reads! [{:some/read ~(om/get-query SubComponent)}])
and then read the query/ast in merge.

petterik 2017-04-04T12:40:55.868061Z

Maybe I missed it, but what's the problem with passing the reads after the mutation?, i.e:

(om/transact this `[(some/mutation {:param1 "a parameter"}) {:some/read ~(om/get-query SubComponent)}]
Is it because :some/read is not a remote read, and the return value of the remote mutation changes the outcome of a local :some/read?

petterik 2017-04-04T12:42:12.888402Z

I've structured my reads/mutations such that I don't rely on what's returned by mutations. Just sending [(some/mutation {})] wouldn't do anything to my app-state

petterik 2017-04-04T12:43:16.904994Z

The benefit of this is that I always send my reads, which I can return from merge and om.next will update the components that care

petterik 2017-04-04T13:03:13.248068Z

But yeah, if you want to do something after a mutation in merge, passing it as parameters seems like it would work

2017-04-04T13:06:10.302045Z

"Is it because :some/read is not a remote read, and the return value of the remote mutation changes the outcome of a local :some/read?" - It's because it changes the outcome of a remote read so i want to re-read that after the remote mutation.

2017-04-04T13:09:49.368870Z

Specifically, I'm adding a new item to a list (on the server) and my UI needs to re-read the list. It's not possible to optimistically update the list on the client side, I need things only the server can provide.

wilkerlucio 2017-04-04T13:19:02.544158Z

I hear Tony Kay talking about it somewhere

๐Ÿ‘ 1
petterik 2017-04-04T13:21:51.599194Z

Ok, then I'm confused. Wouldn't specifying the read after the mutation execute the read just like your saying? In my mind it would read 3 times: optimistic client-side -> after mutation server-side -> post remote mutation client-side (triggered by merge returning {:keys [:some/read] ...})

denik 2017-04-04T13:23:32.633035Z

@peeja found your figwheel reload gist for reloading components without remounting the root component. https://gist.github.com/Peeja/eccd5e8169709c12ec0420c86beb49b9 we actually do want to update local state. Do you know a way to do that?

2017-04-04T13:29:31.756266Z

@petterik If I specify the read as a trailing arg to transact, it actually gets sent in the same request as the mutation. Interestingly, this seems to work, but I'm not sure if I can rely on that behaviour. It depends which is parsed first.

2017-04-04T13:31:52.805589Z

Sending the reads as params on the mutation also worked (FYI) when I transacted them in merge.

2017-04-04T13:32:25.817190Z

I think I can rely on the order actually, it's a vector after all.

๐Ÿ‘ 1
2017-04-04T13:34:34.862120Z

It's optimistic client-side -> after mutation server-side... guess i'm missing something for post remote mutation client-side, or that isn't the case.

2017-04-04T13:34:55.869683Z

My merge function is a thin wrapper over default-merge, I just pull out some error keys and have special behaviour when a user is returned (login/logout).

petterik 2017-04-04T14:48:59.602321Z

@danielstockton Does your merge function return :keys to re-read? The keys returned from merge is queued: https://github.com/omcljs/om/blob/master/src/main/om/next.cljc#L2330-L2332

2017-04-04T14:49:38.618042Z

Yeah, I checked the source. It looks like default-merge takes the keys from the response, so no, I'm not in the case of mutations.

petterik 2017-04-04T14:49:50.623074Z

ok

2017-04-04T14:50:05.628891Z

I actually think it's fine with just optimistic client-side and after mutation server-side, don't think I need the after mutation client-side.

peeja 2017-04-04T15:41:20.909605Z

@denik I'm not sure I follow. What do you want to do?

denik 2017-04-04T16:22:36.889338Z

@peeja figure out whether a componentโ€™s local state has changed and remount it

peeja 2017-04-04T16:23:00.898230Z

What would change the local state?

peeja 2017-04-04T16:24:18.926981Z

If you change the local state of a component, the component should re-render with the new state automatically. It knows to do that because it's managing its own state, and you just told it to change that state.

peeja 2017-04-04T16:24:36.933792Z

If that's not what you're seeing, there may be a deeper issue

peeja 2017-04-04T16:35:12.166610Z

Question: It looks to me like the indexer indexes component classes by keys (`:prop->classes`) and component instances by ref (`:ref->components`). If a component instance changes its query to use different keys, does the indexer not pay attention? If a merge changes one of the keys in that new query, will the component instance be re-rendered or not?

thosmos 2017-04-04T19:14:10.648654Z

have you actually tried it? It's been a while since I did this, but my memory is that by adding the read key to the transact!, it adds that key to the indexer, so when that key later gets merged, it updates all components that have transact!s with reads on that key ... I might be wrong, so you should test it