This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-27
Channels
- # admin-announcements (1)
- # beginners (1)
- # boot (37)
- # cbus (1)
- # cider (44)
- # cljs-dev (16)
- # cljsjs (2)
- # cljsrn (18)
- # clojure (205)
- # clojure-belgium (6)
- # clojure-china (1)
- # clojure-india (1)
- # clojure-russia (24)
- # clojure-spec (21)
- # clojure-turkiye (1)
- # clojure-uk (72)
- # clojurescript (91)
- # core-async (4)
- # cursive (12)
- # data-science (2)
- # datascript (2)
- # datomic (12)
- # emacs (6)
- # flambo (7)
- # funcool (12)
- # hoplon (24)
- # incanter (2)
- # jobs-discuss (29)
- # keechma (2)
- # lein-figwheel (2)
- # leiningen (2)
- # mount (13)
- # nyc (2)
- # om (76)
- # om-next (1)
- # onyx (38)
- # other-languages (4)
- # planck (40)
- # re-frame (33)
- # reagent (101)
- # ring-swagger (5)
- # slack-help (1)
- # untangled (7)
- # yada (14)
can someone help me with creating “routing” system, when components dynamically get rendered in content area based on selected item in the menu?
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?
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
I’m doing something similar where I run my parser manually, but I’m struggling to get remote execution
https://gist.github.com/hkjels/ec2bfa514e9c17291d9b11ef3cf76785 Here’s the gist of it
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)"
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!
@iwankaramazow: oh cool, thanks
so I’m getting
No queries exist for component path
I can’t set-query!
in componentWillReceiveProps
?@ag: that error is not about setting query in a lifecycle method
it’s exactly what it says, there are no queries along the path of the components it lists
i.e. queries don’t correctly compose
happy to help you figure out what’s wrong if you post the defui
declarations of the components involved with just their IQuery
implementations
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
right but that is an entirely different problem
which is not related to the error you’re getting when setting the query
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]} }]}]
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
there’s e.g. process-roots
or you can roll your own
probably better to manipulate the query in the send
method
@urbanslug: get-state
doesn’t return a cursor
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.
maybe not -> “You should only implement this if you really know what you're doing. Even then you probably shouldn't."
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)))))
When the recursive query isn't under a fake root, it throws #object[Error Error: ... is not ISeqable]
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
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.
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?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
?
@ag: in your send function, flatten
the query like this: (into [] (flatten (:remote remotes)))
(or just send the first
element of (:remote remotes)
the “why" is here: https://github.com/omcljs/om/blob/master/src/main/om/next/impl/parser.cljc#L262-L263
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)))
right, so s/remotes/m
@ag: it seems you’re sending the whole remotes map to the server
I meant you need to get at the first element of the query that is probably under the key :remote
sounds unlikely
if you changed it and it’s behaving the same
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