Fork me on GitHub
#clojurescript
<
2018-11-17
>
idiomancy02:11:08

is that how web3 does it I wonder?

Dustin Getz03:11:47

is js/console.log syntax future proof? as opposed to (.log js/console)

mfikes03:11:16

@dustingetz I have never seen anything that formally guarantees this.

❤️ 4
mfikes03:11:28

But it is so heavily used, it would be odd to break that.

mfikes03:11:51

I’ve also seen people do (console.log "foo") 👀

michihuber06:11:58

I've started seeing Cannot read property 'j' of null errors in places where it doesn't make sense since upgrading to 1.10.439 from 339. e.g. the stacktrace leads me to the second line here:

(defmethod handle :tutorial/next [{:keys [state]} _]
  (let [schedule (get-in state [:edit :tutorial :schedule])
any ideas what could be causing this?

michihuber06:11:10

90% sure this coincided with the cljs upgrade

igrishaev09:11:10

Does anybody know how can I add a static property or an extra method to a reagent component? Here is an example from the docs:

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Home',
  };

  /* render function, etc */
}
I need to declare a Component within the navigationOptions property or method. How can I do that in Clojurescript + reagent? The third form does not give any result.

serg11:11:19

Hey everyone, I’m just trying ClojureScript and figwheel and wondering if this is ok:

(event/listen (dom/get-element "test")
              :blur
              (fn []
                (prn ":blur")))
This event handler doesn’t work when I run production build js. But if I replace :blur to “blur” it does. So is it required? I am using advanced optimization.

Roman Liutikov12:11:05

Event type should be a string anyway

folcon13:11:13

Hey, are there any good resources on consuming clojure libs from clojurescript? I’m trying to use cljc as much as possible. Specifically I’ve been working with loom (mixture) and ubergraph (java focus) as they both bring things to the table and I want to wrap up the complexities of dealing with them in a cljc namespace.

Joe15:11:20

https://github.com/reagent-project/reagent/blob/master/doc/UsingSquareBracketsInsteadOfParens.md <-- is there a general pattern in clojure for putting functions inside square brackets, or is reagent an exception?

enforser15:11:36

I believe reagent is an exception!

enforser15:11:32

if you put a function in a vector in other contexts you will not get the result of the function, you will get a vector where the first element is a function

enforser15:11:23

cljs.user=> (defn foo [x] [:div x])
#'cljs.user/foo
cljs.user=> [foo 1]
[#object[cljs$user$foo "function cljs$user$foo(x){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"div","div",(1057191632)),x], null);
}"] 1]
cljs.user=> (foo 1)
[:div 1]
The renderer is what does the [foo 1] magic

billyr16:11:32

Without parens reagent would have to make use of macros. This vector trick helps to avoid that

billyr16:11:23

with parens*

jaawerth16:11:41

@joebetz91 It's a useful pattern to describe functions and the args you want to pass them, and I've even used it in other langs, like javascript, before, but I don't think it's a pattern particular to clojure. Reagent makes particularly heave use of it, but it's a sometimes useful form of indirection in general

Joe17:11:51

what is the value of the indirection when you already know the function and args?

Joe17:11:28

I can see how you'd want to delay evaluation of an expression to inspect or manipulate it, but then, isn't that what macros are for?

jaawerth16:11:10

I've used it for e.g. things like building up functions to pass to a DB query builder from, say, query params passed to an API call

kenran_16:11:26

I'm having a peculiar problem (again). In the snippet you can see cljs and clj code that work perfectly fine when running in dev mode (figwheel-main). As soon as I make a prod build via uberjar (and simple optimizations), nothing is sent via POST. The handler is still called but whithout data. I'm at a loss. Any tips on how to debug this or hints what this could be are greatly appreciated!

kenran_16:11:02

The console logs show data in dev mode, but the form data seems to not have anything in it in a prod build.

jaawerth16:11:18

did you verify from the client-side that nothing is sent? via e.g. dev tools or by trying the same POST from curl? Might help narrow it down to a client or server issue

kenran_16:11:16

I just this moment realized that the form data might not be empty but just looks like it. I have to dive deeper into the dev tools I think (no experience looking at js objects and the like in the dev console so far).

jaawerth16:11:09

I think you need ring.middleware.multipart-params

jaawerth16:11:51

there's a wrap-multipart-params in there you can use around your /upload handler that should parse it for you

kenran_16:11:46

That sounds like it might be the culprit! I stumbled over this when I figured out compojure routes, but I read somewhere that compojure does this automatically. I wonder why it works in a dev build after all. But I just found the place where I can see whether it's at least sent correctly and I'm doing another prod build right now.

jaawerth16:11:28

yeah that's a silly thing to add for you in dev, better to catch such an omission early. I'm also curious as to why it did that

kenran_16:11:58

Could it be figwheel-main that is doing this in a dev build?

kenran_16:11:58

That is the part that's strangest to me: I've been using the code for a month now locally 🙂

jaawerth17:11:59

not sure, tbh - it's possible the server it provides has some default middleware wrappers I guess

kenran_17:11:05

That was it; Thanks a lot!

jaawerth17:11:09

@johb.maier ahhh I bet it's this - specifically the ring-defaults it's referring to https://figwheel.org/docs/ring-handler.html#the-last-handler

kenran_17:11:43

@jesse.wertheim Yes, I bet! It's been a long time since I've added the handler... I forgot about that. I even remember having read it now

jaawerth17:11:40

I guess a good takeaway is to write separate tests for the server that make API calls against it directly (or just testing the handlers via ring test tools) rather than via figwheel

jaawerth17:11:49

I'll be remembering that for future reference, too 😉

kenran_17:11:34

The funny thing is: I'm in the process of trying to switch to or at least trying out shadow-cljs. I just wanted to get the prod build running before doing so. In hindsight the other direction would have been better since I'd probably have caught that 🙂

kenran_17:11:29

@jesse.wertheim Yes that's a todo as well! It's a learning project 🙂

kenran_17:11:46

thanks for your quick and helpful response!

jaawerth17:11:17

sure thing! I'm still learning my way around ring as well so helping you helps me

kenran_17:11:35

Yay, working dev and prod build with the clojure cli tools and deps.edn now!