This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-29
Channels
- # bangalore-clj (2)
- # beginners (22)
- # boot (28)
- # cljs-dev (91)
- # cljsrn (4)
- # clojure (30)
- # clojure-austin (8)
- # clojure-conj (4)
- # clojure-japan (1)
- # clojure-russia (3)
- # clojure-spec (9)
- # clojure-uk (8)
- # clojurescript (42)
- # cursive (2)
- # editors (1)
- # hoplon (16)
- # klipse (91)
- # lein-figwheel (1)
- # luminus (9)
- # off-topic (4)
- # om (83)
- # onyx (29)
- # perun (6)
- # re-frame (17)
- # spacemacs (6)
- # untangled (1)
- # vim (5)
@anmonteiro: use om.next server render. on the side of the backend component runs a query and html render-string, but on the client side state is empty map respectively on mount component in DOM/backend Component! = client/Component. Look at the example of om-full-stack, but in this example and the backend and the client state is empty map
@a.espolov sorry I don't understand what your problem is
there's nothing magical happening in server-side rendering. you only get HTML on the client. you still need to initialize your state and fetch things from the backend
I'm not sure if that answers your question?
"initialize your state and fetch things from the backend" - run before the client component will prove is mount?
you need to fetch your data somehow just like you would do without server-side rendering
in the fullstack example, the state is an empty map because it's initialized after a request to the backend
np, hope that helps
I'm a big fan of the cider debugger. To what extent can om-next be developed only in clojure (not clojurescript)? Presumably you can't add-root!
without a real gdom/getElement
. I'm not sure what testing of the app I can do without combining the reconciler with components via add-root!
. Just wondering if there is something I'm missing, or if I'll just have to surrender my cider-debugger?
@anmonteiro call (dom/render-to-str c) returned state -> serialize state to json and put js to DOM -> deserialize on init reconciler
I still don’t understand what this error message means: "No queries exist for component path: (componentA componentB)"
@arohner usually means you're not composing components' queries correctly
e.g.: where Parent
-> Child
;; wrong:
(defui Child
static om/IQuery
(query [this]
[:child]))
(defui Parent
static om/IQuery
(query [this]
[:parent]))
;; correct:
(defui Child
static om/IQuery
(query [this]
[:child]))
(defui Parent
static om/IQuery
(query [this]
[{:parent (om/get-query Child)}]))
ah, i have
(defui Parent static om/IQuery (query [this] `[:parent/foo ~@(om/get-query Child)]
`i.e. you have to set up an explicit "path" between the queries in the component tree
@arohner that's definitely not going to work
you're stealing queries
they need to compose through joins
@anmonteiro so if I have [{:child ~(om/get-query Child)}]
, and I want child to be able to read out of global app state, that means I need to (defmethod read :child)
, and have it call {:value (om/db->tree (om/get-query Child))}
, right?
@arohner hrm, you'll get a :query
entry in env
so no need to specifically get a component's query in the parser
(`env` as in the 1st arg to the read method)
@anmonteiro ok, so db->tree looks like it works, except that it isn’t calling read
on things that would send, so my sends aren’t happening
@arohner so db->tree
doesn't call read
if you want to call read
on nested stuff you need to call the parser recursively
i.e. call the parser inside read
(there's also a :parser
key in env
)
don't forget, though, that you need to return the parser result at the top-level. i.e. if you don't return :remote ...
in the topmost call, send
won't be called
@arohner here's one example of calling the parser recursively https://github.com/compassus/compassus/blob/master/src/main/compassus/core.cljc#L184-L186
@anmonteiro thanks. What does target
mean there?
target is :remote
in the default case
but you can have multiple targets
the target for which the parser is currently reading will be in :target
under env
i.e.: there's a :remotes
reconciler option (defaults to [:remote]
)
but you can easily have more than one, think static / dynamic endpoints
@arohner the remote synchronization tutorial touches on this a bit: https://github.com/omcljs/om/wiki/Remote-Synchronization-Tutorial#remotes-1
yeah, I know the feeling 🙂
@arohner maybe looking over the Compassus tests could help? https://github.com/compassus/compassus/blob/master/src/test/compassus/tests.cljc
there's some simulated remote stuff there
@anmonteiro one more stupid question. recursively calling the parser works, and sends fire, but it looks like my Parent render method isn’t being called again after the sends return?
@arohner hrm that might be the case depending on the remote response
by default the merge function will queue (keys novelty)
for re-read
ah, but the send queried for [{:child [:foo]}], recursively sent for [:foo], which got returned. Nothing depends on :foo because according to parent, it depends on [{:child [foo]}], and does nothing
@arohner right, that's what I suspected 🙂
@arohner you'll need to override the merge function
which if I recall correctly you already do?
right. now you need to modify the :keys
part that merge returns
@arohner give me 1 sec
(into (or (:keys novelty) [])
(map (comp :dispatch-key om.next.impl.parser/expr->ast))
(om/transform-reads reconciler (keys novelty)))
^ that should queue the appropriate things for re-read
(untested, though)
what is novelty here? default-merge has a signature of default-merge [reconciler state res query]
sorry, I thought the signature had novelty
@anmonteiro how to render cljs om component(example use d3) in cljc om component?
@arohner btw, in case you're wondering, it's normal to have to override these things in the reconciler, e.g. :merge
, :migrate
, etc
the default implementations are intended to be naïve and not fit for every use case
@anmonteiro ok, still not working. I’m trying to manually trigger the render just to prove this approach is correct
after the sends, shouldn’t I be able to (p/queue! reconciler [:foo]) (om/schedule-render reconciler)
and see the UI update?
@arohner doesn't quite work like that. the render loop is async and renders are batched
@anmonteiro but the point is, I should be able to call something that says the key has changed, and then trigger a render?
you can (om/transact! reconciler [:foo])
🙂
that wasn't obvious to me until very recently
hrm though that might hit the server again
I assume you don't have this code somewhere (public)?
I'd rather look at a minimal case, if you have the time to produce one
Just out of curiosity, why make a new cache type and use js arrays in om.next? https://github.com/omcljs/om/blob/ee4c7ac33934fcd9b3ea663045ced1408dd7df24/src/main/om/next/cache.cljs I’m guessing the js array has better performance than an immutable vector. Is the custom type just for encapsulation?
@anmonteiro https://github.com/arohner/om-next-fullstack/blob/master/src/shared/todomvc/todomvc.cljc