Fork me on GitHub
#clojurescript
<
2019-01-22
>
john03:01:08

Hey y'all, gotta fresh toy here for ya: Kanaka's latest Mal over WASM, ported to ClojureScript and using tau.alpha for blocking reads, running in a browser REPL, producing a Mal REPL: Malhala https://github.com/johnmn3/malhala

5
heyarne10:01:54

i'm looking for a presentation of figwheel and reagent where you could follow along as tetris was implemented. does anybody have the link? i can't find it anymore šŸ˜•

borkdude10:01:21

yeah, that one is amazing

orestis10:01:43

Has anyone worked with Klipse as a library? I want to have some live-rendered snippets of reagent (as part of an interactive tutorial), but I want to call Klipse as a library from ClojureScript. Is this even possible?

borkdude10:01:01

if you find out, let me know, Iā€™ve been meaning try this too

orestis11:01:18

Itā€™s tricky, because Klipse needs self-hosted CLJS, but I want the tutorial to be able to seamlessly reuse whatever lies around in my project which is compiled by shadow. I might have to look into actually using filesā€¦

Roman Tsopin13:01:33

Just watched the talk ā€œfunctional programming in angerā€, where David said that now you could require any npm lib, and there is no need to write externs manually. Thatā€™s cool. But I canā€™t figure out how to actually do this. Can someone please provide an example? Should you use foreign-libs, npm-deps, infer-externs etc? Also it would be awesome to include this into get started tutorial.

Roman Tsopin13:01:01

Thanks, I actually read those, but couldnā€™t figure out how to apply them in my case (empty cljs project and leftpad installed from npm)

idiomancy13:01:15

lol, can someone help, I've been up for a thousand years. what's the best way to just get a pretty print formatted string in cljs

idiomancy13:01:05

so I have some json, I want to edit it in a textarea in my browser, and I want it to be pretty printed

borkdude13:01:13

(with-out-str (clojure.pprint/pprint the-thing))

borkdude13:01:41

oh json, you could convert it to clj first with js->clj

borkdude13:01:06

if you want to edit it as json, I donā€™t know. you could look for some existing react lib for it, or use codemirror, I donā€™t know

idiomancy13:01:37

still now what I'm going for

idiomancy13:01:25

doing the pprint thing seems to just be adding escape slashes

thheller14:01:52

@idiomancy if you just want pretty printed JSON and not EDN you can just use (js/JSON.stringify (clj->js {:some "data"}) nil 2)

idiomancy14:01:18

no i mean its already json

idiomancy14:01:37

but its like, I want it to look like this (I pasted it into an IDE and used the auto-reformat and pasted it back)

idiomancy14:01:46

but instead, it looks like this:

thheller14:01:48

(js/JSON.stringify the-json-obj nil 2)

šŸ’Æ 15
idiomancy14:01:24

look at that!

manutter5114:01:37

I never knew you could pass additional args to stringify to control the formatting

idiomancy14:01:40

the magic words

roklenarcic16:01:52

How do you require namespaces in cljs REPL? I tried (require '[my.namespace :as x]), but x/.... doesn't work.

borkdude16:01:19

should work

borkdude16:01:01

have you changed anything after the first load? then you could try: (require '[my.namespace :as x] :reload)

lwhorton16:01:07

so hereā€™s a good one: how do you convince someone who doesnā€™t know what they donā€™t know (and is convinced theyā€™re right) to look into clojurescript when ā€œnah man i dont like abstractions over raw jsā€ is their line of thinking? react/redux ā€œis the best thingā€ and re-frame is just silliness.

lilactown16:01:34

what do they value?

lilactown16:01:10

for example, I came from the react/redux world into Clojure(Script) because I was exploring things that were already being talked about by the people I respected in those communities: - immutability - hot reloading - new syntax

lilactown16:01:58

when I started trying out Clojure, it was because I had tried and struggled with those 3 things and had heard that Clojure(Script) had them all by default šŸ™‚

lilactown16:01:17

essentially it was easy to do the things I valued + had found hard

lilactown16:01:14

but those values didnā€™t come from Clojureā€¦ I already had them from listening to Dan Abramov, Jordan Walke, etc.

lwhorton16:01:57

well, presumably immutability because they keep the mental overhead of using {... spread, a: 1} syntax everywhere. or they use immer/immutablejs. they have a lot to setup to get hot reloading, but admittedly you usually only have to do that once. itā€™s like im missing a piece to make it ā€œclickā€.

lwhorton16:01:50

for them things like javascripts object equality by reference instead of value isnā€™t a problem šŸ˜ž

lilactown16:01:33

I mean, for most people it isnā€™t. you might think it is, but to them youā€™re just inventing problems šŸ˜›

lol 5
lilactown16:01:25

maybe if you related that to componentDidUpdate and having to use immer/immutablejs. I canā€™t imagine someone using immutablejs in anger and not wanting to burn their project to the ground.

lilactown16:01:48

it sounds like this person is happy. are you trying to convince them for some reason?

lwhorton02:01:20

yes, i want to use cljs + reframe when we have to build SPAs (not often, but often enough). the react/redux stack very often seems like pouring concrete and i know thereā€™s better ways šŸ˜ž

lilactown05:01:03

would you and he be developing together?

lwhorton16:01:51

its a consultancy, so occasionally but not all the time. unfortunately we try to standardize on a stack for new projects. if thereā€™s not agreement i think weā€™re going to default to some js framework simply because itā€™s least far from the familiar

lilactown17:01:34

well, maybe yaā€™ll could use it once for an experiment

orestis18:01:36

Iā€™ve been through this recently @lwhorton. I think itā€™s impossible, because the things ClojureScript brings to the table manifest over a longer period of time, and they also require a considerable up-front investment. So people who feel productive in their local maximum are reluctant to change.

lwhorton02:01:40

thatā€™s really depressing but i donā€™t disagree

orestis18:01:06

One argument I had is that Clojure incorporates into the language many concepts that in JS you need to have a framework for. E.g. the succession model with atoms that can replace redux entirely. Also a standard library.

orestis18:01:45

In the end, it feels like youā€™re in a Monty Python sketch arguing about what the romans ever did for us.

šŸ˜€ 5
ā˜ļø 5
Braden Shepherdson18:01:24

one tactic I've used with a bit of success in that argument is to rebuild something - and not just a prototype, but a full reimplementation of some part of the app, real data and all - and then show (1) how much smaller and simpler the code is, and (2) how much more quickly I wrote it. the conclusions are either that these proposed tools are more powerful and allow us to do more with less code in less time, or that I'm way smarter and more productive than whoever wrote the original code, which seems unlikely.

Braden Shepherdson18:01:00

both arguments fall apart if there's even one footnote on the reimplementation; it needs to be real.

Braden Shepherdson18:01:25

because if there's even one tiny crack, it will become the explanation for everything, rather than the language.

āž• 10
Braden Shepherdson18:01:11

(even if it's completely impossible for the tiny crack to cause the four-fold code size reduction, etc. etc. you can probably hear how many frustrating and circular arguments we had about this.)

Braden Shepherdson18:01:52

(caveat, for honesty: I failed to ultimately persuade my team. there was an irredeemable "crack": Javascript is an officially supported language inside Google, and ClojureScript is not. never mind that both go through the Closure compiler and ultimately result in Javascript code for the user's browser to run.)

lwhorton02:01:11

i actually did a complete rewrite of an existing clientā€™s SPA. it was verbatim a copy-paste at 4.8x less code and it took me a week vs. 2 months. šŸ˜ž

lwhorton02:01:21

iā€™m sorry yours didnā€™t work out either

Braden Shepherdson17:01:30

I know that feeling. there's a bottomless well of frustrating counterarguments people use. "oh, we can use this library and reduce our code size by 20%." "yes, but I'm talking about a five-fold reduction in code size."

Braden Shepherdson17:01:14

I'm pitching a drop-in replacement thing at work right now unrelated to Clojure, it shrinks a block of generated JS by 20x, from 1.1MB to 70KB.

Braden Shepherdson17:01:55

my detractors propose changing the generation options to reduce the size by ~30%, and having to change all the call sites.

Braden Shepherdson18:01:16

but I had converts, which is something.

tim19:01:29

@lwhorton I typically express shock along with a disingenuous attempt at empathy for those using raw js. OMG you actually live without core.async?

lwhorton02:01:19

i feel similarly. itā€™s hard not to be disingenuous, and sadly that makes us lispers often look pretty arrogant (i think). if youā€™re on the outside looking in, you donā€™t know what you donā€™t know.

tim13:01:40

> makes us lispers often look pretty arrogantā€¦ true, but Iā€™m suggesting a response to arrogance + I tend to smile šŸ™‚ itā€™s hard to be arrogant (at least for me) when you smile

mrchance19:01:28

Hi, I'm trying to compute a d3 pack layout from some cljs data. It works quite well, but when I convert the result back with js->clj, I just get #object[Node [object Object]]... Any idea how to turn that into useful data again, or do I have to recurse through it myself?

mrchance00:01:12

Ended up recursing through it myself feelsgood

mrchance20:01:04

json.stringify works on it, after I removed the parent field from it, which otherwise makes it circular -.-

souenzzo20:01:12

define multimethods in runtime is a bad thing to cljs? example

(defmulti foo ...)
(defn main []
  (defmethod foo ... ))

dnolen20:01:43

@souenzzo any kind of runtime usage of def is discouraged

dnolen20:01:03

we certainly don't check for problems you might encounter doing that and don't have plans to

dnolen20:01:55

the one exception here is wrapping defs in some kind of conditional feature detection

dnolen20:01:59

but that's not def in def

thheller20:01:30

defmethod is just sugar over (-add-method foo :val (fn [...] ...)) so you could use that directly instead too. defmethod doesn't actually def anything so I'd say its fine.

thheller20:01:20

but imho its probably a code smell if you do that because you need access to extra state in the function definition. something that should probably be passed as an arg

dnolen20:01:08

well I would argue the problem here is unmanaged manipulation of global state - def and defmethod both do that - so I'd still argue probably not fine šŸ™‚

dnolen20:01:19

unless you're doing something special that really calls for it anyway - I would avoid the pattern

jaide21:01:57

Is there any guides on using ClojureScriptā€™s browser events API? I found wrappers https://github.com/clojure/clojurescript/blob/master/src/main/cljs/clojure/browser/event.cljs but havenā€™t been able to locate any API docs

dnolen21:01:41

@jayzawrotny that ns exist primarily for historical reasons

dnolen21:01:55

just use Closure Library directly, goog.events etc.

jaide21:01:15

Ah ok, thanks!