Fork me on GitHub
#clojurescript
<
2018-07-24
>
jjttjj00:07:17

i have a lot of data coming in as json, and being rendered as js objects, so i don't really want to add the overhead of converting too and from clj data structures. but the js data updates over time and needs to be re-rendered, and it would be nice to be able to treat it like an atom

justinlee00:07:10

@jjttjj there’s probably a reason not to, but the idea is kind of intriguing. if the data always comes from the server, then it seems quite interesting. if you are doing a lot of manipulation on the client side, then you may end up converting from clj->js (?). i implement ILookup on object (even though there are reasons that’s a bad idea) so that get-in and destructuring work on js objects. that would pair nicely if you ended up doing that.

ajwerner07:07:50

Hi I have a pretty simple web app made with re-frame/reagent/re-com and one annoying thing is that I'm using the secretary/accountant to deal with routing and I'd expect that when switching pages, it'd scroll to the top of the new page. Is there a trick to make sure that it sets the scroll to the top of the page when navigating?

gregg07:07:52

Yep, we had the same problem in our re-com demo page: https://re-com.day8.com.au

gregg07:07:57

We fixed it by defining a scroll-to-top fn and calling this when we navigate to new pages

gregg07:07:11

Having said all that, I just tested it and it no longer works. The code was written a long time ago and so, many moving parts have now moved

gregg07:07:18

But hopefully this will provide inspiration for your code

gregg07:07:24

If you find out what's wrong with our code (or find a better way), drop me a note or create a PR 🙂

ajwerner16:07:26

(defn ui-comp [p]
  (let [ref (atom nil)]
    (reagent/create-class
     {:component-did-update
      (fn [this]
        (if-let [r @ref]
          (.scrollIntoView r true)))
      :reagent-render
      (fn [p] (if p
                [:div {:ref (fn [com] (reset! ref com))} p]
                [:div]))})))

(defn ui []
  (fn [] [ui-comp @(rf/subscribe [:page])]))
The above snippet worked beautifully. ui is my outermost container.

gregg22:07:43

Cool. Thanks

gregg07:07:10

PS: The main problem is...it's not really switching pages, just re-rendering on the same one

royalaid07:07:29

Idea for you

gregg07:07:35

Can only speak for our demo

royalaid07:07:49

I had to solve a similar problem recently and used scrollIntoView

royalaid07:07:31

if you have the element you can just call this on initial render and it should reset the page

royalaid07:07:52

that being said it does require a form-3 component

ajwerner16:07:48

👍 worked like a charm

abdullahibra10:07:58

https://presumably.de/reagent-mysteries-part-1-vectors-and-sequences.html, in this post it shows how can you reagent table, i have tried this with making fields of rows as input, but when change the values of inputs i got re-render the row

abdullahibra10:07:04

i can't figure this out

abdullahibra12:07:47

my situation is: i have input field which has css hover property to change the radius, when i hover and change the input i got flashing the input

abdullahibra12:07:02

how can i fix this? or even what cause this problem?

abdullahibra12:07:05

what do you think guys?

Rina13:07:39

Hi How can I set the n element in a JS array in my clojurescript code?

dehli14:07:06

Anyone know why when I do clojure -m cljs.main -re node and execute (cljs.nodejs/require "package") I get that the module cannot be found when it is in my node_modules?

dehli14:07:34

When I use cider-jack-in-cljs it can find the package fine so I must be missing some command line argument

thheller14:07:43

@dehli did you check the current directory? maybe you are just in the wrong directory? try (js/process.cwd)

dehli14:07:50

Ya, the current directory is the one that has node_modules inside of it

thheller14:07:27

@dehli I'm not sure where CLJS puts the output files. see if js/__filename is defined?

dehli14:07:34

it's set as [stdin]

thheller14:07:37

does (js/require "aws-sdk") report the same error?

dehli14:07:16

nope! that works

dehli14:07:37

should that be used in place of node/require?

thheller14:07:17

well ideally you should use (require '["aws-sdk" :as x]) but that only works in shadow-cljs currently

thheller14:07:38

well it might work for CLJS too I'm not actually sure

dehli14:07:57

I'll see if that works. Thanks for your help!

richiardiandrea15:07:32

The above works here with shadow, I use it in my project with plain install to package.json

dehli15:07:40

So the above works, however when I do (require 'aws.core) it fails since that namespace has (js/require "aws-sdk") inside of it

abdullahibra18:07:32

can i use this within clojurescript project https://felicegattuso.com/projects/datedropper/ ?

Joe G18:07:30

Does anyone know of an example that uses the D3 treemap? I can’t seem to find one on Google

quoll20:07:15

@mfikes Now you can see what I was attemping to do over the weekend 🙂

mfikes20:07:22

Pretty cool!

quoll20:07:53

I saw your retweet on Twitter 🙂

quoll20:07:23

I love how I can go back through the pages, change the definitions, and have it do something completely different in the end

mfikes20:07:17

Yeah… having the compiler with you in the browser is still something I find crazy cool 🙂

mfikes20:07:12

I think your site can be a great intro to people who are interested in Clojure / ClojureScript… especially since you can mess with the code

quoll20:07:23

That’s exactly the purpose

quoll20:07:48

show people that ClojureScript can really be used to do things in a web page

quoll20:07:32

this is why I showed the SVG structures. Sure, I don’t mention sablano, but it’s just an intro

quoll21:07:32

wrap it all up in a Game-of-Life-via-Linear-Algebra bit of über geekiness 🙂

mfikes21:07:09

@quoll There is one place where it dumps the value of a function (and you see a lot of JavaScript). You might be able to avoid this by simply adding :def-emits-var true to the options passed into the eval-str call. https://clojurescript.org/reference/repl-options#def-emits-var

quoll21:07:03

I was wondering there… I realize that it’s messy, but it also shows people that this really is generating code that does stuff!

mfikes21:07:11

That’s true

quoll21:07:59

do you know what the figwheel repl uses when printing a function? Because it just shows a short object string

mfikes21:07:21

Yeah, if you want to see the function value (set! *print-fn-bodies* true)

quoll21:07:53

thank you

bhauman21:07:57

@mfikes you set that in CLJS land or Clojure land?

quoll21:07:07

I could turn that off

mfikes21:07:10

It is a ClojureScript var

mfikes21:07:28

cljs.core/*print-fn-bodies*

quoll21:07:44

I don’t think I want to change the :def-emits-var, as there are a couple of screens which do a def, and they wouldn’t see what was generated

quoll21:07:55

I’m also trying to avoid configuring different behavior for each screen (there’s a little of that, such as the text vs. SVG output)

steven kent23:07:49

Hi, is anyone very familiar with cljsjs.react-modal? I am trying to make modals disappear when the user clicks the browser back button. The best info I have found is http://reactcommunity.org/react-modal/ , but I am currently unable to solve this. Any help appreciated.