Fork me on GitHub
#clojurescript
<
2018-05-20
>
yen04:05:01

How do you do maths in clojurescript?

yen04:05:13

It looks like clojure.math.numeric-tower isn’t supported in cljs

benzap04:05:13

I usually use js/Math

benzap04:05:32

Anything that javascript uses can be used in clojurescript, if you need sin(), you could use js/Math.sin ie. (.sin js/Math x)

benzap04:05:19

For additional libraries, you could check out what's available in Clojure Toolbox: https://www.clojure-toolbox.com/

👍 4
benzap04:05:45

In the search bar if you type "Math", a few libraries come up with more advanced stuff

benzap04:05:59

although, it looks like all of them are for clojure... so I guess that isn't much help

theeternalpulse05:05:38

what's the easiest way to append a string into a dom element, don't seem to be finding a straightforward way. if I have a string, how can I create a dom node that I can easily append to another element's body

theeternalpulse06:05:53

On that note, is there an easy way to get the metadata of a function in clojurescript

theeternalpulse06:05:46

the clojurescript repl allows me to use (-> fn var meta :my-meta) but the browser complains about calling var

benzap07:05:26

@theeternalpulse You're still working with Dom elements similar to how you would do it in javascript, so you would access, create, append using js/document, js/window, etc

benzap07:05:21

so to append to a dom element, assuming the dom element was elem, you could do (aset elem "innerHTML" "the string")

benzap07:05:12

Which is similar to how you would do it in javascript elem.innerHTML = "the string";

benzap07:05:12

say you wanted to append a div with class "foo" to elem:

theeternalpulse07:05:24

so the doto was a gap I was missing

benzap07:05:58

It's a nifty macro

benzap07:05:07

really useful for javascript interop

theeternalpulse07:05:59

I ended up just declaring a block in the header with an ID and using reagent's render for it

theeternalpulse07:05:14

but I like this since it can let me append instead of replacing

risto08:05:46

hi everyone 👋

risto08:05:01

does anyone know how to set up figwheel to use lumo?

jco10:05:25

Hi, I'm attempting to get Figwheel to work with Stuart Sierra's Component library. My (Ring) server is a Component. I've tried using the figwheel-sidecar.system/figwheel-system function that is described in the README of figwheel-sidecar. This function is used to create the :figwheel Component of my System. I have another Component for my application server (port 3000). The result is that when I visit localhost:3449, I get an error message Figwheel Server: Resource not found, Keep on figwheelin'. My application is available at localhost:3000, and seems to work fine, but I guess without Figwheel support... I was hoping to get a figwheel-enabled version of my application when visiting port 3449. Any ideas of what I could be doing wrong?

mfikes11:05:41

Also, expressions like (Math/sin 0.3) work (which matches Clojure).

yen12:05:26

How does one reuse extend-protocols in a different namespace?

kwladyka16:05:11

What is the best way to use https://mdbootstrap.com/react/ with ClojureScript (re-frame)? Will it make issues?

dvingo16:05:21

mostly you just need to convert the jsx into function calls: <Button x={y}>Click</Button> into React.createElement(Button, {x:y}, "Click") - the fulcro docs have a good overview of the issues - the same applies to any cljs lib using react: http://book.fulcrologic.com/#_using_javascript_react_components

kwladyka16:05:44

How to include this library into project? I guess I shouldn’t add ver. of mdbootstrap with react, because re-frame alread use react hmm. I am afraid doing this in ClojureScript will make more issues, than solutions. What do you think?

kwladyka16:05:25

Like ClojureScript with mdbootstrap vs Vue with mdboostrap or ClojureScript with something supported

dvingo16:05:30

I'd recommend using shadow-cljs which just adds a friendly layer on top of the clojurescript compiler - the key feature is it makes using npm packages really easy and simple - https://shadow-cljs.github.io/docs/UsersGuide.html#_using_npm_packages

kwladyka17:05:25

What with figwheel?

dvingo17:05:07

shadow-cljs has similar hot reloading features, so you'd use one or the other

dvingo17:05:07

as far as picking a tech stack - the answer is always "it depends". Learning anything new always takes longer than you think, (Hofstadter's law) so it depends how much time you have, vs using something you know.

kwladyka17:05:34

on the other hand it has some ready solutions for beautiful design

kwladyka17:05:03

it looks I will have to learn how to do it and try if it make sense

kwladyka17:05:27

still afraid issues > solutions while it is not supported

kwladyka21:05:56

I can’t run it. If anybody success let me know 🙂

Bravi23:05:56

hey everyone. I’m getting a circular dependency error and cannot figure out how to solve it. so I have routes.cljs

(:require [app.events :as events])

(defroute projects "/projects" []
  (re-frame/dispatch [::events/set-active-page {:page :projects}]))
and I have events.cljs
(:require [app.routes :as routes]) ;; importing the above file here

(re-frame/reg-event-db
 ::get-project-success
 (fn [db [_ {project :data}]]
   (-> db
       (assoc-in [:loading :project] false)
       (assoc :active-project project
              :page-title (:title project)
              :breadcrumb [{:label "Projects"
                            :path (routes/projects)} ;; and using it here
                           {:label (:title project)}]))))

theeternalpulse03:05:51

routes is referenceing events and events is requiring routes

valtteri04:05:07

Hitting circular dependencies is usually a smell. You may need to re-think how to organise your code. I’d start by figuring out what are all the things your event-handler is trying to achieve atm and whether it should be doing all that or not. I mean, should the handler know anything about routing of your app in first place?

nenadalm05:05:08

I have same issue with routes. I solved it by not requiring events in routes and typing the keyword like :app.events/set-active-page.

Bravi09:05:39

@theeternalpulse I know the problem 🙂 I wasn’t sure how to solve it. @U662GKS3F thanks, I’ll try that!

theeternalpulse09:05:40

yeah, sorry I missed the root problem