Fork me on GitHub
#reagent
<
2017-08-30
>
lepistane08:08:10

wanted to add button "back to the top" when i scroll 300px

lepistane08:08:14

i found this example

lepistane08:08:43

window.onscroll = function() {scrollFunction()};

function scrollFunction() {
    if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
        document.getElementById("myBtn").style.display = "block";
    } else {
        document.getElementById("myBtn").style.display = "none";
    }
}

lepistane08:08:56

added that to html in <script> tag

lepistane08:08:03

how do i convert that Js function to cljs

lepistane08:08:08

how can that be used?

lepistane08:08:36

i dont know how to access the window.onscroll so it is global like in that js file

lepistane08:08:11

maybe the question isnt right how do i do this properly in reagent ? that is maybe better one

lepistane08:08:32

so can anyone help?

reefersleep10:08:04

@lexwin I added more comments to the ReactTransitionGroup github issue for reagent-project: https://github.com/reagent-project/reagent/issues/55

lexwin10:08:34

Yes, I see! But I'm wondering if that issue was dead too long, maybe a new one should be started.

reefersleep10:08:43

That may very well be 🙂

reefersleep10:08:41

@lepistane you should have access to the same js functions, look up clojurescript / js interop. You’ll probably have to dig a little and fiddle with it to get it to work. As for the “proper reagent solution”, I don’t know 🙂

lexwin10:08:53

I also looked at the code you found but I think my conclusion was that that was only for when reagent needed to add its behaviour?

reefersleep10:08:32

the custom-wrapper function, you mean?

reefersleep10:08:43

in reagent-project

reefersleep10:08:26

I can’t tell what it does 😄

reefersleep10:08:02

I mean, it wraps function calls somehow, but why or what the wrapping does is beyond me at the moment

reefersleep10:08:32

bbl, lunchtime 🙂

lexwin10:08:30

I will create a new ticket

reefersleep11:08:51

Are you Scandinavian, btw? Looks like we’re in the same time zone. (And I notice the “å” in your last name… : )

stvnmllr214:08:58

any idiomatic way to have a for return more than one element per iteration? Want two tr elements sometimes, and other times one per item in the collection. Might just be a basic clojure problem, but thought i'd ask

lwhorton14:08:27

@stvnmllr2 you could use a vec as your return argument

lwhorton14:08:51

(let [[one two] (returns-two foo)] ...)

lwhorton14:08:40

but as far as the reagent requirements, you cannot pass two flat siblings and expect it to render - each node must have only 1 root

stvnmllr214:08:03

ok. figured. thx

lwhorton14:08:53

hey all .. i’m running into a pretty outlandish bug of which I’m still not 100% sure the root cause. I suspect its a call-stack-overflow caused by the fact that reagent uses a renderqueue via requestAnimationFrame: https://github.com/reagent-project/reagent/blob/dda0cfa0ad65f40659304bccd7ae069237025809/src/reagent/impl/batching.cljs#L54-L58

lwhorton14:08:57

if an animation frame is never granted for a long while, for example in google chrome where only the active tab gets the frame, i think this eventually leads to the flushing of a queue that exceeds memory limits

lwhorton14:08:51

i.e. if someone tabs-away from the running reagent process, but that process continues to receive websocket updates, it will seemingly enqueue requests for the next frame until it finally blows the stack when swapping back to the tab

jaju18:08:43

Hello. While this is a more general problem, I’m asking with the hope that someone here has encountered it and knows where I might be wrong. I have the following (relevant) dependencies in my project.clj [cljsjs/react-dom “16.0.0-beta.5-0”] [cljsjs/material-ui “0.19.0-0" :exclusions [cljsjs/react cljsjs/react-dom]] [reagent “0.7.0” :exclusions [cljsjs/react cljsjs/react-dom]] But in my output JS file, with advanced mode compilation, React code is included twice. What could possibly be wrong? My build config looks like this :prod {:id :prod :source-paths [“src”] :compiler {:source-map-timestamp true :main “==my-main-namespace==” :verbose false :output-to “www/js/app.js” :output-dir “www/js/app-out” :optimizations :advanced :pretty-print false :source-map “www/js/app.js.map” :cache-analysis true :externs [“externs/material-ui.js”]}}