This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-11-05
Channels
- # beginners (11)
- # boot (121)
- # bristol-clojurians (3)
- # cider (5)
- # cljs-dev (45)
- # clojure (122)
- # clojure-conj (3)
- # clojure-germany (1)
- # clojure-japan (9)
- # clojure-russia (48)
- # clojurescript (129)
- # community-development (2)
- # cursive (17)
- # datomic (11)
- # editors-rus (3)
- # events (2)
- # funcool (32)
- # ldnclj (22)
- # om (110)
- # onyx (15)
- # re-frame (2)
@thosmos: that wouldn’t actually be so hard, the most challenging bit would be what to do with the query part
I'm missing somewhere the idiomatic way to build up a query for only rendered components. I see two possibilities, both of which seem like I'm missing something easier: (a) extensive use of Query Params and manipulation of them or (b) Looking at current state and conditionally returning null for things that I know aren't being rendered.
if you think of queries like urls then it’s a natural place to put result size parameterization
Result size make sense, I'm thinking more binary. Like I'm looking at the dashboard, and the "chat" nav item has not been clicked. I don't want to load the chat data until it is.
there is an reading code advantage to the declarative aspect of having syntax for it ...
Yes, just changing the query seems perfect, but my inclination is to return just the parts I need from IQuery. However, I've observed IQuery is only called once, not at each render. At least that is what appears to happen. I'd want IQuery called each time, access om/props from within it and return a different query.
This will be a common challenge for large apps that have deep functionality, much of which is infrequently accessed.
I don’t see any challenges here at all … only a challenge based on the way you to achieve this as far as I understand it
(dom/render-to-str (om/build some-widget data)) -- Would this would need to be done on the server?
Ok so that means even if I used Om with a different backend language I would still technically need JVM if I wanted to have a faster first page view and keep my SEO up
@grounded_sage: you would need a JavaScript engine, not a JVM
@bplatz: one way that’s more declarative is to put all the fragments you intend to use in IQueryParams
So using om/set-query! within the context of a transaction sounds like your recommendation. That sounds good, only downside I see is that it separates where you can easily reason about what a given query might be.
Do I need a JavaScript engine to run it when I am using Clojure on the backend?
I was referring to the logic that determines what a query might be. Part of it would end up being handled in a function that is detached from the component itself. Your recommendation of using Query Params is a way to avoid that.
@bplatz: ah, yes I see what you mean and it’s clearer what your original question was about.
yeah I would use IQueryParams
if I wanted to make it clear what types of queries a component might make
so of course working on recursive queries reveals things I do not like with current parse behavior
once you’re doing something recursive having to read from the atom only to rewrap a part of the atom to make a recursive call seems gratuitous
One item that has bothered me is common query items that are repeated at many levels of the query tree, for example something like :user/language. Most components will want to know it, so it ends up sitting in, with my case, 2/3 of all components. Keeping with the purity of the parser, it is looked up with every recursion. I was thinking I'd optimize some of this with memoize as I figure out the implications.
@bplatz the scaffolding for :shared
is there, I would probably propagate this at the root
@jannis I need to think about this some more once I can actually express my dislike for how parse looks in this case I will
@dnolen :shared works great for these sort of environmental variables, thanks for pointing that out. If IQuery can be analogous to a REST request, :shared can be analogous to HTTP headers... a context.
FWIW, at first blush :context seems a bit more descriptive of intention (or at least how my intention is of using it). Extends nicely to the idea of reusing code in different contexts, like React Native. Query defines data needed, context could modify behavior of the component.
and in Om Next we already had this before it was ever public in React and we called it shared
Function is a nice addition. I'll have to look to see if the function is executed only on the first root render, or every props change.
@dnolen: reconciler docstring states all properties are required
probably a typo?
@anmonteiro: thanks fixed
@bplatz: it’s run every root render but this shouldn’t really be problem since the function should be side effect free.
Hi guys. I am still stuck in my first attempt. https://gist.github.com/leontalbot/1d57bb05c063a989757c
@leontalbot: that’s a lot code for what is as far as I can tell a very simple problem / misunderstanding
just make the tiniest possible thing demonstrating the conceptual issue you are having
@leontalbot: can you explain why this doesn’t work for you ^ ?
You are right. I'll narrow down the problem tonight
i was surprised that om/computed
clobbers any existing computed props, but i’m doing this within a union component so i may only be seeing the outlier case
@joshfrench: there’s no particular reason for the behavior we could merge instead
ordinarily you wouldn’t pass down the complete props wholesale except in the case of a union or a pass-through, right? i’m trying to decide if it would be weirder to find inherited props in om.next/computed
or to have to manually reconstruct them at every level
that’s my hunch, for all the cases where merging would be a reasonable convenience there are probably more where it’s a code smell
I could imagine merging computed
to be quite confusing. Imagine A
passing down a click-fn
to a child B
, which in turn has another child C
that also allows a click-fn
to be passed down. You could easily end up passing the root click-fn
to both subcomponents by accident and weird things might happen.
If we don't merge, the click-fn
will only be set in child C
if it's explicitly passed down from B
. I think at least for callbacks that's desirable.
I think it helps a lot if you have to assemble computed
at each level. It'll be very explicit in each component, making it easier to understand what's going on.
Does anyone understand how creating new Todos work in David’s om-next-demo re: Getting the datomic generated Todo :db/id attribute back to the client? I can’t find anywhere where todos/create-temp
is being transacted
I have a thing that works for part of the problem. In my resource creation, I’m pushing into the list new item, but with an id of :temp
, which renders it to the screen. Then I kick off the :remote true
transaction
(defmethod read :places/list
[{:keys [state selector]} _ _]
(let [st @state]
(if (contains? st :places/list)
(let [places (get-places st selector)
has-temp-place? (some #(= (:db/id %) :temp) places)]
(if has-temp-place?
{:remote true}
{:value places}))
;; First pull
{:remote true})))