Fork me on GitHub
#om
<
2016-05-02
>
abtv13:05:52

I cant' find out how to have 2 components which show the same data, but have different operations. I have a counter and 2 components. InnerView component shows a value of the counter and can increment the value. SmallView component shows the same value of the counter and can decrement_ the value. What is the idiomatic approach to implement it? I have the following, but it fails to update one of components when I call transact!.

abtv13:05:04

Can I create things like this?: (query [this] [{:settings (om/get-query InnerView)} {:settings (om/get-query SmallView)}])

mitchelkuijpers13:05:25

@abtv: I would also like to know that I am doing something like this:

`[({:forms/current ~(om/get-query ColumnSelection)} {:form/type :form.type/company})
  ({:forms/current ~(om/get-query FilterBar)} {:form/type :form.type/company})]
But it seems like the last one always wins

abtv13:05:27

@mitchelkuijpers: why do we need lists there inside a query vector?

mitchelkuijpers13:05:59

@abtv: to give the query the parameter :form/type

mitchelkuijpers13:05:26

@abtv: the same thing you do with mutations

abtv13:05:53

is this a query vector or mutation?

anmonteiro13:05:03

@mitchelkuijpers: join queries are hydrated by the parser into maps

anmonteiro13:05:08

and you can’t have repeated keys in a map

mitchelkuijpers13:05:21

Aha that makes sense

anmonteiro13:05:29

so you shouldn’t have repeated keys in a query

anmonteiro13:05:42

I’m pretty sure you would never write a query like this: [:foo :foo]

abtv13:05:53

can I just conjoin 2 subqueries? @anmonteiro

anmonteiro13:05:25

@abtv: I’m not sure I understand, but I’m going to cautiously say “no"

abtv13:05:53

@anmonteiro: could you say how to implement what I'm trying to do (the code above)?

anmonteiro13:05:35

ah, I hadn’t looked

anmonteiro13:05:28

@abtv: seems like the simplest case would be to have 1 component

anmonteiro13:05:45

with a query like [:value :label: ]

mitchelkuijpers13:05:03

For me that isn’t really an option.. but maybe I am going wrong about this

anmonteiro13:05:05

you could also pass the label as a computed prop

abtv13:05:19

no, I'm trying to understand how to implement it with 2 components. I have a problem and trying to solve it with the simple example @anmonteiro

anmonteiro13:05:02

maybe your example doesn’t clearly illustrate the real problem you’re having

anmonteiro13:05:10

I’d definitely pass the transaction as a computed prop

anmonteiro13:05:15

and have only 1 component in that case

anmonteiro13:05:24

which could be reused for the 2 operations

abtv13:05:28

I see. Do you know some useful and simple examples of Om.Next (not untangled)?

anmonteiro13:05:00

not from the top of my head

anmonteiro13:05:04

there are some links in the om wiki

abtv13:05:17

I saw them simple_smile looks pretty complex

anmonteiro13:05:22

people find the om-tutorial pretty useful too

abtv13:05:52

>I’d definitely pass the transaction as a computed prop Like this one: https://github.com/Jannis/om-next-kanban-demo/blob/master/src/kanban/app.cljs ? @anmonteiro

abtv13:05:06

is it an idiomatic approach? ^

anmonteiro13:05:39

@abtv: I’ve actually got a simple example of what I meant

anmonteiro13:05:44

something like this

anmonteiro13:05:56

is how I’ve solved the problem of a counter that increments and decrements

anmonteiro13:05:16

it’s a different context, though

anmonteiro13:05:24

and only meant to be looked as an example

abtv13:05:17

I see, great thanks simple_smile @anmonteiro

mitchelkuijpers13:05:24

Thank you btw @anmonteiro i fixed it with some computed props now. This actually feels cleaner.

abtv14:05:43

While it works with computed props I still can't understand why do I need to call transact! on parent, not child? If I call it on a child component I receive the error: #error {:message "No queries exist for component path (om-next-starter-kit.core/OuterView om-next-starter-kit.core/InnerView)", :data {:type :om.next/no-queries}}

abtv14:05:01

And another question: if I have settings page with 2 components how to combine queries from each component to make a join on settings? It feels like I need something like {:settings (something-here (om/get-query Component1) (om/get-query Component2))}. Right now I just pass [:settings] , but this is equivalent to [{:settings [*]}] , right? Or Om.Next can do detect it automatically?

abtv17:05:21

Eventually I settled down on this: (query [this] `[{:settings ~(reduce conj (om/get-query InnerView) (om/get-query SmallView))}])

abtv17:05:05

but it's possible to have duplicates with this approach

seberius23:05:47

I have a question regarding links from the Thinking With Links! tutorial on the wiki. Should I expect a change on :current-user to trigger a render of the above component?