Fork me on GitHub
#clojurescript
<
2024-01-05
>
Stef Coetzee10:01:25

Not getting clarity while running WWRD (What would Rich do?) regarding the use of Google Closure Library in new CLJS projects. Is it prudent, given that it's transitioned into maintenance mode? If not, are there recommended alternatives? https://clojurians.slack.com/archives/C07UQ678E/p1698353101153739

p-himik10:01:30

If the functionality you need from the library works, it'll continue to work just fine. With that being said, a lot from that library is either not needed with modern browsers or a bit questionable (like the UI stuff).

Stef Coetzee10:01:54

Thanks! I'm interested in goog.net.Cookies in particular, after seeing its use in https://github.com/reagent-project/reagent-utils/blob/master/src/reagent/cookies.cljs as part of https://github.com/reagent-project/reagent-utils. Do you consider goog.net.Cookies unnecessary or questionable in the context of modern browsers?

p-himik11:01:31

It's alright. Not necessary but convenient and not questionable.

🙏 1
Chris McCormick15:01:00

This one from npm will probably do the job: https://www.npmjs.com/package/js-cookie

🙏 1
lwhorton17:01:51

i found some of the most particularly useful goog.* to be around the stateful session-related stuff in the browser. they have really good activity tracking [of course they do, it's google] and expose very reliable interfaces for things like: "if the user hasnt been active in 5m, do a thing". because browsers bend over backwards to maintain existing compatibility, i think you'll be fine using it for a long while.

🙏 1
hifumi12319:01:31

GCL is relatively stable, and most of its usage in your code is likely from third party CLJS libraries wrapping around it. If you fear the library having unfixed bugs or security bugs, then I recommend ditching those wrapper libraries and using the JS standard library, which likely has what you want. e.g. goog.crypt.base64 is unnecessary nowadays and likely slower than simply using btoa and atob similarly, goog.crypt.stringToByteArray and related functions can be replaced with TextEncoder and TextDecoder from the JS standard library goog.net.XhrIo isnt really needed unless you have a hard requirement of supporting XHR quirks in ancient browsers like Internet Explorer 8. so on, so forth

🙏 1
fvides13:01:24

Hello everybody. I'm fairly new to ClojureScript (not so much with Clojure), so please be patient. I'm currently playing with core.async and I've found a behaviour that is baffling me:

c.user> (require '[clojure.core.async :refer [<!! go]])
nil
c.user> (def c (go (/ 4 3)))
#'cljs.user/c
c.user> c
#object[cljs.core.async.impl.channels.ManyToManyChannel]
c.user> (<!! c)

Execution error (TypeError) at (<cljs repl>:1).
Cannot read properties of undefined (reading 'call')
:repl/exception!
This exact same code works in Clojure. Could anybody give a hint about what I'm doing wrong? Thanks in advance!

p-himik13:01:22

JS is non-blocking, so <!! cannot be implemented there. Also, unless you really need to manage communicating processes, there's little reason to use core.async with CLJS. There are more downsides than upsides.

fvides13:01:45

Thanks a lot for your answer. I'm currently studying an example app which uses core.async. But then, how is one supposed to read a channel outside a go block? Can it be done?

p-himik14:01:28

Or rather, it can be, but you have to pass a callback.

p-himik14:01:45

So you can't use in a way that would make it seem as if it were a return value.

fvides14:01:33

Ok, I'll try that. Again, thanks.

lwhorton17:01:28

so this is probably the wrong place to ask, but does anyone know of any prismatic/schema, spec, or malli-like lib that's implemented in native js? i've looked at options like zod, yup, joi, and typebox. im not overly impressed with any of them. i think ajv is probably the most data oriented, but it's coupled tightly to the jsonschema spec. i ask because i'm currently unable to sneak clj/cljs into the tech stack, but i still want to build a resilient system in the meantime. i'd love some advice if anyone knows of particularly useful tools in js-land.

valtteri17:01:27

I explored this a few years ago and at least back then json-schema + ajv was the closest.

valtteri17:01:32

I guess the trend is to lean on Typescript typings in js-land and there’s not that much push for data driven schemas

lwhorton17:01:46

there seems to be a whole lot of options, but ajv is the only thing i've found that uses data literals for some reason. every other tool is really invested in().the().builder().pattern() which seems really hard to compose and build other tooling around

lwhorton17:01:10

ah, yes. typescript might be the reason behind that ...

valtteri17:01:11

Some convincing might be needed to make others write schemas instead of TS types. 🙂 You can generate TS type declarations from json-schema though

valtteri17:01:57

One point for data driven schemas is that if you have a highly dynamic system and it would be good to be able to construct or modify schemas dynamically. With types you end up with a generics-nightmare if you try to achieve that.

valtteri17:01:42

Schemas can be transported over the wire, stored into a db etc..

lwhorton17:01:12

i agree. we're in the fortunate(?) position of not relying on TS right now. i'm trying to slowly introduce the team to some opt-in data-driven specifications. from the little bit of exploration i've done, i think i might be forced to use ajv just to maintain the data-first properties we're talking about

👍 1
valtteri17:01:39

Ajv is not that bad IME 🙂

valtteri17:01:57

Of course the dev-experience is subpar to what you’re used to with schema/malli + the REPL

lwhorton17:01:12

it's so strange how seemingly noone else thought a data literal based spec tool was worth it. they jumped right into stateful javascript functions/prototype/class constructs. and yea, i'm already feeling the pain of no more repl. it's kind of like one hand tied behind my back 😕

lwhorton17:01:51

i kind of wonder if protobufs might get me there ... at least it's data oriented.

valtteri17:01:30

I tried mimicking repl-driven development with node-js repl but it was not great. Fine for small experiments though… as long as you remember to erase all const definitions before sending to repl 😄

valtteri17:01:48

Depends what you’re building but if it’s anything “high-level” I recommend json-schema over protobuf

lwhorton17:01:22

thanks for the consultation session, i appreciate your time blob_thumbs_up

valtteri17:01:50

No problem, I’m happy if this was helpful. Good luck! 🙂

Nundrum23:01:55

CORS question time! 🎉 I was practicing CLJS by way of putting together a custom "new page page." Hoping I could just drop it as static files and use file:// for access. That seems to work for referencing the css and js files, but my script I try to fetch a list of URLs and icons so the page can be a bit configurable. But I ran into CORS request not HTTP. Is there some more clever way to achieve this without putting the files on an http sever? Something I'm not thinking of?

thheller23:01:08

browsers restrict direct file access for security reasons, so no it requires http for good reasons

Nundrum23:01:33

Sure. But is there some way to make the url/icon config available in some other way? Include a link the the HTML?

thheller23:01:01

I don't know what you mean by "url/icon config"

Nundrum23:01:14

It's a list of URLs and icons to show in the page for quick links. Right now it's an edn file. I left it in a separate file so it would be easy to update the list as needed.

Nundrum23:01:35

If I put them in the cljs source, that works, but means rebuilding and deploying if the list changes.

thheller23:01:03

well you could make it a JS file I guess

thheller23:01:41

accessing random files is not possible via JS, at least as far as I know

Nundrum23:01:23

hmmm include it as JS and then reference the object it creates

Nundrum23:01:35

I'll play with that

Nundrum00:01:18

Thanks a bundle. That worked great, and it wasn't obvious to me.

👍 1