Fork me on GitHub
#om
<
2016-10-29
>
a.espolov11:10:18

@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.espolov11:10:38

way it should be?)

a.espolov11:10:13

and I'll have to somehow initialize client state with necessary data?

anmonteiro11:10:54

@a.espolov sorry I don't understand what your problem is

anmonteiro11:10:50

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

anmonteiro11:10:59

I'm not sure if that answers your question?

a.espolov11:10:01

"initialize your state and fetch things from the backend" - run before the client component will prove is mount?

anmonteiro11:10:38

you need to fetch your data somehow just like you would do without server-side rendering

anmonteiro11:10:59

in the fullstack example, the state is an empty map because it's initialized after a request to the backend

anmonteiro11:10:01

np, hope that helps

fenton11:10:28

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?

a.espolov13:10:11

@anmonteiro call (dom/render-to-str c) returned state -> serialize state to json and put js to DOM -> deserialize on init reconciler

arohner18:10:17

I still don’t understand what this error message means: "No queries exist for component path: (componentA componentB)"

anmonteiro18:10:21

@arohner usually means you're not composing components' queries correctly

anmonteiro18:10:11

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)}]))

arohner18:10:21

ah, i have

(defui Parent static om/IQuery (query [this] `[:parent/foo ~@(om/get-query Child)]
`

anmonteiro18:10:24

i.e. you have to set up an explicit "path" between the queries in the component tree

anmonteiro18:10:26

@arohner that's definitely not going to work

anmonteiro18:10:30

you're stealing queries

anmonteiro18:10:50

they need to compose through joins

arohner19:10:19

@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?

arohner19:10:21

or is there a cleaner way?

anmonteiro19:10:00

@arohner hrm, you'll get a :query entry in env

anmonteiro19:10:18

so no need to specifically get a component's query in the parser

anmonteiro19:10:43

(`env` as in the 1st arg to the read method)

arohner19:10:05

@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

anmonteiro19:10:41

@arohner so db->tree doesn't call read

anmonteiro19:10:02

if you want to call read on nested stuff you need to call the parser recursively

anmonteiro19:10:17

i.e. call the parser inside read

anmonteiro19:10:23

(there's also a :parser key in env )

anmonteiro19:10:13

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

arohner19:10:07

@anmonteiro thanks. What does target mean there?

anmonteiro19:10:23

target is :remote in the default case

anmonteiro19:10:30

but you can have multiple targets

anmonteiro19:10:58

the target for which the parser is currently reading will be in :target under env

anmonteiro19:10:27

i.e.: there's a :remotes reconciler option (defaults to [:remote])

anmonteiro19:10:37

but you can easily have more than one, think static / dynamic endpoints

arohner19:10:19

yeah, I’ve read that a few times, but it hasn’t really made sense yet

anmonteiro19:10:55

yeah, I know the feeling 🙂

anmonteiro19:10:25

there's some simulated remote stuff there

arohner20:10:57

@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?

anmonteiro20:10:46

@arohner hrm that might be the case depending on the remote response

anmonteiro20:10:09

by default the merge function will queue (keys novelty) for re-read

arohner20:10:42

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

anmonteiro20:10:03

@arohner right, that's what I suspected 🙂

arohner20:10:15

this whole use case seems entirely too hard to accomplish 😕

anmonteiro20:10:41

@arohner you'll need to override the merge function

anmonteiro20:10:47

which if I recall correctly you already do?

arohner20:10:23

yeah, but a different piece of it

anmonteiro20:10:38

right. now you need to modify the :keys part that merge returns

anmonteiro20:10:13

@arohner

(into (or (:keys novelty) [])
  (map (comp :dispatch-key om.next.impl.parser/expr->ast))
  (om/transform-reads reconciler (keys novelty)))

anmonteiro20:10:54

^ that should queue the appropriate things for re-read

anmonteiro20:10:10

(untested, though)

arohner20:10:29

what is novelty here? default-merge has a signature of default-merge [reconciler state res query]

arohner20:10:49

novelty = res?

anmonteiro20:10:23

sorry, I thought the signature had novelty

a.espolov20:10:02

@anmonteiro how to render cljs om component(example use d3) in cljc om component?

anmonteiro20:10:49

@arohner btw, in case you're wondering, it's normal to have to override these things in the reconciler, e.g. :merge, :migrate, etc

anmonteiro20:10:16

the default implementations are intended to be naïve and not fit for every use case

arohner20:10:47

@anmonteiro ok, still not working. I’m trying to manually trigger the render just to prove this approach is correct

arohner20:10:24

after the sends, shouldn’t I be able to (p/queue! reconciler [:foo]) (om/schedule-render reconciler) and see the UI update?

arohner20:10:35

my render function still isn’t being called, with any key I can think of

anmonteiro20:10:36

@arohner doesn't quite work like that. the render loop is async and renders are batched

arohner20:10:47

@anmonteiro but the point is, I should be able to call something that says the key has changed, and then trigger a render?

arohner20:10:28

I think my merge is correctly returning updated keys, and nothing is happening

anmonteiro20:10:38

you can (om/transact! reconciler [:foo]) 🙂

anmonteiro20:10:45

that wasn't obvious to me until very recently

anmonteiro20:10:14

hrm though that might hit the server again

arohner20:10:39

that would be fine for now, if this thing would re-render

anmonteiro20:10:57

I assume you don't have this code somewhere (public)?

arohner20:10:50

its not, but I could invite you

anmonteiro20:10:10

I'd rather look at a minimal case, if you have the time to produce one

currentoor22:10:08

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?

arohner22:10:45

I forked your om-next-fullstack as an example

arohner22:10:10

I was trying to play with links to see if I could get that to work, but I also tried our previous discussions

arohner22:10:23

I can get it to where it sends, but never redraws Header