Fork me on GitHub
#clojurescript
<
2017-03-06
>
emccue01:03:27

@eveko For adding lein to your build config, I will defer to the more knowledgeable people here. As far as how you are designing the backend: It isn't how I would do it, but for your school project it is how it is. I'm not intimately familiar with the terminology around the Java EE world, but as long as it exposes an API to the client you shouldn’t have any problems using reagent. (And I would recommend re-frame with reagent, for at least the reason that it will make explaining the design pattern used more succinct

sova-soars-the-sora03:03:09

Hi everyone. What's a good way to do Ajax calls, and how do you do the response on the server | ring side of things?

qqq05:03:06

cljs-ajax

thedavidmeister06:03:37

@sova cljs-ajax + ring-defaults + buddy for auth

kauko13:03:07

We're starting a clojure course at my company. We're going to start with this Clojure MOOC http://iloveponies.github.io/120-hour-epic-sax-marathon/index.html and then move on to clojurescript and stuff related to analytics (so Datomic, Onyx, clojure in the cloud, etc..). Anyone know any interactive clojurescript courses, similar to the one I linked? We're probably going to build our own, but inspiration is always good.

jdeisenberg18:03:33

kauko: I'm also writing an interactive clojurescript book http://langintro.com/cljsbook

jrychter13:03:26

@sova or just use Sente — it falls back to AJAX if necessary, but uses websockets by default.

hkjels13:03:07

How do I pass a function-reference to a macro? Context: If I hard-code ui.element.input/checkbox into my macro, I’m able to exercise that specification. But if I send it as an argument to that macro using syntax-quote, it’s not able to resolve the spec

hkjels13:03:47

(spec-panel `checkbox)

joshkh14:03:42

howdy folks! how might i go about adding the project.clj's version number as a property to my compiled javascript as part of the lein cljsbuild process?

joshkh14:03:11

i'm using local storage that i need to burn when a new version of the app is released

not-raspberry15:03:08

What about embedding that in the app's HTML (`<script>APP_VERSION = 1.2;<\script>`) in the backend (you can obtain the number with (some-> (io/resource "project.clj") slurp edn/read-string (nth 2))

joshkh15:03:01

could do, not-raspberry! thanks for the suggestion. i'm trying to avoid the need for server side code at all though.

joshkh15:03:53

i'm closer but i seem to have a problem with clojurescript / closure compiler, specifically closure-defines: https://github.com/clojure/clojurescript/wiki/Compiler-Options#closure-defines when i try to compile my clojurescript i get the following error. it doesn't make sense to me. i'm obviously passing a string as a value to the key.

------ Figwheel Configuration Error ------

The key redgenes.core/VN at (:cljsbuild :builds :min :compiler :closure-defines) has a non-conforming value: 
  (str "some-version-number-test")
It should satisfy one of: Number | NonBlankString | boolean?

  {:cljsbuild
   {:builds
    {:min
     {:compiler
      {:closure-defines
       {redgenes.core/VN (str "some-version-number-test")
        ^---- The value at key redgenes.core/VN doesn't conform
        }}}}}}

joshkh15:03:50

passing in a pure string works fine

dnolen15:03:52

@joshkh are you using Lein?

dnolen15:03:04

if you are everything is implicitly quoted

dnolen15:03:10

so you are passing a list there

dnolen15:03:34

i.e. ’(str “some…”)

dnolen15:03:47

a list containing the symbol str and a string

joshkh15:03:55

uhg, that's totally right. thanks dnolen. it even warned me when i quoted a key somewhere else.

dnolen15:03:38

everyone gets burned by this at some point 🙂

joshkh15:03:35

what's the fancy way of "unquoting" the form?

dnolen15:03:27

there’s no way to do that

dnolen15:03:33

if you’re using Lein you are stuck with the behavior

dnolen15:03:21

it’s the tradeoff of defproject being a declarative thing not a programmatic thing

joshkh15:03:42

gah. at the end of the day all i want is my project.clj's version somewhere within my cljs. maybe i can write a script to just append it to the compiled code, but that feels dirty.

joshkh15:03:50

looks like i'll be investigating boot when i find the time

joshkh15:03:49

someone over in #clojure linked me to this lein project and they seem to be doing it: https://github.com/jonpither/juxtweb/blob/d85b6443bbcd6b0202f150010816641f9feae28c/project.clj

dnolen15:03:46

@joshkh cool, that’s news to me, I didn’t know defproject understood unquote

joshkh16:03:20

well that's the weird thing. it apparently does for them but not me. 😉

joshkh16:03:38

okay, just to wrap up that mystery: i had (def version "0.1") at the top of project.clj and in my cljsbuild options: ~version in an attempt to unquote it. no bueno. so then i def'ed the version in a map (def props {:version "0.1"}) and tried ~(:version props) and that worked just fine.

gklijs16:03:15

I'm going to replace the plain websockets in my hobby project for Sente, any reason I should not do this, or any pitfalls I might enter? The middle ware I use is compatible.

mobileink17:03:42

hi. I’m trying to hot-reload html imports (<link rel=”import”…) using boot-reload and not having any luck. works fine for plain old css and js, though. can figwheel or some other lib handle this?

gklijs18:03:09

figwheel can, not sure how, used luminus to setup my project, and it works there.

mobileink18:03:20

@gklijs actually I wasn’t clear enough. I’m talking about an html import that contains polymer stuff e.g.

<dom-module id="headers">
  <template>
    <style> .... </style></template></dom-module>

mobileink18:03:42

just tried with plain old <style> as content, that didn’t work either. I’ll give figwheel a try, thanks.

timgilbert19:03:15

@joshkh: it's not at all an elegant solution, but in the past I've used a two-step compile process on my CI server that first basically does lein pprint version, then uses sed to update a file that just has (def version "@@LEIN_VERSION@@") in it, which is then followed by the normal lein cljsbuild process

timgilbert19:03:19

Never tried the lein-unquote thing with a :closure-define, but that sounds like a better solution if you can get it working

joshkh19:03:04

in the end the closure-define method worked 🙂

joshkh19:03:08

(note that it won't work for :optimization :none)

vikeri20:03:51

Probably a very basic question, but how do I load an ns and then use the updated def in the same repl statement? These work consecutively but not in the same statement: works

(require '[my.ns :as mns] :reload)
=> nil
(inc mns/const)
=> 2
doesn’t work (it does not reload the ns with the new definitions)
(do
  (require '[my.ns :as mns] :reload)
  (inc mns/const))
=> 2

joshkh20:03:51

out of curiosity, if you manually (inc mns/const) after the (do...) in the repl does it find const?

joshkh20:03:11

(i'm just wondering if it's a RACE condition)

joshkh20:03:16

actually that was a dumb question, sorry

vikeri20:03:35

Somehow the require statement is never run.

vikeri20:03:57

I’m solving this with a REPL action in cursive atm, but it would be neat not to have to do that

anmonteiro20:03:06

hrm, sounds like a bug

bronsa20:03:46

cljs probably needs to handle the gilardi scenario for that to work, like clj does

vikeri20:03:14

Maybe my workflow is strange, but wouldn’t this be a fairly common usecase when in the REPL? “Evaluate something, change a little code, evaluate it again"

juhoteperi20:03:13

I'm not too familiar with Cljs repls, but require will trigger async file load which needs to be finished before the code using code from required ns can be read and evaluated?

dnolen20:03:34

@vikeri require is a special thing, there’s no such thing as a dynamic require - it must be top level

dnolen20:03:52

you can’t put it inside do or anything else

vikeri20:03:08

@dnolen Ok, I tried using load-file as well, but it threw an error.

dnolen20:03:24

none of those things are going to work

dnolen20:03:32

so I would give it up

dnolen20:03:39

loads need to be top level period

vikeri20:03:19

Haha ok, good to know. Luckily enough Cursive solves it for me atm.

dnolen20:03:15

it might be possible to make it work at the REPL but it’s obnoxiously special case-y

dnolen20:03:36

and the fact that most editor integrations have inferior lisp like interactivity

dnolen20:03:38

small value add

vikeri20:03:05

Ok, I guess most editors have some macro (not the lisp kind) functionality and it can be solved that way if needed.

vikeri20:03:34

Another question, can I tell a REPL to start by evaluating a certain command? I would like my REPL to always (js/require “bootstrap.js”) the first thing it does.

dnolen20:03:43

at a low level yes this can be done - but other REPLs need to expose that

dnolen20:03:51

if you have your own REPL startup script :init is a thing

vikeri20:03:09

I’m using this one from the quick start:

(require
  '[cljs.repl :as repl]
  '[cljs.repl.node :as node])

(repl/repl* (node/repl-env)
            {:output-dir "out"
             :optimizations :none
             :cache-analysis true
             :source-map true})

vikeri20:03:40

What is :init?

juhoteperi20:03:16

repl is just a wrapper for repl*, which takes the options as kwargs instead of a map

vikeri21:03:23

@juhoteperi Alright, tried updating to

(require
  '[cljs.repl :as repl]
  '[cljs.repl.node :as node])

(repl/repl* (node/repl-env)
            {:output-dir "out"
             :optimizations :none
             :init #(js/require “./myJsFile.js”)
             :cache-analysis true
             :source-map true})
But it seems the init function is executed by Clojure? Got this erro:
Exception in thread "main" java.lang.RuntimeException: No such namespace: js, compiling:
...

mfikes21:03:30

@vikeri You could consider putting any special initialization you want into a namespace and then have it required via :repl-requires. See https://clojurescript.org/reference/repl-options#repl-requires

PB21:03:25

Is https://github.com/r0man/cljs-http the recommended way to make http calls using cljs?

tbaldridge21:03:49

@petr I've always just used the Xhrio utils that came with google closure (And therefore come with CLJS): https://developers.google.com/closure/library/docs/xhrio

PB21:03:06

Thanks!

raspasov22:03:21

@petr I’ve recently been using this library, which is a relatively 1:1 wrapper around Xhrio https://github.com/JulianBirch/cljs-ajax ; I used to use cljs-http but found certain limitations after a while; imo it’s always better to stick to less “decorated” libraries; in the end, you can always re-create the convenience in a few lines of core.async if you need to but also retain more power/control

piotr-yuxuan23:03:55

Hiya ClojureScripters 🙂 Would anyone have ever tried to use a polyfill so (compiled) cljs code works better on more browser? I can provide a example of a small project which currently behaves in a weird manner: https://piotr-yuxuan.github.io/1111101000-pieces/ I use css-transforms and clip-path, which are not properly supported on some browsers (works like a charm in Chrome Canary). Even when I try to add a polyfill from http://Polyfill.io <script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script> it still has a lot of issues (disclaimer: I know cljs itself doesn’t have anything to do with compatibility issue, I'm just wondering if anybody has faced such troubles)

isak23:03:59

@piotr2b are you using advanced compilation? if so, probably you have a lot of missing externs for those polyfills

piotr-yuxuan23:03:11

Thanks for your answer 🙂 but well, I thought any JS code (as minified as possible) will always talk to standard API through their standard names, won’t they? I’ve read that http://Polyfill.io relies upon user agent (so after compilation) to guess which definitions are to be sent.

isak23:03:04

@piotr2b there is no guarantee that whatever functions that service add are recognized by closure. Here is a list of stuff it knows about: https://github.com/google/closure-compiler/tree/master/externs/browser

isak23:03:39

@piotr2b to work around this, you can use pass a string to aget, since that will not be renamed

piotr-yuxuan23:03:16

Sorry @isak , I’m afraid I’m not sure to get your point: I don’t understand why I should provide externs to Google Closure. If somewhere my (not optimized) cljs code use Array.Stuff (which need to be polyfilled), will the heavily optimised js produced by Google Closure shrink this reference? I think it won’t but I’ll be happy if you prove me wrong!

netroms23:03:56

hi, desperate newbie question. I want to trigger "open file dialog" on an "input type=file" element via another button's "on-click" event. I have all the elements in the dom etc. I just struggle to find the right syntax/lib to manipulate dom to trigger what would be like "$input_el_id.click()" in jquery ? I'm using re-frame

piotr-yuxuan23:03:22

@netroms I gonna get afk from some hours but send me a msg if you still need help, it will be a pleasure to help you 🙂

netroms23:03:22

thnx piotr2b, bit late here too, everything was going smooth until this problem 🙂

piotr-yuxuan23:03:28

@isak same as above, I’m going to get afk for a couple of hours (aka night).

isak23:03:46

@piotr2b it is because you are using library functions that closure does not know about. Think about it -they aren't even in your build, they are fetched from a service. You might want to turn off advanced compilation for now, it is not something that "just works" https://clojurescript.org/reference/advanced-compilation

qqq23:03:03

use https://github.com/binaryage/cljs-oops -- I started using it yesterday, it's awesome