This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-18
Channels
- # announcements (2)
- # babashka (65)
- # beginners (104)
- # boot (8)
- # calva (23)
- # circleci (3)
- # clj-commons (1)
- # clj-on-windows (3)
- # clojure (43)
- # clojure-europe (45)
- # clojure-france (2)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-norway (13)
- # clojure-uk (4)
- # clojurescript (5)
- # core-typed (2)
- # cursive (5)
- # data-science (2)
- # datalevin (10)
- # emacs (38)
- # events (2)
- # fulcro (11)
- # graphql (6)
- # gratitude (2)
- # helix (11)
- # hugsql (3)
- # jobs (2)
- # lsp (17)
- # luminus (1)
- # malli (15)
- # missionary (3)
- # nrepl (6)
- # off-topic (6)
- # pedestal (2)
- # portal (16)
- # reagent (33)
- # reitit (4)
- # releases (12)
- # ring (2)
- # sci (3)
- # shadow-cljs (21)
- # spacemacs (7)
- # sql (5)
- # tools-build (36)
- # web-security (2)
(defn production-rate
[speed]
(let [v (* speed
(cond (= speed 0) 0
(<= speed 4) 1
(<= speed 8) 0.9
(= speed 9) 0.8
(= speed 10) 0.77))]
(float (* v 221.0))))
(= (str 1392.3) (str (production-rate 7)))
(= 1392.3 (production-rate 7))
(= (float 1392.3) (production-rate 7)) = true check out https://clojure.atlassian.net/browse/CLJ-1036 also if your not aware (= 0.06 (+ 0.01 0.05)) = false because (+ 0.01 0.05) = 0.060000000000000005
the first equality return true, the second one return false
how to fix my function production-rate to let it return true ?
user=> (defn production-rate
[speed]
(let [v (* speed (cond
(= speed 0) 0
(<= speed 4) 1N
(<= speed 8) 9/10
(= speed 9) 8/10
(= speed 10) 77/100))]
(* v 221N)))
#'user/production-rate
user=> (= 13923/10 (production-rate 7))
true
user=> (= 1392.3M (bigdec (production-rate 7)))
true
For instance, depending on what you need exactly, of course.See also https://clojure.org/guides/equality#_floating_point_numbers_are_usually_approximations
@U4ZDX466T thank you!
remove the float
conversion will be ok:
(defn production-rate
[speed]
(let [v (* speed
(cond (= speed 0) 0.0
(<= speed 4) 1.0
(<= speed 8) 0.9
(= speed 9) 0.8
(= speed 10) 0.77))]
(* v 221)))
(= 1.23 (float 1.23)) will return false
Is there a way to print the code for a generated anonymous fn? It's an assembly of a few smaller pieces and I want to make sure they are composed correctly, but printing it predictably yields #object[Function] Edit: in CLJS btw, in case that matters :)
dunno but say your functions are at 1 point collected in a list, you could have 1 form evaluate to the list and test it in isolation
It's likely that im just a freaking idiot, but I cannot find any material on how to implement a cljs app and a clj webserver together without a template. I'm specifically trying to implement sente+reagent. I can create each component separately but all attempts to conjoin the two have failed. What can I read to figure this out? Nearing the end of my wits
thanks for the response! This is cool, I'll try to study it. Is there a write-up for how to arrive at code like this repo?
No, you'll probably have to look at several different projects that are doing what you want to see how they do things. I'm not aware of any in-depth analysis on this setup.
this build appears to fail anyway...
is there no resource on how to add a reagent frontend to an existing clj webserver? I have the two built already
let's say I create a "new" vector [1 2 3] a thousand times in a loop. Is there immutability or jvm magic that makes it so I don't allocate 1000 times?
it creates a java Pattern when compiled
how does one add a reagent frontend app to an http-kit webserver?
For development and getting started, I suggest setting up http-kit with shadow-cljs. Just add one route that serves some static index.html
which links to the generated app.js
file or whatever yours is called.
thanks for the response! How do I ensure that the app.js linked is my clojurescript?
https://github.com/FiV0/spa-ws-template it's an example project setting up a websocket with http-kit, but also serving a cljs frontend with re-frame
Here are the routes https://github.com/FiV0/spa-ws-template/blob/master/src/io/dbme/router.clj#L11-L14. So you serve the https://github.com/FiV0/spa-ws-template/blob/master/resources/index.html and shadow-cljs compiles the js which gets served as a resource. Let me know if that makes sense.
in what thread? if it's https://github.com/DavidVujic/sente-with-reagent-and-re-frame then that's similar to the solution you supplied above, it's a complete project without a wrrite-up w/r/t replication or a template
thanks for asking, I feel like an absolute dunce.
I feel worse than that, but I'm trying to keep it clean on the boards
i can create an webserver with compojure and http-kit and I can create a reagent app. I can do these things with appropriate templates such as lein new app
or lein new reagent
but I have also found guides to build them from scratch, which is my preference. however, I have not found any guides for adding clojurescript to an existing clojure webserver; only for starting a new full-stack template or for creating one or the other. I don't know how to join them
I'm trying to build something to help with job applications, as I got laid off two months ago and am starting to lose my sh*t
for that reason I am trying to find a method that does not rely on templates. the reagent template uses reitit, for example, which I could not get to play nicely with sente. I asked about it earlier and got "try not using a template"
yes totally get it. I think looking at templates just helps you see how other people might do it and then you can copy bits and pieces.
the sort of "dumbest" thing you can do if you have both a server and frontend project running is to just hardcode the app.js
path of the reagent app in your index.html
and go from there
just what I rebuilt today, at least
it runs with lein run on port 3000
it has some clojurescript but none that's loading
im updating the deps
i just pushed an update that expands the project.clj file to include more deps as well as :profiles, :cljsbuild, and :figwheel
lein run still behaves (by building to 3000 and displaying random pokemon)
wow it looks like is a magic totem that makes my code work
that and all the screaming from this morning
now if only i could add sente to the frontend section of my app
now I still need to navigate the last hurdle: I keep getting 403s (bad request) from the chsk handshake in the browser console.
oh flip duh i need middleware
tried adding middleware and keep getting classNotFound exceptions... đź’˘
I updated the Readme in https://github.com/FiV0/spa-ws-template
this looks lovely! I'd love to use this, but I'd need to be able to re-build it myself esp. if I ever used it in a production setting or to use for job applications. What's your process for building this? did you start from scratch or with a template?
I've finally gotten an http-kit server running with reagent on the frontend and am trying to implement sente to facilitate client-server interaction. here's https://github.com/jollyblondgiant/clj-pokedex so far (it's a little messy because I'm still figuring out the details). everything works (in its dinky way) except for sente, which keeps causing a 403 (bad request) error in my browser console. what piece am i missing? feeling crazy
looking at the sente code, it appears have two places 403's are given, and in returns an informative message in the body for both
GET 400 (Bad Request)
goog.net.XhrIo.send @ xhrio.js:198
taoensso$encore$ajax_lite @ encore.cljc?rel=1637263374814:3424
taoensso$sente$poll_fn @ sente.cljc?rel=1637263375810:1431
(anonymous) @ sente.cljc?rel=1637263375810:1425
looks like something related to wrap-params
and wrap-keyword-params
middlewares. injected them back into my code and I'm still getting 400. this time the browser error is much larger
how can i determine the fault between the csrf token and a bad websocket origin? i've updated the https://github.com/jollyblondgiant/clj-pokedex
being a 400 and not a 403 (I saw 403s once but now, having done I-kn-wnot-what. I only see 400s now), it looks like the websocket's never acutally connecting.
It looks like requests to localhost:3449/chsk aren’t valid routes, but I did set up the CHSK routes in the server and I don’t know how to point them at any other endpoint from the client.
sounds like you are trying to do sente stuff against the server figwheel runs, and not your server with your routes
In one terminal I run “lein figwheel”. In another terminal I run “lein do clean, run. ” the lein run terminal seems to hang though, even after i rebooted my machine
Is this something I need to update in the project.clj file or in my server code?
Some stdout that says what port it’s running on maybe
lein run, if everything is correct, will just run this function https://github.com/jollyblondgiant/clj-pokedex/blob/master/src/clj/pokedex/core.clj#L84-L95
I just don’t want to assume I’m not an idiot
If anything isn’t going right I just assume it’s because I broke it. So it’s good to hear that lein run is still behaving normally
I’ve been beating my brain against this wall since Monday. It’s starting to take its toll on me.
I suspect you need to point the sent stuff at the sente stuff at the server start via lein run, and not whatever figwheel is doing
if you look at the README file in the project it actually mentions that websockets may not work correctly with the figwheel server
How can I fix the issue you alluded to above, that sente may be pointed at the wrong server?
Cool, I’ll remove figwheel and try again. Does this preclude using figwheel for development then?
i'm testing locally with lein figwheel
hello I am trying to use a react component in my clojurescript app I am trying to convert a html to hiccup is it correct way:
original react code
<Pie dataKey="value" data={data} cx={200} cy={200}fill="#ff7300" label />
my hiccup
[Pie {:dataKey "value" :data data :cx 200 :cy 200 :fill "#ff7733" :label true} ]
@m373h4n this looks good. react may act funny and require you to prepend your custom data keys with :data-
eg :data-cx
in javascript what does curly brackets means why they wrote {200}
instead of 200
I never used react outside clojurescript it confuses me 🙂
Thats not actually plain JS, its JSX. Its a way to splice in a value in a prop of a React component.
so <MyComponent propName={3} />
means ’create a react component, MyComponent
, with as props, propName
with value 3
In JSX you need to enclose all values that aren’t strings (and booleans, other story) with {}
(ns tools.charting
(:require
[reagent.core :as r]
["recharts" :refer [PieChart Pie Sector Legend Tooltip Cell]]))
(defn chart-render []
[:div.boxed
[:h1 "Hello!"]
(let [data [{:name 'Ada' :value 800}
{:name 'Turing' :value 500}
{:name 'Alice' :value 700}
{:name 'Bob' :value 900}]]
[PieChart {:width 800 :height 400}
[Pie {:dataKey "value" :data data :cx 200 :cy 200 :fill "#ff7733" :label true}]])])
When I use PieChart
or Pie
results an error TypeError("Cannot call a class as a function")
I am trying to draw a chart just like this: https://github.com/recharts/recharts/blob/master/test/specs/chart/PieChartSpec.js the way original javascript version calls must be identical to my clojurescript. according to my understanding it should just work but apparently I am missing something.https://github.com/reagent-project/reagent/blob/master/doc/InteropWithReact.md#creating-reagent-components-from-react-components should give some documentation about how to call react components directly from reagent forms