This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-05-30
Channels
- # admin-announcements (4)
- # alda (49)
- # beginners (42)
- # boot (55)
- # cider (33)
- # cljs-dev (4)
- # cljsjs (3)
- # cljsrn (152)
- # clojure (92)
- # clojure-belgium (3)
- # clojure-brasil (18)
- # clojure-dusseldorf (32)
- # clojure-france (2)
- # clojure-greece (10)
- # clojure-japan (1)
- # clojure-mexico (1)
- # clojure-russia (50)
- # clojure-sg (1)
- # clojure-spain (1)
- # clojure-spec (12)
- # clojurescript (262)
- # core-async (2)
- # cursive (7)
- # datomic (79)
- # emacs (16)
- # euroclojure (2)
- # events (1)
- # hoplon (260)
- # jobs (2)
- # jobs-discuss (1)
- # keechma (7)
- # luminus (8)
- # mount (7)
- # off-topic (3)
- # om (101)
- # onyx (33)
- # re-frame (34)
- # reagent (10)
- # slack-help (4)
Hey guys!
Trying to learn om.
I've got a mostly empty project created by lein new figwheel om -- --om
, and I'd like to add a draggable element to it, something like this done in straight js: (https://jsfiddle.net/tovic/Xcb8d/)
I really appreciate any help in trying to understand how this works
Hey People!
I have a question… I don’t know if it’s a bug or my fault (surely it’s my fault :P)…
I have a root component which om/get-query
is: [:current-route {:some-entity/new [:id :name]}]
and then a subcomponent which om/get-query
is: [{:some-entity/new [:id :name]}]
.
Every time I’m doing a transact on the child element, this error occurs Uncaught #error {:message "No queries exist for component path (my-project.core/Root my-project.pages.create-entity/CreateEntityPage)", :data {:type :om.next/no-queries}}
(The error is triggered, but the transact is done and all the app works fine)
I looked for this error and I found some issues on github, but all are closed now, so I suppose I'm doing something wrong... Anybody has any idea?
Thanks! 🙂
@rgomezcasas: I bet you’ve stumbled upon the exact same thing that made me feel stupid just yesterday. Look into (om/process-roots)
, if you search for it in Tony Kay’s tutorial, you’ll find that. Also I suggest you to look for it in om-next's source, the docstring is helpful
Okey, I’m gonna look in!!
Thnks, @ag
Ok! 🙂
@rgomezcasas: that error has nothing to do with process-roots
it is exactly what is says, there’s no path in the queries from Root
to CreateEntityPage
most likely your queries are not correctly composed (e.g. via get-query
)
I tried to do: [:current-route {:create-page {:some-entity/new [:id :name]}}]
but doing this I do not receive the query “some-entity/new” result
So, that’s the computed and the query is [:current-route {:create-page (om/get-query CreateEntityPage)}]
`
what about the CreateEntityPage
component’s query?
The CreateEntityPage query is: [{:some-entity/new (om/get-query Entity)}]
And the Entity
query is: [:id :name :description :reward :application-id]
@rgomezcasas: 2 more questions: 1. which Om version are you using? 2. are you passing props down correctly?
The version is 1.0.0-alpha36
And maybe I’m passing incorrectly the props down
I’m passing down all the props
Inside a let in the render
part I have current-page (om/factory (current-route-page))
by all the props you mean you’re always passing (om/props this)
down?
And then I’m rendering like: (current-page (om/props this))
so that’s what’s wrong
you need to select the key in props
that corresponds to the path in the query
Ok, so I only need to pass the “current page” props?
exactly
Ok, I’m going to try!
once you do that the error should go away
Ok, so, I let the root query as [:current-route {:current-page (om/get-query CurrentPageComponent)}]
and only pass down the current-page
props?
there’s nothing wrong with your query structure
the queries are correctly composed
Ok, thnks @anmonteiro! 🙂
but as a rule of thumb, if you have a query [{:current-page (om/get-query CurrentPageComponent)}]
, you’ll want to pass (:current-page (om/props this))
down to the CurrentPageComponent
@anmonteiro: I just changed the code as you said, but now the read method it’s not executed never, so in the Root get-props I’m receiving {:current-route :create-entity, :current-page {}}
@rgomezcasas: the changes I suggested shouldn’t impact anything in the read
method
it might be a whole different bug altogether
I’m going to do some debug! 🙂
I’m trying to understand the default-migrate
function included in Om.next. Using it gives me a result that is surprising to me. My app state has looks like
{:place/by-id
{17592186045441
{:db/id 17592186045441,
:place/name “name"}…} :leaflet/map-obj #object[Object [object Object]]}
and my component that renders Places has this query [:db/id :place/name [:leaflet/map-obj _]]
using the link strategy to pull in the top level leaflet
key into each Place. But when I create a new Place and the default-migrate
function is called my app state turns into {:place/by-id
{17592186045441
{:db/id 17592186045441,
:place/name “name”,
:leaflet/map-obj #object[Object [object Object]] }…}}
so the top level object is pulled completely out of the key where it was and placed into each Place object in the app state. I know this happens because default-migrate
calls db->tree
internally which resolves links, but is what I just described desired migration behavior by default?@anmonteiro: after some debugging I found this error core.cljs:9857 Uncaught Error: No method in multimethod ‘my-project.infrastructure.parser/read' for dispatch value: :current-page
Is treating this key as a query, inside look for the inside ones
I assume I should create another read
with that key and inside of these raise the others queries?
@rgomezcasas: can’t say anything without more information
e.g. normalized vs. denormalized data, using db->tree
or not, recursive parsing or not
Ok, so my question is… I have a similar approach to https://anmonteiro.com/2016/02/routing-in-om-next-a-catalog-of-approaches/#routing-with-union-queries, but my “pages” have queries that goes to the read
fn, so I can’t get the keys directly from the state
Is there a way to call these reads from another read?
I’m not sure what you’re trying to say
I don’t know how to explain xD
My root element has this computed query
[:current-route
{:current-page-queries
[{:some-entity/new [:id :name :description]}]}]
So, this will trigger the defmethod read :current-page-queries
right
Is there a way to trigger the defmethod read : some-entity/new
from the : current-page-queries
read?
@rgomezcasas: you can use recursive parsing. in the env
argument for your read method, there’s a :parser
key
which allows you to recurse on the parser
the signature is env query target
okey!
So, I’ll return a map from my “query” using the recursive parsing
I don’t know what that means
In the :current-page-queries
I receive this query [{:promo/new [:id :name :description]}]
But in another page I could receive [:some-stuff :another {:some-entity/new [:id :name :description]}]
you probably want to recurse on the current route, if that’s what you’re asking
Yes xD
Ok, It’s all ok now, thanks, @anmonteiro! I’ll buy you a beer when you come to bcn for the fullstackfest 😛
The read method ended being:
(defmethod read :current-page-queries
[{:keys [query parser] :as env} _ target]
{:value (parser env query target)})
Hi folks - I'm working through my first om next app right now, and found a surprising case where the reconciler has the correct values for my state, but the components affected don't re-render. My current code is almost identical to the components, identity, and state tutorial: https://gist.github.com/stijlist/53b420fb1647070b78ee001687fb0de1#file-core-cljs-L53
The UI is a simple one - click the button on line 47, and the reconciler and dom both get updated correctly
If you click the button on line 53, though, the reconciler shows " [61353.954s] [om.next] [:parameters/by-name []] transacted '[(parameters/update {:name "Salary", :value 5, :editing? false})], #uuid "08f702ab-66a3-478d-b137-b3f488e248d5" "
But the UI remains the same - :value is still rendered as 2, and :editing? is still true
I’m using set-query! and IQueryParams to implement routing in an SPA. The problem is that not all of my top-level components have a query. This means that any attempt to call set-query! when transitioning to a top-level component with no query generates an error “Invalid join query”. I have fixed it by creating a dummy query and associated read for such components that just returns nil, but this seems like an ugly hack.
Is there any reason that set-query! couldn't accept nil joins and leave the dealing with that up to the read methods rather than throwing an error?
guys, you helped me to understand how to do reads with :query-root
and om/process-roots
, now I have a similar problem yet with mutations. So for my component bar
I have something like:
(defmethod mutate 'change-bar-data!
[{:keys [state]} key {:keys [bar-data] :as props}]
{:action #(swap! state assoc :current-bar-data bar-data)})
this mutation basically says get :bar-data
of a component from the state and put it in :current-bar-data
(let’s say you have a list of bar
s and want to render details (bar-data) of each in a view next to the list.
and it works when the component used as a root, but then if it is a child of another component it doesn’t, and now I have to do something like:
(defmethod mutate 'change-bar-data!
[{:keys [state]} key {:keys [bar-data] :as props}]
{:action #(swap! state assoc-in [:root-data :current-bar-data] bar-data)})
but what if next time I want same component be a child to another component?oh, gosh I think I know the answer, I have to do mutations with idents, since every bar
has and ident
in my case, currently I’m triggering the transactions like this:
{:on-click #(update-current-bar-data reconciler `[:current-bar-data ~bar-data] %)}
(defn- update-current-bar-data [ctx data ev]
(.preventDefault ev)
(om/transact! ctx `[(~’change-current-bar-data! ~data)]))
(defmethod mutate 'change-bar-data!
[{:keys [state]} key {:keys [bar-data] :as props}]
{:action #(swap! state assoc :current-bar-data bar-data)})
I don’t think it has to be as complicated as this, I copied it from somewhere and it worked. but apparently I’m doing something very wrongcan someone tell me how should I handle details
part of the list, in something like this: https://github.com/agzam/om-basic-app/blob/master/src/cljs/om_basic_app/ledger_index.cljs
@dgroulx: You only need to add an if
😛
@rgomezcasas: So I don’t really like the if
in the routing component solution since it will leave the query params set to the previous frames query which could trigger needless remote requests
Hey, I’m having the same problem @tmorten had here https://clojurians-log.clojureverse.org/om/2016-04-19.html
I have one read
fn that contains
(defmethod read :current-page-queries
[{:keys [query parser target] :as env} _ _]
{:value (parser env query target)})
But with this, the remote queries are not executed, is always trying to go local
Has anybody faced this?
@rgomezcasas: if you think about it, the recursive parsing call is returning back to your read
method and not to the original parser caller
so even if you specify :remote
in that call, what the original caller effectively sees is just a map with :value
, which is what you return at the topmost level
Ok…, So there is a way to be able to do remote queries by this way?
@rgomezcasas: definitely. in your topmost read you just have to check the value of the recursive parsing call
there was an example of this yesterday here
Ok, I’m going to try!! Thnks again, @anmonteiro 🙂
It’s working perfectly!! Now you deserve some beers and some cubata 😛
Thanks!
❤️ clojure.spec / cljs.spec https://gist.github.com/swannodette/c1444684bc2a8236634e4e110c654fe5