Fork me on GitHub
#clojurescript
<
2016-02-05
>
crocket07:02:40

There's now hope for creating libraries for nodejs in clojurescript. Check out https://github.com/crocket/cljs-npm-template

crocket07:02:55

If you want to publish your npm library in clojurescript, you might want to publish it to clojars. Clojurescript npm libraries can be imported from clojars without the issue of multiple clojurescript runtimes.

meow07:02:26

Very nice. :thumbsup:

braai engineer12:02:17

Any way to use an URL route prefix with bidi? I.e. /#/my-route instead of /my-route.

jaen12:02:09

Do you by # mean the hash fragment?

jaen12:02:48

I use bidi, am satisfied. Though I heard silk is nice, just didn't have any chance to try it out so far.

jaen12:02:25

Maybe a bit of a downside to bidi is slightly unreadable route definitions at times. I quite often tend to miscount the parens I need.

jaen12:02:13

Also as I mentioned on boot, hash-fragment is something you should handle before reaching bidi IMO. Use the hashchange event and then dispatch to bidi.

pandeiro13:02:29

@jaen Do you use hashchange as a substitute to the goog.history machinery, or in addition to?

jaen13:02:33

Hah, no, I use HTML5 history API; but since the question was about # it's what I suggested.

pandeiro13:02:03

ah ok, gotcha thanks

martinklepsch14:02:44

can someone tell what's broken with this regex #"application\/vnd\..+\+json"?

jaen14:02:43

And what's the behaviour you didn't expect?

jaen14:02:25

@martinklepsch: "application/vnd.test+json".match(new RegExp("application/vnd\..+\\+json")) seems to work if that helps; I guess Clojurescript reader interprets \+ as a string escape and resulting string is invalid?

jaen14:02:25

I also think \/ is not needed unless you use a regex literal like in Javascript or Ruby. That is unless Clojurescript's regex literals compile to them, but I assume they compile to new RegExp(...)

martinklepsch14:02:13

@jaen: sorry, that was a bit of a brief problem statement

martinklepsch14:02:30

(re-find #"application/vnd\..+\\+json" "application/vnd.test+json") — I'd expect this to match but instead it returns nil

joost-diepenmaat14:02:02

(re-find #"application/vnd\..+\+json" "application/vnd.test+json")

joost-diepenmaat14:02:02

instead of (re-find #"application/vnd\..+\\+json" "application/vnd.test+json")

martinklepsch14:02:21

huh, now I'm confused

martinklepsch14:02:47

I thought I've tried a single slash but apparently not with that version — fixed it, thanks! @joost-diepenmaat

joost-diepenmaat14:02:03

you’re welcome

joost-diepenmaat14:02:55

you should only need double backslash for escaping backslashes in regex literals

joost-diepenmaat14:02:05

so for matching literal backslashes

jaen14:02:23

Oh, so Clojurescript escapes those slashes for us then?

joost-diepenmaat14:02:35

yeah that’s what the #”…” syntax is for

joost-diepenmaat14:02:17

otherwise you have to first escape backslashes in a string literal and then again for the Regex constructor

jaen14:02:02

Hmm, so what about if I wanted to match on \n?

joost-diepenmaat14:02:17

#”\n” should work for that

joost-diepenmaat14:02:02

IIRC \n is interpreted as a literal newline character in strings and in regexes

jaen14:02:22

Oh, so it's smart enough to know what's string escape and what it can ignore?

jaen14:02:34

I thought it might have broken because it interpreted \+ as an escape.

joost-diepenmaat14:02:18

yes it’s smart enough to do it correctly. as long as you don’t think about it too much it works simple_smile

joost-diepenmaat14:02:41

(java.util.regex.Pattern/compile "\\\\") #"\\"

joost-diepenmaat14:02:01

AFAIK there are only a few special escapes in string literals; \\ \n \r and a couple more. Those all work in regex literals as is. The other special backslash escapes for regexes can also be used directly in #”” syntax.

joost-diepenmaat14:02:46

In JVM clojure things like “\+” are invalid in a string literal, and only work in #”…” syntax

jaen14:02:21

That makes sense, I suppose; didn't have to write much regexes in Clojure so far, so didn't know all the details

jaen14:02:02

Was kind of assuming it from how JS's regex behaved (and it didn't like \+)

meow15:02:45

Tomek, do you have like a photographic memory or something? You're like an encyclopedia of programming knowledge. Or a set of encyclopedias. Seriously. Damn. simple_smile

jaen15:02:07

Don't exaggerate : V

mull15:02:49

I don’t know if there’s a Clojure equivalent, but AFAIK regexes in Clojure/ClojureScript are quite similar right? If so, http://rubular.com is a nice tool to use while building regexes. I use it to build JS matchers as well. Thought I’d drop this in simple_smile

jaen15:02:41

@mull: It's pretty cool, but Ruby's expression are PCRE, so they are strictly more powerful so it's something to keep in mind.

jaen15:02:57

What Javascript lacks, for example, is named groups which are terribly useful.

jaen15:02:05

Java8 added them I think, but IIRC Clojure has no support for them in re-find (that is, you get just a vector, not a map.

mull15:02:07

True, I guess I never considered it. I rarely write anything else than the most simple of patterns

mull15:02:27

(thankfully!)

jaen15:02:49

Also, while we're at it, https://www.debuggex.com/ and https://regex101.com/ are also very useful websites when writing regexes.

jaen15:02:25

And yeah, I agree regexes shouldn't be too complex if possible. The RFC-compliant email regex is an abomination for example.

jaen15:02:56

I love how Haskell guys decided to do that with PEGs instead - https://hackage.haskell.org/package/email-validate

nha16:02:12

@jaen we have something quite similar with instaparse, although this particular lib won't work in clojurescript. Ex. for e-mails : https://github.com/sfx/schema-contrib/blob/master/resources/email.abnf

jaen16:02:00

@nha: oh, nice someone took the right idea. Also, I think I've seen instaparse-cljs somewhere. Not sure if it could deal with this grammar though.

jaen16:02:40

But I usually just do it login + at sign + at least tld style rather than 100% conforming to the RFC.

nha16:02:06

Right. The only way to know if the mail is valid is to send a mail.

jaen16:02:12

Yep, that's probably the smartest move anyway. I think for example that not all gmail logins are RFC-valid for example (you can do .. in the login which is RFC noncompliant, but gmail ignores dots in the login).

nha16:02:42

Oh I did not know that. I use <mailto:[email protected]|[email protected]> quite often, and I am not even sure it is valid, or if some validations in the wild validate only a subset of valid mails.

jaen16:02:48

Oh, pluses are valid, as is this #!$%&'*+-/=?^_{}|[email protected]` for example, but double dot for some reason is not.

jaen16:02:12

Hah, even slack doesn't buy it ; d

jaen16:02:08

But yeah, websites validating mails or RL addresses that are valid because they work is vexing; so it's probably best to not get too overboard on that. At best just issue a warning or something.

jaen16:02:45

@nha: if you're interested in some examples of valid/not valid here are some test cases from an RFC-compliant validator - http://isemail.info/_system/is_email/test/?all

nha16:02:56

Some of those would be perfect for a quizz ^^

nha16:02:28

Here is what I use (re-find #"^[^@]+@[^@\\.]+[\\.].+" e) but I certainly did not write it. Until recently I was just checking that there was an @.

jaen16:02:05

Yeah, basically what I use as well; though if one day someone with an email in a TLD would want to register, they would be surprised xD

nha17:02:40

Aha right (>_<)

josh.freckleton21:02:44

What are the top recommendations for cljs UI libraries? I'm using react, reagent, reframe, and I've had a nightmare trying to get cljsjs's react-bootstrap and react-mdl working...

cjmurphy22:02:05

My thinking is a good way to avoid nightmares is to go with libraries that don't use js - where all the code is in cljs. re-com and reforms are examples. re-com uses Bootstrap css and the rest is written in cljs I believe.

richiardiandrea22:02:26

yes re-com is cool I have used it for http://clojurescript.io 😉

cjmurphy22:02:37

Also these libraries are just code. You can learn from them.

josh.freckleton22:02:35

@cjmurphy: If I go the cljs route, does that mean I really shouldn't plan on js interop?

cjmurphy22:02:11

That's a hard question. More experienced people here. It is the wrong time for lots of activity. Weekend and most asleep.

josh.freckleton22:02:13

oh geez, you're chris from http://stackoverflow.com/questions/35232945/in-clojurescript-how-do-i-properly-use-cljsjs-react-mdl, thanks so much for being my guide in all this! I feel converted to clojure, just a bit overwhelemed with learning the whole new ecosystem! It's cool to know there's a clojure support group simple_smile

cjmurphy22:02:51

But you can combine all things. Say if you really wanted a js date picker (there's one in re-com by the way) you could use it via Interop.

jaen22:02:38

@josh.freckleton: well, it's not that hard to combine Clojurescript and Javascript. For example take a look at this gist - https://gist.github.com/jaen/7123aa5f7e15dccbed28 - it combines reagent with Semantic UI's dropdown.

cjmurphy22:02:06

Yes you will get plenty of help here, especially for particular problems. Big issues and general questions about 'what is the best' can be tough. As you know at the moment I'm going with Semantic UI. Great - Jaen's here!

josh.freckleton22:02:04

@jaen: thanks jaen. CJMurphy had just made a couple recommendations over bootstrap/`material` for getting UI components into a react/cljs app, have you been having pretty good experiences with Semantic UI? Any other suggestions?

jaen22:02:49

Right now I've used only the dropdown, but it was pretty painless. You can look at links in this issue - https://github.com/gadfly361/soda-ash/issues/1#issuecomment-174381692 - for more context.

jaen22:02:14

Semantic UI components seem to be written in a way, that makes integration with React relatively simple.

jaen22:02:40

And visually it also looks pretty nice to boot.

cjmurphy22:02:31

I tried to do a tabbed pane kind of thing with MDL and it was tough to do - all kinds of unnecessary code - compared to same thing with Semantic UI - so I went back.

cjmurphy22:02:04

I was having to write lots of HTML that relied on ids being correct etc.

jaen22:02:59

If you want material look&feel specifically then this seems pretty kewl - http://www.material-ui.com/#/

jaen22:02:18

It's already React to boot.

jaen22:02:04

It would be pretty tough to integrate with Clojurescript (it's CommonJS modules) but someone already did the hard work - there are both om and reagent compatible libraries for it.

jaen22:02:58

(by pretty tough I mean: using webpack/browserify as an additional build step to compile the modules out; it's not hard per se, just vexing)

cjmurphy22:02:31

Actually this is the exact reference I used:

jaen22:02:00

Ah, so they're different

jaen22:02:11

The one I linked is React components, so it should be considerably easier.

cjmurphy22:02:15

Just I couldn't read the examples so easily. Although now I like your one better - at least you don't have to do two sets of tabs and tie them together - which was my main problem.

cjmurphy22:02:30

And nothing yet for Om Next.

richiardiandrea22:02:47

@jaen the integration of Semantic UI and reagent is straightforward, I wonder if these components can be contributed to soda-ash (I have been pondering this in the last two days for a project of main, choose Semantic UI instead of re-com and contribute components back)

jaen22:02:55

Yeah, it is, at least from what I can tell. Liked I mentioned they seem to have paid some attention to integration with React.

jaen23:02:08

So a first pass on those components could be just wrapping of existing jQuery components

jaen23:02:21

And then at some later point, reimplementation of them in Clojurescript. Or something.

jaen23:02:40

This is certainly cool for prototyping that you can Just Use Them™.

nha23:02:40

@josh.freckleton: For react.mdl all the objects are behind window (ex. window['MaterialCheckbox'] https://github.com/tleunen/react-mdl/blob/master/extra/material.js#L701 ). But I use semantic.ui now as well (even though I submitted react-mdl to cljsjs), following advice from cjmurphy.

cjmurphy23:02:32

It was just my experience with that tabbed pane thing really.

cjmurphy23:02:23

But if I had gone the React route it might have been different.

josh.freckleton23:02:09

@nha: awesome, I'll probably end up trying out Semantic! In the mean time, any idea why this is throwing an error?:

(ns project.views
  (:require [cljsjs.react-mdl]))

(def Button (aget js/ReactMDL "Button"))
how should I use your information about the objects being behind window?

cjmurphy23:02:29

Honestly at the time I thought I had got it wrong - that Material UI was a made up conflation of Semantic UI and Material Design. But as Jaen shows it really exists.

nha23:02:09

@josh.freckleton: I replied on SO, hope it makes sense

nha23:02:34

if you open a browser console you should be able to see the react-mdl components as well

nha23:02:55

(also I replied from memory)

nha23:02:58

you could try MaterialButton(element) for instance in the brower console to check the import worked

cjmurphy23:02:01

But you know if you are just doing css as I was, React integration does not matter.

cjmurphy23:02:26

Or does it?

nha23:02:03

Agree with you @cjmurphy, unless you need ready-made components (like datatable in react-mdl, or some fancy dropdown maybe)

cjmurphy23:02:27

Hmm - but I would have had an easier time of it with the tabbed pane thing - because it must have been the Javascript that meant not having to double up with all that html.

cjmurphy23:02:32

Interesting thing is Semantic UI tabbed pane is only css - and no need to double up on the html. So seems like it is of smarter design.

nha23:02:31

Yes, being pure css is definitely a plus. Maybe there will be a om-semantic-wrapper at some point for the more dynamic components, in the meantime I'm happy with semantic.

nha23:02:49

But I would love to know what people use, especially with Om.next

cjmurphy23:02:23

soda-ash for Om Next?

nha23:02:56

That would be great simple_smile

nha23:02:15

However the author told me that he doesn't see a migration path with om

nha23:02:45

(even though I use sablono with om.next)

venantius23:02:22

I preferred cljs-ajax, personally

venantius23:02:28

but I’m sure either works

jaen23:02:05

I more often than not just go the sente route if I can and the few times I didn't I used cljs-ajax and was satisfied by it. Didn't have any chance to compare it to cljs-http though.

nha23:02:00

Thanks, I only used cljs-ajax so far as well.