Fork me on GitHub
#om
<
2016-02-22
>
jlongster01:02:36

I'm using a link in a query, like [:foo :bar [:link-item _]], and if I transact! on that component the link-item is nil from props. Anyone else seen that?

tawus02:02:47

I am using https://github.com/anmonteiro/aemette as a lein template. My read calls for queries in the sub-components don’t invoke send when I return {:remote true}. What am I missing here ?

drcode03:02:38

@tawus: Are you saying :some/key is a child of :dom-com/props? I can't tell from your snippet. If that is the case, :dom-com/props will need to set the :remote to a value somehow, as well, in order for the child's value to be sent to the remote.

tawus03:02:08

@drcode: Yes, that is the case. Hmm...

drcode03:02:34

@tawus: You need to do something like this:

(defmethod read :dom-com/props
           [{:keys [parser query target ast] :as env} _ _]
           (if target
               {:target (assoc ast :query (parser env query target))}
               {:value (parser env query)}))

tawus03:02:55

Still doesn’t work but if I return {:remote true} it does invoke send.

taylor.sando03:02:48

You have to add :query-root true to the ast if that is a subquery, or not a top level key

tawus03:02:24

@taylor.sando: Do I have to that while returning from the :dom-com/props (query) or :some/key (sub-query). I tried the latter but it didn’t work

tawus03:02:48

{:remote (assoc ast :query-root true)} This is what my subquery is returning.

taylor.sando03:02:12

Which one do you want sent to the server?

tawus03:02:35

the subquery

taylor.sando03:02:42

The :dom-com/props that drcode suggested would be fine, you need to make sure some/key has a :target (assoc ast :query-root true)

tawus03:02:18

Thanks, @drcode & @taylor.sando. It was a typo on my end.

tawus03:02:24

It is working now.

drcode03:02:07

@taylor.sando: Any good documentation anywhere on the meaning of :query-root?

taylor.sando03:02:35

Not really beyond looking at code examples from different projects and reading the source code. I doubt the documentation will get better until the Beta is released.

tawus03:02:03

I was using :query-root but I was missing the condition based on target. I think reading all the messages in this group is the only way forward for now simple_smile

jannis12:02:39

The Om Next query language definition refers to EdnVector, EdnValue etc. Is there a definition of what an EdnValue is anywhere?

anmonteiro12:02:49

@jannis: not sure there is, but I'd say a value is: number, string, nil, keyword, boolean or symbol

anmonteiro12:02:03

hope I'm not forgetting anything

jannis12:02:51

@anmonteiro: Yeah, the EDN spec itself is "casual", leaving this up to interpretation

jannis12:02:11

I guess a vector of values may again be a value by itself

jannis12:02:18

Same for other "composed" values

anmonteiro12:02:39

@jannis: You might be right, yes

anmonteiro12:02:07

since you can have, say vectors, as the key of a map

addywaddy14:02:54

Hi! I posted this on #C03S1L9DN and was pointed here - didn’t realise #C06DT2YSY had it’s own channel.

addywaddy14:02:57

I’m trying to get my head around normalization and thought I was making progress, but I’ve stumbled again and am not sure if I’m just not thinking correctly about the problem. How do I normalize the current user’s messages? See this gist for the details: https://gist.github.com/addywaddy/2b2ecf4ca389afb0d202

petterik14:02:12

Is there anyone who's doing optimistic updates with om.next, datascript and datomic? Here's my imperfect approach and questions: https://gist.github.com/petterik/50779d8cf15d6b6443e4 Let me know, or comment on the gist, if you have answers, feedback or questions

marianoguerra15:02:16

@petterik: I am, using tempids, but not reverting in case of an error, not sure how that part is handled

marianoguerra15:02:48

@petterik: I think what I could do is in the send function if the result is an error and the request contains tempids then I can call some function that will remove that tempid from the tree? not sure if there's a best practice for that or a standard way

petterik15:02:30

How are you using tempids though? I might be missing something basic here

petterik15:02:22

Beautiful, thanks marianoguerra

danielstockton15:02:15

i think managing tempids is different when using datascript...you can't update an id, unless it's another attribute

petterik15:02:39

But yeah, not sure how you'd revert errors using this trategy

danielstockton15:02:45

@petterik my approach is to remove the optimistically added thing and transact a new one

danielstockton15:02:58

(if successfully received from server)

petterik15:02:19

So that's what I'm trying to do too

petterik15:02:37

how do you identify all the added datoms/entities when you're removing them?

danielstockton15:02:57

i send the tempid from the client side and have the server return it in :tempids so i can identify it

danielstockton15:02:35

the only difference is that my merge function doesnt 'update' the tempids but removes and re-adds them

danielstockton15:02:23

tbh i think we're pretty much on our own, don't expect too much help when choosing datascript at this stage

danielstockton15:02:27

lots of things im not sure about

petterik15:02:32

And by "send the tempid from the client side" you mean you've put a temp id in your call to (om/transact `[(your-mutation { <temp id here?> })]) ?

marianoguerra15:02:56

@petterik: you send it in the data, I send it in the :id field

petterik15:02:25

marianoguerra: right. I'm assigning it in the :remote ast to get sync without having to change how we do mutations, but I might consider doing what you're doing.

danielstockton15:02:44

as @marianoguerra said, im sending it in the data too on a :db/id key

danielstockton15:02:55

i just generate a new one server side and send them both back

grzm15:02:10

@marianoguerra: out of curiosity, why did you choose immutant instead of just, say, jetty?

petterik15:02:18

danielstockton: Yeah, I'm surprised by all the answers really. Thanks! It's fun being early in the game 😉

petterik15:02:46

thanks to both of you

marianoguerra15:02:03

@grzm: I'm used to immutant, I used it for 2 projects and I know how to use it 😛

grzm15:02:17

makes sense simple_smile

grzm15:02:04

I'm trying to limit the number of new things that I'm learning. I worked through the tempid stuff from tudu on Saturday and applied it to my own project. Very helpful!

marianoguerra15:02:59

@grzm: there's only one line of immutant in the example simple_smile

grzm15:02:06

Oh, I know. I just want to limit my dependencies. Hopefully fewer things to potentially go wrong. Nothing against immutant. The guys behind it seem really sharp.

marianoguerra15:02:01

@grzm: I understand, your reason is the reason I used immutant, even if it's overkill for this case simple_smile

acron16:02:43

possibly me being dumb, but is there an om/build equivalent in om next?

dnolen16:02:45

@acron: there isn’t and that’s a good thing

acron16:02:49

@dnolen: Ok, so, I think the question I meant to ask is...will any sub-UI's be notified about the reconciler associated with the parent root?

dnolen16:02:12

@acron: I do not understand your question

dnolen16:02:27

also don’t see how it’s related at all to the previous question

acron16:02:53

@dnolen: lets pretend I never said anything and I'll come back when I've de-Om-ified myself

acron17:02:01

@dnolen: This is the problem I'm trying to solve - https://gist.github.com/acron0/66659295433a93819719#file-foo-clj-L49 <- It looks like 'Sub' doesn't know about the reconciler

dnolen17:02:17

@acron: sorry don’t have time to look at that

dnolen17:02:26

as the channels says, just direct questions to the channel not me

hueyp17:02:59

the main component doesn’t reference the sub’s query

hueyp17:02:42

queries need to compose down to the root

acron17:02:59

hueyp: So parent components need to query on behalf of their subcomponents?

hueyp17:02:23

you use om/get-query Sub to compose the child query

hueyp17:02:00

and: "Common Mistakes Failing to Reach the UI Root"

acron17:02:11

hueyp: thanks for your help, will have a look!

acron17:02:17

@dnolen: my apologies! I thought it was obvious that the link was related to our earlier exchange.

jamesmintram18:02:43

OK - so another question: I have seen read methods that directly read items from the state using get-in - I have also seen db->tree - are there any rules around which to use and when? does db->tree cover the use case of doing (map get-in…. on the state? (Or is there something I have missed)

jamesmintram18:02:26

(defn get-todos [st]
  (into [] (map #(join st %)) (get st :todos/list)))

jamesmintram18:02:47

That being an example of what I am describing above. (Except, I think I have seen another demo using get-in instead of join

drcode20:02:54

Sending totally different mutation to a remote Hi everyone, I have a mutation on the client that needs to send a very different mutation to the remote- What is the canonical way to write this? I don't know how to format the AST data for the remote correctly- Just calling om/query->ast by itself causes an extra set of brakets to end up in the resulting data... Here is what I'm currently writing, which works great but is super ugly: :remote (first (:children (om/query->ast '[(foo)])))

sander20:02:56

@drcode (first (:children (om/query->ast '[(foo)])) gives {:dispatch-key 'foo, :key 'foo, :params {}, :type :call}, you could just use that directly in your mutation fn

iwankaramazow20:02:14

@drcode: there's an ast included in your env 😉

iwankaramazow20:02:07

(defmethod mutate :key [{:keys [query state ast] :as env} key _] ...)

drcode21:02:54

@sander: Good point- I'm overcomplicating it, aren't I?

drcode21:02:49

@iwankaramazow: Yes, but the remote needs a different mutation from the client AST, in my use case- I think @sander has the best idea: I should just write the raw AST.

anmonteiro21:02:24

@drcode: (om.next.impl.parser/expr->ast '(foo)) will give you what you need

drcode21:02:05

Ahh! I remember seeing that function and then forgot about it! Thanks @anmonteiro

anmonteiro21:02:00

@jannis: cool stuff, have you been using it yourself?

jannis22:02:38

@anmonteiro: I am using it. There are a few more features coming as well.

anmonteiro22:02:05

nice, I'll try it out soon

anmonteiro22:02:55

to clear up some of the confusion around current routing approaches in Om Next, I've written about a few different ways to solve the problem: https://twitter.com/anmonteiro90/status/701899774925131776

sander22:02:04

I have one component that wants to read both (:data {:from :yesterday}) and (:data {:from :today}). When I put both parametrised queries in the component's query vector, the props only contain one :data key. How should I redesign my parser/query to access both datasets from the component?

jannis22:02:32

One :data key and make :from a vector?

jannis22:02:54

Or split it up into :from and :to to define a range?

sander22:02:05

@jannis: thanks! the first makes most sense in my case

steveb8n23:02:15

@anmonteiro great write-up on routing, that will save me time. Thanks