Fork me on GitHub
#beginners
<
2018-04-06
>
noisesmith00:04:29

the trick here is that an interface can't extend anything, but two things extending the same interface or protocol is how we tend to do things

noisesmith00:04:42

also composing interfaces - implementing multiple interfaces to make one thing

athomasoriginal00:04:49

The question I meant to ask: Should I be using :import or require for goog.fx.Dragger. My thought is that it should be import because Dragger is a class. see https://google.github.io/closure-library/api/goog.fx.Dragger.html

athomasoriginal00:04:41

but then this class also has enums that can be imported at Dragger.EventType

athomasoriginal00:04:19

To take this thought to the next step, what happens when enums from different class have the same names like:

[goog.events EventType]
[goog.fx.Dragger EventType]
The above won't work because the second EventType overwrites the first. Would this mean we just have to do the following:
[goog.events.EventType]
[goog.fx.Dragger.EventType]
and then reference the full name each time?

Chris Bidler02:04:41

@tkjone You would be able to get away with importing one of the EventTypes while using the other one’s full, namespace-qualified name

Markus Åkerlund Larsson08:04:43

Anyone know much about Cursive? I can't get Clojurescript to work in the REPL. It'll load files fine as long as they don't use any external libraries.

troglotit08:04:27

Hey! I am using cljs-ajax like this :

(defn signin
  "Try to signin using email and password"
  [{ :keys [email password handler error-handler]}]
  (POST (str uri-host "/users/password_signin")
              {:params {:email email
               :password password}}
               :format :json
               :handler handler
               :error-handler error-handler))
to post json, and it sends transit, not json. Is there anything wrong with this? Used ajax-request, and it worked. very strange :thinking_face:

Fahd El Mazouni11:04:30

is there someone with bigquery experience ?

curlyfry12:04:12

@troglotit Looks like :format, :handler, and :error-handler aren't part of the options map

curlyfry13:04:02

Not sure what you mean. In your example those parameters aren't included in the map literal {}

timo12:04:54

Hi there! Anyone know what this means? Uncaught TypeError: Cannot read property 'ReactCurrentOwner' of undefined How can I debug the advanced-compiled reagent/re-frame-app?

Surya Poojary13:04:35

(read-line) can read integers as well ?

bronsa13:04:42

read-line reads strings

Surya Poojary13:04:31

For reading ints

Surya Poojary13:04:16

read-int is not valid

bronsa13:04:14

read the input as a string and parse an int from that string

bronsa13:04:30

using e.g. Integer/parseInt

sundarj14:04:47

you can define read-int like so:

(def read-int (comp (fn [s] (Integer/parseInt s)) read-line))

Surya Poojary15:04:38

Thanks for the reply !

Surya Poojary16:04:34

Is that function anonymous

sundarj17:04:37

yeah, it shows up in stack traces as

clojure.core/comp/fn core.clj: 2560
boot.user$fn__2470.invoke    :    1

sundarj17:04:29

to have it show up as boot.user$read_int.invoke you can define it fully like (defn read-int [] (Integer/parseInt (read-line)))

Charles Fourdrignier13:04:54

How do you write and store your doodling ? I write little code with data.csv and spec-provider to explore some files. Not something I really want to put in an application, but I would like to put in a repository for futures explorations. I create a “app” with leiningein with seems overkill, but that’s the only way to write Clojure I know at the moment. Maybe I should look at deps.edn, ... ? Do you have some good pointers (blog posts, articles, ...) on the subject ?

sundarj14:04:56

yeah deps.edn is much lighter; the official docs are good: https://clojure.org/guides/deps_and_cli

seancorfield17:04:48

I like that you can use clj to fire up a REPL with a set of dependencies in the command-line arguments, so you don't need a "project".

seancorfield17:04:04

It's one of the things I really like about Boot vs Leiningen.

seancorfield17:04:39

There's lein-try, but then you need that in your personal config etc.

sundarj17:04:40

☝️:skin-tone-3:

seancorfield17:04:56

boot -d some-group/the-artifact repl
will fetch the latest (non-snapshot) release of that project and fire up a REPL with it. With clj you can do
clj -Sdeps '{:deps {some-group/the-artifact {:mvn/version "RELEASE"}}}'
but that's a lot more verbose.

4
seancorfield17:04:14

I also like that Boot lets you load new dependencies at runtime into your REPL, so you don't have to stop your REPL, edit some file, start the REPL back up...

seancorfield17:04:03

I think Boot is a lot more beginner-friendly -- but Leiningen is older/more established, so nearly all the tutorials out are written for lein ¯\(ツ)

sundarj17:04:03

and there's the fact that tools like Figwheel are tied to Lein (i think?)

seancorfield17:04:27

Hmm, I thought I'd seen folks talking about Figwheel in #boot (but I don't pay much attention to cljs stuff).

sundarj17:04:34

well, i just use adzerk-oss/boot-reload, but bhauman/lein-figwheel (naturally) only mentions Lein, and boot-clj/boot-figreload is incomplete according to the readme. perhaps there's a way to use figwheel-sidecar with boot, but i never really looked into it 😛

sundarj17:04:15

the new figwheel-core being worked on works with clj though, so that would probably work with Boot too

Charles Fourdrignier14:04:25

@seancorfield Thank you for all this feedback ! (I should activate some mails notifications, I don’t open Slack during 3 days and nearly miss you response.) I need to say I love this community, so helpful, so beginners friendly.

manutter5113:04:36

@timok I’m not sure exactly what your issue is, but based on some googling, I’m seeing reports of people getting this error when they have multiple React libs with different versions, especially React 15 vs 16. Try lein tree :deps to see if you can spot any conflicting React versions and if lein recommends any exclusions.

timo13:04:45

@U06CM8C3V Hi! Thanks for the reply. I was already looking into this and really, I am feeling lost here. I changed a lot of stuff now to get back to a running state.

👍 4
timo13:04:58

lein deps :tree does show me a lot of advices but there is nothing about react. Is it possible that google closure is the issue here?

manutter5114:04:32

I don’t know enough about it to really tell, unfortunately. I tend to doubt it though, sounds like something inside React is unhappy

timo14:04:15

maybe when I exclude react for a specific library? that this library needs e.g. a newer version?

manutter5114:04:47

Are you excluding any libraries at the moment?

timo15:04:24

not anymore

timo15:04:45

I now explicitly require the exact versions from reagent 0.7

timo15:04:30

but I did exclude react and react-dom from semantic-ui and react-datepicker

manutter5115:04:50

And that fixed it for you?

timo15:04:23

no not until now...maybe I need to systematically approach this and try all the combinations...but the thing is, that running the uberjar on its own works and when deploying it to a server it does not and that's an indicator that it has to do with something else...

timo15:04:43

the deployment is not really automated and it takes me hell of a lot of time

timo15:04:50

that's it

timo15:04:07

kind of works now...but no idea why...with these specific react dependencies and no excludes...aw_yeah

manutter5115:04:21

Sounds good. Sometimes I think removing a dependency might leave behind bits of code that should have been removed. The weirder things get, the more I do lein clean, out of sheer paranoia.

😆 4
justinlee15:04:51

@c09mld try #cursive. the author hangs out in there.

Daniel Hines16:04:15

I'm trying to use clj-http's convenient :as :json option to turn JSON into a Clojure map, but the OData endpoint I'm using returns annoying JSON field names like "[email protected]". Some functions seem to handle it just fine, but things like keys or map blow up because of the "@". I need the data the keys provides, and the keys are dynamic, so I can't deal with each key specifically. Any ideas on how to succinctly deal with the bad characters?

justinlee17:04:18

I think you need to use string key instead of keyword keys. so :as :json-string-keys

Daniel Hines17:04:49

Ah, ok. That would solve it. Thanks!

noisesmith18:04:37

@d4hines also, (keyword "[email protected]") does work - but much better to use strings instead of keywords for that kind of data

Daniel Hines18:04:00

Ok, cool. Fortunately, :json-string-keys is working beautifully.

Kari Marttila18:04:40

I'm pretty puzzled how to use cljs-ajax library correctly. I have implemented a Clojure/Ring backend and tested with curl and Postman that both the GET and the POST interfaces work properly. I have configured the required cors settings. In ClojureScript frontend when using the cljs-ajax library to send a GET request everything works properly. But when sending a POST request (a map of a couple of key/value pairs as json) I get reply: XMLHttpRequest cannot load <POST url>. Response for preflight has invalid HTTP status code 400. And the weird thing is that the browser seems to send OPTIONS instead of POST. I'd be happy to find some working example to check what I have misunderstood.

justinlee18:04:00

@kari.marttila are you sending your GET and POST to the same url specified in exactly the same way?

noisesmith18:04:26

unlike curl, a cross origin request needs a preflight and cors setup

noisesmith18:04:56

it will send OPTIONS first iirc and the backend has to be ready to cooperate

justinlee18:04:34

oh GET doesn’t require preflight

justinlee18:04:49

that’s why the different behavior

noisesmith18:04:40

> The CORS specification mandates that requests that use methods other than POST or GET, or that use custom headers, or request bodies other than text/plain, are preflighted.

noisesmith18:04:13

(quote from my above http://mozilla.org link)

justinlee18:04:41

@kari.marttila the root of your problem is not cljs-ajax, it’s that you just don’t have cors setup correctly

Kari Marttila18:04:57

Ok. Thanks. I'll investigate the issue now that I now what to fix. Thanks. 🙂

Kari Marttila18:04:49

@lee.justin.m and @noisesmith: Any suggestions what should I add in the Clojure/Ring application side? I have currently configured the cors settings as: (assoc-in [:headers "Access-Control-Allow-Origin"] "*") (assoc-in [:headers "Access-Control-Allow-Headers"] "X-Requested-With,Content-Type,Cache-Control") (assoc-in [:headers "Access-Control-Allow-Methods"] "GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS") (assoc-in [:headers "Content-Type"] "application/json") (assoc-in [:headers "Access-Control-Max-Age"] "1728000")

seancorfield18:04:24

@kari.marttila Have you looked at the ring-cors middleware to do this automatically for you?

seancorfield18:04:09

(let [h (ring-cors/wrap-cors handler
                               :access-control-allow-headers #{"accept"
                                                               "authorization"
                                                               "content-type"
                                                               "origin"}
                               :access-control-allow-methods [:delete :get
                                                              :patch :post :put]
                               ;; 24 hours (in seconds) -- note that only Firefox
                               ;; will honor this; other browsers cap lower!
                               :access-control-max-age "86400"
                               :access-control-allow-origin #".*")]
    (fn [req]
      (h req)))
for example

seancorfield18:04:38

(It doesn't improve the configuration much over what you're doing manually, but it handles the OPTION preflight check automatically)

Drew Verlee19:04:48

Maybe this should be obvious, apologies if it is, with the clj tool is there a recommended way to integrate clojure.test?

seancorfield19:04:34

@drewverlee Did you see my dot-clojure deps.edn file? I posted the link to GitHub in a few places...

seancorfield19:04:50

clojure.test is "built-in" (part of the main Clojure JAR) so you can just use it in code without additional dependencies -- so the key steps with clj are: adding test as a path (or wherever your test code lives) and adding some sort of test runner (such as Cognitect's test-runner project). https://github.com/seancorfield/dot-clojure/blob/master/deps.edn --

clj -A:test:runner
lets me run tests

seancorfield19:04:20

clj -A:test:runner:1.7
will run tests using Clojure 1.7, for example

seancorfield19:04:52

I separate the test paths/deps from the runner so that I can start an nREPL server with tests on the classpath

clj -A:test:nrepl

Drew Verlee19:04:06

Yea. Thanks @seancorfield. I somehow missed it in the offical docs to: https://clojure.org/guides/deps_and_cli#extra_paths

seancorfield19:04:11

(hmm, I don't have Clojure 1.7 in my deps.edn but I do have that alias in core.cache and core.memoize which both use clj / deps.edn for local dev/testing)

seancorfield19:04:22

So, multi-version testing of core.cache https://github.com/clojure/core.cache/blob/master/deps.edn is

for v in 1.6 1.7 1.8 1.9 master; do clj -A:test:runner:$v; done

Kari Marttila21:04:54

Thanks @seancorfield! I'll try that tomorrow. It's already midnigh in Finland, got to go to bed.