Fork me on GitHub
#clojurescript
<
2015-12-11
>
tom00:12:23

How do you use regex in cljs? How would I translate /notes/gi into something like (re-find)?

tom00:12:32

or, something re-find can use I mean

richiardiandrea00:12:07

Cannot point you to some resource but cljs regex follows the Clojure rules...with little differences, for instance "/" is not a special char (if I remember correctly)

dgellow05:12:59

@tom:

cljs.user=> (re-find #"notes" "hello here some notes for you")
"notes"
Is that what you want?

rauh10:12:59

How much overhead (roughly in KB, gzipped) does Datascript have?

jindrichm10:12:02

I cannot find this documented: Can you compile Clojurescript with Java 8?

rasom10:12:45

@jindrichm: I can do this on my comp with Java 8, so it should work

jindrichm11:12:00

@rasom: OK, thanks. I probably have a different problem then. EDIT: Updating to lein-cljsbuild "1.1.1" solves it.

tonsky11:12:45

@rauh: just tried to compile simple example with and without DS. 310k → 498k raw, 78K → 118K gzipped

tonsky11:12:57

so I would say 40k

tonsky11:12:19

I’m not sure how much of this is shared CLJS core functions, because DS uses a lot of these

tonsky11:12:37

in a bigger application difference would probably be smaller

rauh11:12:46

@tonsky: Thanks, that sounds actually very reasonable. I'll eval it further

danielgrosse12:12:30

How can I declare a global variable with clojurescript?

rm12:12:16

//global variable
globalName = "JavaScript Interop";
globalArray = globalArray = [1, 2, false, ["a", "b", "c"]];

joelkuiper13:12:46

@juhoteperi: hey, I saw you packaged selectize for cljsjs, and I was wondering if you by accident know if there you need to do anything special to get the typeahead/text completion to function in Reagent

joelkuiper13:12:34

sort of the code I have now https://gist.github.com/joelkuiper/0b970745cda78de007a0 I pass in options and defaults as the options param, but no typeahead!

juhoteperi13:12:56

@joelkuiper: Sorry, I didn't package it originally. You should probably debug if the problem is with JS or CSS, check with dev tools if selectize elements are being created.

juhoteperi13:12:47

Also, instead of creating input with id using set inner html, it's much easier to just create input with id with react: [:div [:input {:id id}]]

joelkuiper13:12:21

yep, bit of a legacy issue when I was fiddling with it

joelkuiper13:12:33

I guess the problem is that it lacks the sifter dependency

juhoteperi13:12:20

@joelkuiper: Cljsjs package uses standalone version so shouldn't be needed

juhoteperi13:12:11

@joelkuiper: Check if update-selectize! sees the input created by selectize!

joelkuiper13:12:39

yep the whole thing works, with the prepopulated options, except typing doesn’t do anything

joelkuiper13:12:52

i guess I can check if the onType fires

joelkuiper13:12:47

welp the onType event gets fired

joelkuiper13:12:35

hmm weird, I guess I can go without the typing functionality for now. Sifter does get included in the source as you say

joelkuiper13:12:01

but I still can’t get the type to work, probably some weird interaction between google closure/reagent/jquery and selectize

joelkuiper13:12:10

but nothing in the console that would indicate that

snowell13:12:52

I know it’s a longshot seeing as Java != Javascript, but is there a way to execute clojure code from my cljs webapp without having to go over http with compojure?

snowell13:12:18

Google says macros, but common sense tells me I can’t just change defn to defmacro and declare victory simple_smile

joelkuiper13:12:03

re:selectize, it was my own fault for not reading tfm, if you change the label/id fields you need to also pass in searchField https://github.com/brianreavis/selectize.js/blob/master/docs/usage.md

joelkuiper14:12:15

@snowell: well not at runtime, since you don’t have access to the JVM on the browser or NodeJS. With macro trickery you can get clojure code to execute at compile time though

joelkuiper14:12:34

also you can share code between Clojure and ClojureScript with cljc and reader conditionals, if that’s what you’re after simple_smile

joelkuiper14:12:02

if you really must execute JVM code in the browser, I guess you can go the old fashioned way with Java Applets 😉

snowell14:12:19

@joelkuiper: I was trying to look into cljc but it didn’t seem like I was going to be able to bring in Java objects and mess around with them

snowell14:12:37

And no, I don’t need this THAT badly simple_smile

joelkuiper14:12:49

nope, if that’s your goal then I guess the only options would be Java Applets, or doing a round trip to the server

joelkuiper14:12:00

the latter is probably preferred in the current ecosystem 😉

snowell14:12:14

Round trip is what I’m currently doing, but the machine I’m hosted on has pretty bad latency

snowell14:12:22

So it’s making the app look super slow

joelkuiper14:12:23

although I’m still predicting a revival of applets in the near future 😛

scttnlsn15:12:39

Trying to use with-redefs with cljs.test but it doesn’t seem to be working. Does with-redefs work in ClojureScript?

dnolen15:12:32

@scttnlsn: if your test is async no it probably won’t work

doddenino15:12:09

Hi guys, I'm having some troubles making my uberjar finding static resources (mainly the index and compiled js file). I started from a re-frame template to which I added a compojure/http-kit backend. Can anyone point me to a guide? Thanks a lot!

joost-diepenmaat15:12:07

@doddenino: are you using wrap-resource ?

joost-diepenmaat15:12:34

if so, we use something like this

scttnlsn15:12:48

@dnolen: Ahh, yeah, it is async

scttnlsn15:12:18

The redefined function is async that is

joost-diepenmaat15:12:24

and then we put :resource-paths ["resources" "generated”] in the project.clj also

scttnlsn15:12:42

The redefined function is called synchronously from the subject under test though

joost-diepenmaat15:12:44

so all generated resources go to the “generated” directory and that’s included in the jar

dnolen15:12:24

@scttnlsn: yeah won’t work

doddenino15:12:43

@joost-diepenmaat: No, I'm not using wrap-resource. Do I have to?

joost-diepenmaat15:12:06

@doddenino: if you’re running from a jar, you have to serve all statics as resources instead of files

joost-diepenmaat15:12:39

so if you’re currently using wrap-file, that won’t work in a jar

joost-diepenmaat15:12:26

if you’re using ring-defaults, that includes resources I think. see https://github.com/ring-clojure/ring-defaults

joost-diepenmaat15:12:53

though the documentation for ring-defaults is very terse and I tend to just look at the implementation

doddenino15:12:13

@joost-diepenmaat: I have a (route/resources "/") route, my js is outputted to resources/public/js/compiled and I have a :resources-path "resources" in my project.clj. I'm not using ring-defaults

joost-diepenmaat15:12:31

I think that should work

joost-diepenmaat15:12:51

does it work when running from the repl instead of in a jar?

joost-diepenmaat15:12:35

as far as I know everything in resources will be included in the jar and should be accessible

joost-diepenmaat15:12:49

you could unzip the jar to see if the files are there

doddenino15:12:51

it's in the jar if I unpack it

doddenino15:12:42

but it seems like it's looking for resources outside of it. For example, if I put the jar in a different folder it complains that it can't find the index.html file

joost-diepenmaat15:12:03

I don’t know. I’ve had trouble configuring all of that before but I can’t really remember what the problem was then

doddenino15:12:23

I'll figure it out, thanks a lot for your help!

doddenino15:12:42

Just one last question: If I have different cljsbuild builds (let's say "dev", "test" and "min"), how can I choose which one has to be used with lein uberjar?

joost-diepenmaat15:12:46

I think you can use an “uberjar” profile

joost-diepenmaat15:12:52

or not. I forget. sorry I have to go.

scttnlsn16:12:40

Is there any way to stub an async function with ClojureScript then?

dnolen16:12:47

@scttnlsn: async tests are serialized so sure write some custom code for this

scttnlsn16:12:45

@dnolen: Not sure what you mean. Custom code for what?

dnolen16:12:12

@scttnlsn: read the source of the with-redefs macro

dnolen16:12:16

how it’s works is trivial

scttnlsn16:12:23

OK, will do

dnolen16:12:31

then write you own version of given that async tests are serialized

dnolen16:12:52

they will happen one after another so that’s strong enough guarantee to write something simple that works for you

scttnlsn16:12:12

Oh I see, OK

scttnlsn16:12:20

Yeah, I think simple set!s around the test code will be fine for now.

jannis17:12:37

Is anyone here fluent in bidi?

jannis17:12:23

I'm using its ClojureScript router, set-location! and :navigate-to to translate back and forth between URLs and app state mutations. So when the URL changes, :navigate-to triggers the mutations necessary to make my app state reflect the URL. I use set-location! from my app to translate the app state to a URL that is then set. However, with URL patterns like /foo and /foo/:x it seems this only works in one direction. So it matches /foo to {:handler :foo} and /foo/13 to {:handler :foo :route-params {:x 13}} when calling :navigate-to. But it translates both {:handler :foo}and {:handler :foo :route-params {:x 13}} to {:handler :foo} in set-location!, which is wrong. The order in which routes are defined may play a role but I'm not sure how it's done right.

jannis17:12:22

@agile_geek: Thanks, looks like you've done that for me. 😉

jaen17:12:58

@jannis: what do you mean by translating {:handler :foo}and {:handler :foo :route-params {:x 13}} to {:handler :foo}? Do you mean using path-for or am I misunderstanding something?

jannis17:12:43

@jaen: I mean that calling set-location! (https://github.com/juxt/bidi/blob/master/src/bidi/router.cljs#L72) with those two inputs leads to :navigate-to to be called with {:handler :foo} both times, and the URL to be set to /foo both times.

jaen17:12:06

Oooh, I didn't know about that

jaen17:12:20

I always set up goog.History by myself so far

jannis17:12:13

I only found out about it yesterday when looking for an alternative to pushy.

jannis17:12:44

It's quite cool. :navigate-to to react to URL changes, set-location! to feed changes into the router. Done.

jaen17:12:14

I guess I'll have to take a look at it

jaen17:12:20

But interesting it looses the params, from the code it looks like location->token does almost the same path-for does, and that worked for me.

jaen17:12:37

I guess you'll have to wait for an implementer to chime in then.

jannis17:12:58

It might actually work with my examples. My routes are a big more complicated than that.

agile_geek17:12:13

@jannis 😄 of course now Malcolm and Jon won't talk to me again

jannis17:12:04

/[#"[^]*" :state]/requirements and /[#"[^*]" :state]/requirements;[#".*" :names] is what they look like (not a bidi notation ;)), and I'm mapping them both to the same handler (`:requirements`).

jannis17:12:55

@agile_geek: Ha, I hope they will simple_smile

jaen17:12:13

Oh, if you're mapping the to the same keyword, then it definitely makes sense

jaen17:12:17

You shouldn't

jaen17:12:26

How it's supposed to know which to unmatch to?

jannis17:12:03

Based on the presence or absence of :names in :route-params, I was hoping.

jaen17:12:17

I don't think it works that way unfortunately.

jaen17:12:36

Why not use different keywords

jaen17:12:46

And just have the handler twice in the keyword->handler map?

jannis17:12:22

keyword->handler map?

jannis17:12:32

bidi seems to have support for multiple routes matching the same handler, according to https://github.com/juxt/bidi/blob/master/src/bidi/bidi.cljc#L443:

;; If you have multiple routes which match the same handler, but need to
;; label them so that you can form the correct URI, wrap the handler in
;; a TaggedMatch.

jaen17:12:49

@jannis: with ring if you use keyword you have to specify a function that maps the keyword to a handler (you can make use of map specifying IFn if you don't need more than a simple lookup) and I assumed this router has a similar parameter.

jaen17:12:22

But now I see I was wrong and it's structured differently.

jaen17:12:37

TaggedMatch could be a solution I suppose, but I've never used it.

jaen17:12:07

But from the docs it seems like this is supposed to work when you specify handlers as functions, not as keyword - https://github.com/juxt/bidi#tagged-match.

jaen17:12:24

But I suppose I'm being more confusing than helpful right now, so I'll zip.

jannis18:12:08

@jaen: No no, you're making a good point. It might work even without function handlers as well: ... {"requirements" {"" (tag :requirements :all-requirements) [";" [#".*" :names]] (tag :requirements :specific-requirements)} ....

jannis18:12:12

At least I'll try that simple_smile

jannis18:12:14

Yes, that seems to work. Need to test it a bit more though.

leonoel18:12:31

hi, is this possible in clojurescript to make functions implement custom protocols like in clojure ?

dnolen18:12:26

@leonoel: at the cost of interop, you can make callable objects but JS won’t understand them

leonoel18:12:27

@dnolen yes that solution could work for me but I was trying to port a clojure code that was an extend-type of clojure.lang.Fn

dnolen18:12:57

there is no analog to that type

dnolen18:12:04

JavaScript has functions

dnolen18:12:22

(extend-type function …) is what you want

dnolen18:12:31

not really recommended of course

leonoel18:12:16

not recommended, because it could break third-party libs ?

dnolen18:12:31

in applications it’s fine

dnolen18:12:36

but don’t put stuff like that into a library

sveri21:12:49

@bhauman: Hi, if you have some time, I raised an issue for prismatic schema in combination with figwheel. Maybe you could have a look at it and see if this could be figwheel related? This is the uri: https://github.com/Prismatic/schema/issues/315

richiardiandrea22:12:42

For REPL lovers, we released a new version on http://clojurescript.io that should be way faster. The following tweaks were combined in order to shred the app size (no modules yet):

Added elide-asserts flag (~100KB less)
Added dump-core flag (~2MB less)
Filtered unused symbols from cljs_api (~500KB less)
In addition to the :optimize-constants and :static-fns flags the total size of cljs-repl-web.js decreased from 9.9MB to 4.7MB

richiardiandrea22:12:02

it was in answer to @mfikes video: https://youtu.be/9k6Z3GTai6c (thanks Mike :))