Fork me on GitHub
#om
<
2016-05-27
>
ag08:05:29

can someone help me with creating “routing” system, when components dynamically get rendered in content area based on selected item in the menu?

ag08:05:22

I have App component (root), I have Content component, that would be dynamically rendering other components. So I do have to have a join query for the Content in the App’s IQuery?

ag08:05:25

let’s say I have something like this:

[ {:app/current-route [:app/current-route}
  {:app/current-data (om/subquery this subq-ref subq-class)}]
and :app/current-data will be dynamically changing based on current-route

ag08:05:30

now I have to have read method that dispatches on :app/current-data?

ag08:05:44

I think I’m totally lost here

hkjels08:05:40

I’m doing something similar where I run my parser manually, but I’m struggling to get remote execution

urbanslug08:05:57

Using Om now can’t I call transact on a cursor I get from get-state? I get the error “Uncaught Error: Assert failed: (transactable? cursor)"

ag08:05:48

@hkjels: {:remote true} I’m not sure about this? shouldn’t you be sending ast to remote?

hkjels08:05:59

I believe {:remote true} is short for sending the AST without modifications

hkjels08:05:13

Each individual component works if I mount them as root, so the problem only occurs when I move the query onto the root-component using set-query!

ag09:05:31

@iwankaramazow: oh cool, thanks

urbanslug09:05:32

How can I make component local state change percolate upwards?

ag10:05:09

so I’m getting

No queries exist for component path
I can’t set-query! in componentWillReceiveProps?

anmonteiro11:05:42

@ag: that error is not about setting query in a lifecycle method

anmonteiro11:05:00

it’s exactly what it says, there are no queries along the path of the components it lists

anmonteiro11:05:19

i.e. queries don’t correctly compose

anmonteiro11:05:57

happy to help you figure out what’s wrong if you post the defui declarations of the components involved with just their IQuery implementations

ag11:05:57

I’m struggling to dynamically bind a component to another component 😞

ag11:05:16

I think it something with queries and stuff

ag11:05:33

so I have a component that when added to the root works fine

ag11:05:53

now I need dynamically render different components in a another container component

ag11:05:39

using set-query! it sets the query, but I’m struggling to send right AST to the server

ag11:05:23

damn it, I can even explain it right

ag11:05:41

so I have a tree of components let’s call them MyTree (when added to the root MyTree works just fine), now instead of that, I need to dynamically render different components (including MyTree), but now in whatever my root component would be (let’s call it App) I need to join a query, {:app/current-data [:app/current-data]} which would be empty at first, but then at some point in Content (which is child of App and container for other components, including MyTree) I set-query! and then it would trigger dispatch of read :app/current-data, there I need to grab part of the query of MyTree (of which the query itself is composed) and send it ast of that query the server. But AST somehow is different (compared to what it is when MyTree is directly added to root) and so fetching data fails

anmonteiro11:05:24

right but that is an entirely different problem

anmonteiro11:05:34

which is not related to the error you’re getting when setting the query

ag11:05:58

yeah, I got that…

ag12:05:42

so my query in read dispatch now looks like something like this:

[{:app/current-data [{:my-tree/resources [:id :description :account-type :account-item-data]} {:my-tree/requirements [:id :description :account-type :account-item-data]} }]}]

ag12:05:52

I need to cut off :app/current-data of that (since I’m interested in :my-tree stuff only) make query->ast and send it to the server

ag12:05:39

or do somehow trigger read methods of :my-tree/resources and :my-tree/requirements

anmonteiro12:05:07

there’s e.g. process-roots

anmonteiro12:05:17

or you can roll your own

anmonteiro12:05:42

probably better to manipulate the query in the send method

ag12:05:43

hold on… I think I got somewhere here

ag12:05:26

nah, it didn’t work

ag12:05:59

every time when I feel I grasped something, next minute I feel completely lost

dnolen13:05:16

@urbanslug: get-state doesn’t return a cursor

urbanslug13:05:50

Yeah, it returns component local state.

urbanslug13:05:28

I have this issue where I change component local state for a “pop up/modal” but when closed and reopened it goes back to its old state.

urbanslug13:05:10

I’m thinking of fixing it in something like IShouldUpdate

urbanslug13:05:30

or similar functions, gotta read the docs more.

urbanslug13:05:03

maybe not -> “You should only implement this if you really know what you're doing. Even then you probably shouldn't."

dnolen13:05:11

you should be familiar with life cycle method yes

dnolen13:05:30

IShouldUpdate is an exception because you have to be careful

dnolen13:05:44

that is you need to replicate everything the default implementation does

urbanslug13:05:50

Yeah I got that from the wiki.

urbanslug13:05:07

Just the stern warning 🙂

urbanslug13:05:28

—> “IWillReceiveProps"

cmcfarlen13:05:56

I wrote this test that demonstrates my issue with process-roots.

(deftest test-process-roots-recursive-non-query-root
  (let [p (om/parser {:read precise-read})
        m (om/process-roots
            (p {:state (atom {})}
              '[{:fake/key [{:real/key ...}]} {:other/key [:other/key {:other/key ...}]}] :remote))]
    (is (= [{:real/key '...} {:other/key [:other/key {:other/key '...}]}] (:query m)))))

cmcfarlen13:05:31

When the recursive query isn't under a fake root, it throws #object[Error Error: ... is not ISeqable]

ag20:05:08

is it always expected that given query round-tripping to om/query->ast->`om/ast->query` would return the initial query? I think I’m seeing somewhat different

danburton20:05:00

I would assume that to be true. Or at least, I would assume that two round trips will give you the same result as one round trip.

ag22:05:38

I have a query that looks like this:

{:app/current-data (om/subquery this sub-ref sub-class)}
now this query is dynamic (it depends on a child component), so in read :app/current-data I’d like to trim the query down and send only child component relevant AST, since I already have dispatchers for :ledger/resources and :ledger/requirements on the server. That subquery is itself a join query that looks like this:
[{:ledger/resources [:id :description :account-type :account-item-data]}
            {:ledger/requirements [:id :description :account-type :account-item-data]}]
So I initially thought that I could just do (-> ast :query om/query->ast) but it’s not working right. Can anyone help me?

ag22:05:20

when I send it, on the server it wants me to have a dispatch for [:ledger/resources [:id :description :account-type :account-item-data], why it’s not triggering read :ledger/resources?

anmonteiro22:05:19

@ag: in your send function, flatten the query like this: (into [] (flatten (:remote remotes)))

anmonteiro22:05:51

(or just send the first element of (:remote remotes)

ag22:05:20

this is my send, I’ve copied it from Malcolm Sparks’s tutorial:

(defn send [m cb]
  (let [xhr          (new js/XMLHttpRequest)
        request-body (transit/write (transit/writer :json) m)]
    (.open xhr "POST" "/ledger-data")
    (.setRequestHeader xhr "Content-Type" "application/transit+json")
    (.setRequestHeader xhr "Accept" "application/transit+json")
    (.addEventListener
      xhr "load"
      (fn [evt]
        (let [response (transit/read (transit/reader :json)
                         (.. evt -currentTarget -responseText))]
          (cb response))))
    (.send xhr request-body)))

anmonteiro22:05:29

right, so s/remotes/m

ag22:05:02

eh.. didn’t get it

anmonteiro22:05:20

@ag: it seems you’re sending the whole remotes map to the server

anmonteiro22:05:54

I meant you need to get at the first element of the query that is probably under the key :remote

ag22:05:05

oh yeah… ok

ag22:05:22

but then it’s not returning anything :[

ag22:05:59

it’s still trying to dispatch on the whole thing

ag22:05:18

{:ledger/requirements [:id :description :account-type :account-item-data]}

ag22:05:48

I don’t have dispatch for that, I have for :ledger/requirements

anmonteiro22:05:33

sounds unlikely

anmonteiro22:05:51

if you changed it and it’s behaving the same

ag22:05:16

this is how m looks like {:remote [{:ledger/resources [:id :description :account-type :account-item-data]} {:ledger/requirements [:id :description :account-type :account-item-data]}]} and it works perfectly when I have the component as a root

ag22:05:47

but if I try to make it a child of another component it stops

ag23:05:25

is it possible that query->ast doesn’t work correctly for join queries? such as

[{:ledger/resources [:id :description :account-type :account-item-data]}
            {:ledger/requiremenkts [:id :description :account-type :account-item-data]}]

ag23:05:36

or am I missing something?