Fork me on GitHub
#clojurescript
<
2021-07-10
>
Nazral04:07:29

any lib recommendation to plot charts in cljs? I've found oz based on vega but it looks pretty complicated and quite overkill for what I want to do at the moment

vanelsas05:07:43

I've used recharts and am quite happy with it

Nazral09:07:38

I ended up going with vega in the end, but thank you for the recommendation

edo11:07:23

Hey everyone, I’m learning clojure(script) 🌈 I’m tackling a small challenge and I’m a bit stuck in how should I write the on-change function of my text-input component. I think I need some help from you mates. ❤️ Here’s a screenshot of my code at this point.

p-himik11:07:35

#reagent would be a more suitable place. Also, it's much better to put the code itself here, and not a screenshot. Slack has two ways of embedding code blocks and one way of using inline code. With that said, you're calling reset! on value, but seems like value is actually a string. If you need to change only value and not the rest of the input fields, remove the outer atom and wrap the value strings in their own atoms. A related thing - the way you wrote the code, those ratoms are (re)created upon namespace evaluation. It means two things: • Re-rendering will not change inputs' values. So even if you unmount the whole component and then add it back, the values will stay the same. Could be changed by creating those atoms in the components themselves, maybe their parent. reagent.core/with-let and form-2 and form-2 components are useful here • Code reloading will reset those values back to their initial value. Can be changed with defonce

p-himik12:07:28

And if you do want to store the whole state of everything in a single atom, you should use swap! instead, pass the whole state atom to it, and use update-in with the right path to change the relevant value. But at that point, you will be reinventing the wheel that re-frame has implemented quite some time ago.

edo12:07:24

Thanks mate! That explains a lot. Next time I’ll paste the code in the reagent channel. Thanks for the suggestion!

👍 3
spacebat16:07:37

Hi, trying to get started with cljs, thought I'd try re-frame but don't want to create a bunch of files by hand, found this https://github.com/day8/re-frame-template

spacebat16:07:28

but it's not clear how to install this template so that leinginen will see it - I found some advice to put is in the classpath, but CLASSPATH=~/re-frame-template lein new re-frame-template myapp doesn't work, it complains that I set the classpath var, then fails to find the template. I've been bouncing around between documentation and blog posts but nothing seems to connect the dots

spacebat16:07:10

how do I install a template so I can start a re-frame project?

p-himik16:07:55

Have you read the README of the template project?

p-himik16:07:29

In general, you don't install templates yourself. They exist as jars in public repositories. Lein knows how to handle them.

spacebat16:07:16

yes, oh I shouldn't have added -template

serg19:07:50

Hi, is there any ClojureScript library like https://www.npmjs.com/package/isomorphic-fetch, that can run in node and browser?

p-himik19:07:15

It's not that often that you see a CLJS library doing the same thing as an existing JS library is already doing, given that CLJS/JS interop is rather smooth.

p-himik19:07:55

To be clear, I have no clue whether such a library exists. But if there's already isomorphic-fetch that you probably know how to use, I'd just use it without even looking for an alternative.

serg19:07:03

Right, I saw a few like cljs-ajax and cljs-http, lambdaisland/fetch, but they all for the browser, I thought that there should be something like this already.

emccue19:07:08

require('isomorphic-fetch');
 
fetch('//offline-news-api.herokuapp.com/stories')
    .then(function(response) {
        if (response.status >= 400) {
            throw new Error("Bad response from server");
        }
        return response.json();
    })
    .then(function(stories) {
        console.log(stories);
    });
(ns your.ns
  (:require ["isomorphic-fetch"]))

(-> (fetch "//offline-news-api.herokuapp.com/stories")
    (.then 
      (fn [response]
        (if (>= (. response -status) 400)
          (throw (js/Error. "Bad response from server"))
          (.json response))))
    (.then
      (fn [stories]
        (.log js/console stories))))

p-himik19:07:37

Just add ^js in front of response to make sure that .-status and .json are not munged during :advanced optimizations.

serg19:07:37

Great, thanks!!! I also want to connect it with transit, to provide better ClojureScript interrop, perhaps I can create a wrapper lib.