Fork me on GitHub
#clojurescript
<
2018-08-28
>
danielglauser00:08:02

With Leiningen is there a place you can put a user.cljs file with functions that will get automatically loaded when you start the repl?

dnolen00:08:56

It works like Clojure if you’re using the standard REPL, probably others too

dnolen00:08:27

@jeaye where was it ending up without that?

prabhath603:08:02

Hi, I have asked the same question in #beginners yesterday. I was told check here. I am trying to copy content to clipboard when a list item is clicked. I found a solution in javascript, which i tried to convert to clojurescript and failed.

var copyText = document.getElementById("myInput");
 
   /* Select the text field */
   copyText.select();

   /* Copy the text inside the text field */
   document.execCommand("Copy");
when i try to do something similar in clojurescipt it fails
app:emoji-search-clojurescript.core=> (.getElementById js/document "emoji-title-100")
#object[HTMLParagraphElement [object HTMLParagraphElement]]

app:emoji-search-clojurescript.core=> (.select (.getElementById js/document "emoji-title-100"))
#object[TypeError TypeError: document.getElementById(...).select is not a function]
How do i select the value and then copy it to clipboard.

prabhath604:08:35

Any help related to this is appreciated.

ghiden04:08:18

i don't think you are getting the right element. #object[HTMLParagraphElement [object HTMLParagraphElement]]

ghiden04:08:48

it should return #object[HTMLInputElement [object HTMLInputElement]]

prabhath604:08:50

I was using that javascript solution as an example. I do not have an input element, i am trying to copy a paragraph element on click.

girish04:08:32

you should first try to execute js on your html in console may be

ghiden04:08:46

select is for textarea and text

👍 4
prabhath604:08:36

i hacked a textarea and then added it to the body and it worked.

prabhath604:08:06

thanks, i think i understood what the issue is now.

jeaye05:08:11

@dnolen Without those lines, the bundle is generated, with all the right code, but it's not exported or assigned or made available in any way. The libraryType is essential for specifying that; it defaults to "var", meaning it uses the library value to generate var foo = { ... }; (assuming library: "foo"). In this case, without the library value, no var is generated. For CommonJS requires in a way which generates exports["UI"] = { ...}, I set the values shown in the paste.

thheller07:08:54

@jeaye it looks to me like you are missing the window.React = React; equivalents? ie. you are supposed to manually ensure the variables created instead of having the index export them. libraryType may however be useful. https://clojurescript.org/guides/webpack#javascript-dependencies

kwladyka10:08:15

Do you prefer to use (-> w3 .-eth .-accounts) or w3.eth.accounts? Why?

kwladyka10:08:39

There is lack of clojurescript style guide

Saikyun10:08:56

@kwladyka I personally like (.. w3 eth accounts)

Saikyun10:08:48

I didn't know you could do w3.eth.accounts though

danielstockton10:08:22

Is async/merge + go-loop the accepted idiom for firing a bunch of cljs-http requests and collecting their results all at once?

pesterhazy11:08:19

@danielstockton my opinion: 10x simpler to use js/fetch & js/Promise.all

pesterhazy11:08:23

what you mention sounds like too many layers to me: core.async wraps cljs-http wraps goog.xhrio wraps XMLHTTPReqeust

pesterhazy11:08:04

plus js/fetch is the better api — again, in my opinion

danielstockton11:08:05

cljs-http handles transit transparently though.

pesterhazy11:08:48

(-> (js/fetch url) (.then #(.text %)) (.then #(transit/read %)))

danielstockton11:08:23

Yeah, fairly nice. I guess I can create my own wrapper around fetch easily enough.

danielstockton11:08:35

That doesn't tie me to core.async

pesterhazy11:08:51

Yeah. Embrace the host. The host loves promises and fetch

👍 4
pesterhazy11:08:47

@danielstockton today I published a demo SPA based on the "embrace the host" principle: https://github.com/pesterhazy/cljs-spa-example - feel free to take a look

Mario C.15:08:16

Is there a reasoning why Hiccup and Hiccup inspired libraries decided to use vectors to represent HTML instead of maps?

pesterhazy15:08:16

Tagged vector:

[:div {:display :block} [:span "hi"]}
The alternative would be:
{:tag :div, :attrs {:display :block}, :children [{:tag :span, :content "hi"}]}

pesterhazy15:08:30

Which alternative do you prefer?

🙂 8
Mario C.15:08:24

Fair enough, I see your point

martinklepsch16:08:12

I noticed that the arglists in this code seem to be of type clojure.lang.Cons in contrast to the usual list that defn constructs. Is this expected? Maybe the way the arglists metadata is constructed is wrong?

~(with-meta fname {:doc doc-string :added (:added validator-meta-data) :arglists `'(~args)})

thiru16:08:43

Is anyone building a React/reagent based website that's not a SPA? I've been holding off on jumping on the SPA bandwagon because I felt it introduces a lot of complexity (local routing, etc.) that's maybe not worth the benefits.. But maybe I haven't take a close enough look. Is it crazy to build a reagent website that's not a SPA?

isak17:08:38

@thiru0130 that can be completely reasonable if it is complex enough. Though for simple needs, you can just use javascript, and avoid the complexity of needing compilation

thiru17:08:25

Hmm I still want to use ClojureScript rather than Javascript. Most of the websites I build don't need a huge amount of rich interactivity on the client-side. The different pages/routes are often quite distinct in the functionality they provide and they usually only have the page header/footer in common!

thiru17:08:29

Some pages do have a fair bit of dom manipulation though and it's definitely not easy/fun to do this with vanilla JS. I'd love to use reagent for these cases.

thiru17:08:49

So I'd like to use a traditional client/server architecture and just use React whenever I need some DOM manipulation. Are there any big drawbacks to this approach?

dnolen17:08:29

@martinklepsch why would that make any real difference?

martinklepsch19:08:21

Some of codox‘ analysis code used a list? predicate. changed that to seq? and stuff is working fine. I guess I was just confused why the macro I linked creates a Cons cell, regardless of whether that should make a difference

dnolen17:08:39

@jeaye it seems maybe you’re just skipping over what the ClojureScript Webpack guide recommends?

dnolen17:08:59

which is just exporting manually via window - I don’t really see what all this config via Webpack is doing for you

dnolen17:08:05

it doesn’t seem meaningful at all

dnolen17:08:39

(but I’m also not a Webpack guru, and I’m happy to be enlightened :)

dnolen17:08:43

@thiru0130 that’s a pretty popular usecase - go for it 🙂

pesterhazy17:08:25

@jeaye if you're stuck on configuration, check out this demo app for an example of how to pull in NPM deps via webpack: https://github.com/pesterhazy/cljs-spa-example

👍 4
ghiden20:08:20

just curious why you use shell script, not boot or lein?

pesterhazy21:08:35

@U0E1YG9M1 it's faster and clearer

ghiden22:08:03

just inherited a big cljs project with 1k lines of boot code and got confused why boot is so complex.

ghiden22:08:17

i just want to know opinions from experts. do you prefer boot, lein, or just shell scripts?

thiru17:08:18

Ahh ok cool! I don't see this approach talked about much in blogs, etc. I figured it was almost taboo. Thanks @dnolen, @isak

dnolen17:08:45

that’s how React got popular in the first place

dnolen17:08:55

you could use it tactically

thiru17:08:18

ah yes exactly

jeaye18:08:24

@pesterhazy Thanks. I did figure it out yesterday, I just needed those two extra config options.

jeaye18:08:59

@dnolen I'm following what webpack recommends, in that case, from https://webpack.js.org/guides/getting-started/ Since I'm also transforming with babel, I need the config for the loader. I also don't care about minification, since Closure does all of that when it needs to. The rest of the config is stock.

dnolen18:08:54

I think maybe you’re missing what I’m saying

dnolen18:08:04

Webpack doesn’t care about export to window

dnolen18:08:40

I don’t see what Webpack recommends interacts with that?

dnolen18:08:48

(what I’m trying to tease out here is why we should change our documentation)

pesterhazy18:08:16

@jeaye for the record I don't use those two options, libraryTarget and library, and it works fine

jeaye18:08:40

You must be exporting via window then, as David pointed out?

dnolen18:08:01

like I said - I just want to hear some rationale about why we should change our documentation

pesterhazy18:08:07

I don't see a lot of downsides to that style of doing things

jeaye18:08:28

@dnolen I see your reasoning for the window approach now; as I mentioned in my original question, I'm not very familiar with the JS ecosystem, so this has been an exploration. However, based on comparing the two docs (CLJS and Webpack), I did things the Webpack way, since I'm using Webpack. That is, the way the Webpack home page and getting started and other docs and articles around Webpack suggest. None of them went through window, but it appears to work well for this case as well. I wouldn't be able to say which is objectively better.

jeaye18:08:12

@dnolen With the understanding I have now, I do redact that the CLJS docs need to be changed, since I see how the window approach is working. It's worth pointing out, however, that it veers from what seems to be the more idiomatic Webpack approach.

dnolen18:08:28

It doesn’t actually veer

dnolen18:08:34

since the Webpack approach cannot even generally work

dnolen18:08:54

you’ll often want to shape the export so you get a sensible looking ClojureScript namespace structure

dnolen18:08:26

but yes, nothing wrong with dropping a note about how this is different from what you might infer from Webpack docs

jeaye18:08:03

I've very narrow goggles, in this environment. Sorry for any confusion! 🙂

dnolen18:08:33

the problem is that you have two mostly incompatible module systems

dnolen18:08:47

going the Webpack way isn’t buying you anything since you’re writing ClojureScript

dnolen18:08:52

but again the docs can be clearer here for those that might be looking at Webpack docs

dnolen18:08:13

We haven’t got this specific feedback before though - probably because people who use Webpack enough know it’s kind of a documentation nightmare

pesterhazy18:08:44

I remember puzzling over webpack's library config option when I started out as well

jeaye18:08:17

People in this situation probably have more experience in the JS ecosystem, so they know what to look out for. I'm more a Clojurist who happens to be in the web world, for this project, and tries to avoid that aspect of things whenever possible. Having higher level documentation on "Doing this JS thing with ClojureScript" which uses Webpack would help; I can cook up a blog post on my findings, for those who're trying to accomplish a similar task without knowing exactly which tools to use.

jeaye18:08:40

In this case, using ClojureScript + re-frame with https://pagedraw.io/ -- which is awesome.

dnolen18:08:57

that’s interesting, haven’t heard of that one before

bhauman19:08:03

but wanted to make sure

jeaye20:08:07

Yup, thanks!

bhauman20:08:40

hmmm I’m needing some design advice for figwheel.main