Fork me on GitHub
#clojurescript
<
2020-09-17
>
scythx01:09:28

Hello, this is noob question but i'm not that familiar with functional programming. Let's say we have Player (js-object) that has a bunch getter-setter (i.e., health, money, armour) which contains side effects. I have no privilege to modify the code of the object. How can i create a function that operate the object to be more pure? I have an idea to create a map that populated with the object values, and commit the changes after the function called, but that would be so expensive. Using a bunch operations of (.-health Player), (set! (.-money Player) 50) doesn't feels right either (some operation with js array really painful).

andy.fingerhut05:09:26

I'm not sure what you mean by "more pure" here.

andy.fingerhut05:09:30

If you want to completely avoid side effects on the Player js-object, then never modify its fields, and use your own immutable object to represent players instead, is one possibility, but perhaps that isn't a useful suggestion if this Player object is needed because of its side effects it performs on other objects in some library.

thanks 3
pithyless07:09:23

> some operation with js array really painful @U018TG9AG8L you may want to check out https://github.com/mfikes/cljs-bean - it won't make your code more "pure", but it could help you use more idiomatic clojure constructs without hurting performance as much as your idea of converting everything to ->clj and then ->js

❤️ 3
kimim12:09:23

Hello, I am writing a company human resource application, mainly grouping, filtering and charting data. Is there any good data cljs grid table library for this task? Thanks.

kennytilton22:09:10

Ah, that is on my do list! I am thinking easier to start with a good JS data grid such as agGrid. Did you check out https://github.com/Kah0ona/re-datagrid?

kimim22:09:52

thank you, I will have a try.

ian_sinn12:09:54

Does anyone recommend a particular http lib for cljs? I'm looking at https://github.com/r0man/cljs-http, but was initially hoping to find something that worked on the back end as well

ian_sinn13:09:10

Hm, seems like this might be what I'm looking for https://github.com/JulianBirch/cljs-ajax Still curious if anyone has other recommendations though

athomasoriginal17:09:35

I would likely start by looking into the NPM ecosystem e.g. Axios and then, if you really feel they aren’t covering your needs, you can look to the CLJS wrappers.

Oliver George21:09:17

You can get a long way with fetch

👍 3
scythx13:09:04

Hello, i use https://cljs.github.io/api/cljs.js/#eval-strbecausehttps://cljs.github.io/api/cljs.js/#eval-stri need to send code to remote machine and evaluate the code there. i can get it working for simple operation, but i can't use any library even though the remote machine have compiled code (*.js and stuffs) before using the eval-str. any idea?

nitaai14:09:10

Hi guys, I am just wondering and trying to find a way how to get the namespace name inside of a given namespace. In JVM clojure one can do (ns-name **ns**) . In CLJS **ns**is nil. I guess it has something to do how CLJS is compiled and executed in the JS runtime. Any idea?

darwin14:09:11

try to read *ns* via a macro, I believe you should be able to emit current ns name into cljs code

nitaai15:09:00

Trying this:

(defmacro ns-macro []
  `(ns-name ~*ns*))
but it doesn’t work.

darwin15:09:13

hmm, ~*ns* is definitely wrong, either look at *ns* or try (:ns &env) or look what is available in &env

darwin15:09:27

sorry, I don’t remember this from top of my head

nitaai15:09:42

(ns leihs.borrow.lib.helpers
  (:refer-clojure :exclude [ns-name]))

(defmacro ns-name []
  `(quote ~(:name (:ns &env)))))
thanks!

👍 3
Lone Ranger16:09:48

Wow! Great trick. That's annoyed me for awhile too!

kingcode15:09:36

Where can I find documentation for use of the cljs compiler, i.e. how to invoke it from the command-line? More specifically, I am trying to invoke clj --main cljs.main <args> where args would be either a build script or a .edn file. Right now I am looking at the cljs.cli/main.clj to try and make sense of it. Thanks!

darwin15:09:50

clj --main cljs.main --help?

kingcode15:09:49

Thanks @U08E3BBST - I had tried this previously, but forgot to use deps.edn 😞

kingcode15:09:54

still new to this new .edn config setup

Karol Wójcik15:09:51

What are some common ways to optimize transit output?

Lone Ranger16:09:06

Anyone have any recommendations for a ClojureScript (or JavaScript I guess...) uptime status tool similar to something like rollbar but opensource?

dpritchett17:09:02

Not familiar with rollbar. How exactly do you envision this integrating with your systems?

p-himik18:09:54

Rollbar just asks you to add a piece of JS to your web page that listens for the error events.

p-himik18:09:19

Oh, you probably meant the backend part.

Lone Ranger18:09:23

I just meant anything that will "check something to see if it's working and display a if it's not working"

Lone Ranger18:09:59

/some/endpoint ✔️ /some/other/endpoint ✔️ /endpoint/no/worky

Lone Ranger18:09:05

possibly with graphs 😛

p-himik18:09:13

It sounds like a web server monitoring and not a web app monitoring, so if you have access to that web server, something like Rollbar is not necessary at all since you can just detect API endpoint errors in code. Regarding graphs and monitoring in general - if you want to deploy something in your own infrastructure, Grafana is a commonly used solution. But there's no magic - you'd have to write something that actually collects the errors and sends them somewhere where Grafana can access them. Likely, something like this already exists - I just don't know about it.

p-himik18:09:10

Ah, of course - if you're using Nginx, it seems that Grafana can just read its logs: https://grafana.com/grafana/dashboards/5063

Lone Ranger18:09:44

ahhh yes sorry, this is actually for upstream sources we don't own but need to "audit"

p-himik18:09:55

If you have access to the logs, seems like Grafana should be able to handle that.

dpritchett19:09:36

Yeah I guess I was trying to figure out what website uptime monitoring had to do with clojurescript, like if you needed a cljs lib you could run inside an app that was doing some intelligent monitoring or health check responding of its own. I've used pingdom and a buncha other services for basic "is it up" monitoring 🤷

dpritchett19:09:23

Never used this but the dev behind it is pretty cool https://apex.sh/ping/

Lone Ranger21:09:59

We don't have access to the log. This would be a preemptive/proactive polling kind of situation 😕

Lone Ranger21:09:18

Apex Ping seems perfect -- except not opensource >.< my company isn't going to pay for that

dpritchett21:09:02

Really depends on where you fall on the "we need this to be very accurate and reliable" vs "we don't want this to be complicated" scale I guess

Lone Ranger21:09:03

def the later. Not a cljs tool but looks like a great tool!

Lone Ranger22:09:25

man, I cannot figure out how to use that checkup tool 😅

nodename18:09:40

Hi folks, can I create an npm package with clojurescript (shadow-cljs perhaps) that I can then import in a typescript project?

p-himik18:09:52

Yes. But there won't be any type information - it will be just plain old JS.

p-himik18:09:43

Huh, this documentation section is empty: https://shadow-cljs.github.io/docs/UsersGuide.html#_creating_code_npm_code_packages Perhaps because it's something that's subject to change. Maybe the next section is of some use. In any case, this is definitely a question for the #shadow-cljs channel.

nodename18:09:59

Thanks @U2FRKM4TW! I’ll ask there