Fork me on GitHub
#reagent
<
2016-03-14
>
sd16:03:15

when using lein reagent template, my .clj changes don’t seem to restart the ring server - is that by design?

noisesmith16:03:26

sd: yes, the best way with ring is to pass a var as your handler function, then redefinitions of that var will be used on the next request

noisesmith16:03:52

eg. pass #'handler intead of handler to your server process as the handler function

noisesmith16:03:46

and if you also want auto-reload on file change, that's better set up through tooling (eg. your editor) or via the wrap-reload ring middleware, which is not provided by default but is easy to add

sd16:03:49

thanks, i’ll try that

leppert19:03:57

Clojure / Reagent newbie here. I wanted to kick the tires on FB Draft.js (https://facebook.github.io/draft-js/) so I ported over their “hello world" example: - Reagent: http://pastebin.com/MnBC52SS - original: https://github.com/facebook/draft-js/blob/master/examples/rich/rich.html I’m getting some weird behavior in on-change, namely that it’s called two or three times with each keypress, whereas in the original JS example it’s called only once per keypress. Is this an expected difference when using Reagent or something I’ve mixed up?

cky19:03:58

Wow. Thanks for pointing me in the direction of a React-based text editor!

leppert19:03:48

@cky: np! The main catch is that it’s backed by Immutable.js, so there’s some redundancy in there when coming at it from a CLJS angle.

pez21:03:19

In the SPA I am working with, page routing is more about changing the contents of a component. This makes the app have a “global” scroll position (e.g. if I’m scrolled down on a page and navigate to another page, I remain scrolled down on the next page). This creates a weird Ux so I am now forcing a scroll to the top of the replaced content. I’d like some input on wether I am doing it right or wrong (or somewhere in between). I have created a component wrapper like so

(def scroll-to-wrapper
  (let [get-top (fn [component]
                  (+ (-> component
                         .getDOMNode
                         .getBoundingClientRect
                         .-top)
                     (.-pageYOffset js/window)))
        scroll-to (fn [component]
                    (js/scrollTo 0 (get-top component)))]
    (with-meta identity
      {:component-did-mount #(scroll-to %)
       :component-did-update #(scroll-to %)})))
When wrapping my content component in this I get almost the behaviour I want. I’d like to be able to treat history back specially (going “back” to the scroll position the page had when I navigated away from it), but don’t know how to do it.

gadfly36121:03:02

I typically have a function like set-page!, where you scroll to top as a side effect whenever changing pages. This doesnt help the going back part, but it does alleviate the need to wrap all your components in a scroll thing.

pez22:03:09

@gadfly361: I only wrap my “page” component in in this, so only in one place. The reason I do it this way is that I don’t want to scroll to the top, but to the top of the page content.