Fork me on GitHub
#clojurescript
<
2018-02-20
>
Lachlan Robertson00:02:45

@mfikes Big thanks for the help, looks like it was an issue with including the macro wrong. I’ll keep looking into it

chrisblom12:02:31

i want to write a function that returns true if the argument is an ordinary JS object, and false if it is a clojure collection, records or type

chrisblom12:02:58

what would be the most reliable way to do this?

joelsanchez12:02:09

satisfies? ISeqable would be a good approximation...?

mfikes12:02:10

object? is my first hunch

chrisblom12:02:03

thanks, object? is exactly what i need

frankiesardo14:02:09

Hello folks, I have a potentially silly question about cljs/js data structure interops. Right now the main pain point using ReactNative is remembering which component is a vanilla js one and which one is a cljs component, so there's a lot of clj->js and #js involved and a lot of confusion.

frankiesardo14:02:15

I saw this gist from dnolen about using ImmutableJs instead of cljs data structures https://gist.github.com/swannodette/436196e9d22a5164f837 Would this solve the clj->js interoperability problem? If so, is there a way to compile a forked version of ClojureScript that uses ImmutableJs whenever we create literal map, lists and arrays?

frankiesardo14:02:29

I'm happy to pay the performance problem to add developer convenience here, and I'm sure many others would do. The nice thing of clojure on java land is the seamless data structure interop.

frankiesardo14:02:40

Another crazy idea: adding destructuring for vanilla js objects would be great

dnolen15:02:06

@frankie I would ask this question in the #react-native channel, in the browser at least this kind of a solved problem as HTML components are so uniform

frankiesardo15:02:06

Yes, cljs on the browser is mainly a solved problem because components are already quite functional. The problem with RN and libraries like react-navigation is having to pass components (written in cljs) as arguments that are going to be called with js args

frankiesardo15:02:48

The typical example is a react ListView that takes a renderer (a simple cljs function) but it will call the renderer passing in a js map (so no chance to use destructuring)

frankiesardo15:02:33

I will ping the react-native channel too but I already know most of the current solutions, which are not satisfying

frankiesardo15:02:53

That's why I wondered if there's something that can be done at the language level

frankiesardo15:02:34

I was wondering if there's a js interface that can be implemented by cljs data structures to ease interop

justinlee16:02:28

it would be pretty neat to have a js interface to cljs structures. this does pop up on the browser sometimes when using callback oriented higher order functions like react-dnd

gklijs15:02:39

@frankie not sure about the performance/ImmutableJs, know to little about js for it. But I do like to keep the js stuff in separate namespaces as much as possible to avoid confusion. Maybe put vanilla js and cljs components in a different namespace will solve some of the confusion?

frankiesardo15:02:41

Not really, in the ReactNative world js and cljs component have to interact with one another quite frequently

frankiesardo15:02:43

The typical example is a react ListView that takes a renderer (a simple cljs function) but it will call the renderer passing in a js map (so no chance to use destructuring)

frankiesardo15:02:36

Anything under react-navigation is quite awkward to use if you don't rely on implicit js transformation done by e.g. reagent

joelsanchez15:02:17

why not wrapping ListView (and the other components)? in your wrapper you could call the renderer passing a cljs map

frankiesardo16:02:53

@U5LPUJ7AP sure, but then you have to maintain wrappers to all React components, which are numerous and because it's js land, change quite frequently from one version to the other

frankiesardo16:02:48

Plus, there's no standard way of wrapping them (because of the fragmentation of om, reagent and rum) so it's likely the effort one does to wrap them for reagent it's useless for rum users etc.

joelsanchez16:02:13

just choose one and the others can use the reagent/adapt-react-class equivalent

justinlee16:02:51

that only really helps if you fix the callback. the point is every time you use one of these callback-style interfaces (which exist in dom land too, btw), you end up having to write a call back that deals with js data in a very confusing way. i’m not sure it is solvable, really. i don’t see how wrapping helps.

joelsanchez16:02:28

(defn ListView [renderer]
  (js/ListView #js{:renderer #(clj->js (renderer (js->clj %)))}))

(defn example-renderer [v]
  ;; v is clj, return value is also clj
  )

joelsanchez16:02:45

same for DOM, wrap the fn

joelsanchez16:02:10

same principles apply, the first one just needs a JS object (`clj->js` will do) and a function that returns a React element (use reagent/as-element or whatever you have)

joelsanchez16:02:36

likewise, I wrote a wrapper for ReactDOM.unstable_renderSubtreeIntoContainer in Om Now, no problems whatsoever. this is a non-issue

alex-dixon15:02:12

Are there any obvious things I should look for when debugging a build of 3 files that takes > 90 seconds?

noisesmith16:02:12

@alex-dixon you could check for weird top level actions in the compile time code

alex-dixon16:02:40

When I turn on verbose I don’t see any console output for the majority of the 90 seconds…

richiardiandrea16:02:39

@alex-dixon is a performance issue you want to debug? Have you tried :compiler-stats true ?

alex-dixon16:02:01

Seems related to cljs 1.9.946

alex-dixon16:02:15

@richiardiandrea Seems like a bug or I’m doing something really wrong. I used complier stats and it outputs time info at the end…not sure if it’s supposed to yield more than that

richiardiandrea16:02:34

It yields time for each namespace iirc

alex-dixon16:02:36

It’s a build for a webworker. Not sure if that matters

richiardiandrea16:02:20

Oh, that is something I have never used so I can't suggest anything more sorry 😄

alex-dixon17:02:18

As far as I know I’m just building a js file that will be workerized though. I can’t see where anything is worker-specific

noisesmith17:02:55

@alex-dixon I guess since this is cljs there’s no chance that some top level js is getting run in the build chain?

alex-dixon17:02:59

There could be I think. I’m trying to use cljs in a worker with a react frontend, so I have a srcjs folder and a node_modules folder in the top level of the project

alex-dixon17:02:34

As far as I can tell the cljs build config isn’t referencing it though

noisesmith17:02:35

in that case, you could double check that you don’t do anything inside def

alex-dixon17:02:58

Hm ok. Well it compiles in 15 sec on 1.9.854 but ~90s with 1.9.908 or 1.9.946

noisesmith17:02:18

… interesting! you might have found a bug

alex-dixon17:02:38

In another project with more node_modules downgrading the cljs version made the build go from 240s to 80s. I still think that’s high because I’m only trying to compile ~50 lines of cljs 😕

alex-dixon17:02:03

I’m willing to file a bug even though I’ve no idea what’s really going on

dnolen17:02:26

@alex-dixon :compiler-stats true + :verbose true

dnolen17:02:49

really the former just augments the later

dnolen17:02:38

maybe you just need the new feature to ignore node_modules completely - that will be in the next release or if you’re using deps.edn you can leverage it now

sggdfgf17:02:22

Hi, who could advice a good book where all build tools (like externs, bundling, leiningen plugins, and working with npm and webpack) . Trying to solve a problem with externs... just need some RTFM 🙂

noisesmith17:02:27

@faxa I’d use the clojurescript project wiki on github as the primary source of information, leiningen is an automation tool and the lein plugin just provides an integration with build processes

dnolen17:02:38

I would try this without other tooling

p-himik17:02:50

I just tried to build my CLJS project with lein-cljsbuild "1.1.7" after I accidentally introduced a circular dependency. I hang up without any warning. Is it just me, or was it failing the build before when it encountered circular dependencies?

dnolen17:02:58

@p-himik known bug with :parallel-build

dnolen17:02:09

disable and you will get the circular build warning

mfikes18:02:41

@alex-dixon If the compiler gets "stuck" in a spot for a good 90 s, one thing you can do is kill -3 on the compiler process ID, and that will produce a thread dump and we can see what it is doing at that point in time.

noisesmith18:02:28

is that the same output you would get with jstack?

mfikes18:02:58

@noisesmith Yes, evidently so. kill -3 causes the results to go to stdout of the signalled process, while jstack appears to fetch the same info and dump it to its own stdout. 👍

thheller18:02:39

jvisualvm also works if you like GUIs

alex-dixon19:02:45

@mfikes Thanks. Will try as soon as I’m done with work. Hopefully sooner 😅

joelv20:02:59

So I've spun up a project using lein new reagent todo, when I'm in the repl from lein figwheel the arrows keys don't work they just print chars. Any work around this?

noisesmith20:02:19

newer versions of figwheel have their own readline wrapping built in - it's still experimental though

justinlee20:02:45

Oh there is also this super spiffy experimental thing but I don’t know if it works with your setup https://github.com/bhauman/rebel-readline I haven’t messed with it yet since I find the repl frustrating

noisesmith20:02:49

@lee.justin.m yeah - the latest figwheel snapshots actually use that repl

hlolli22:02:55

I need to do some vanilla application/x-www-form-urlencoded post request. Is there a way to do it programatically from cljs/js, this is my attemt so far, it's sending a payment request to an payment api

(defn pay-request [env]
  (let [form-data (new js/FormData)]
    (doseq [k (keys env)]
      (.append form-data (name k) (str (k env))))
    (js/fetch ""
              #js {"method" "POST"
                   "headers" #js {"Content-Type" "application/x-www-form-urlencoded;charset=UTF-8"}
                   "body" form-data})))
but from the network panel in devtools I can't see any registration of form data being present. Quite lost.

hlolli22:02:29

despite being in re-agent, I'd want the redirection to take place that this endpoint provides. (it's their test endpoint actually)

justinlee23:02:37

@hlolli in terms of your CLJS translation, there is nothing obviously wrong to my eye, but this github issue suggests that the fetch api doesn’t let you override the encoding type when you pass it a formdata https://github.com/github/fetch/issues/263

hlolli23:02:04

oh the FormData class seems to not to be what I'm looking for, but URLSearchParams.. try that

hlolli23:02:22

these are functions and classes I've never ever seen 🙂

justinlee23:02:29

yea me neither 🙂

hlolli23:02:33

typical Iceland, useing 20 year old technology for everything (not useing json api 🙂 ), their job offering are usually "ASP/NET is the new hot stuff".

hlolli23:02:30

I'm overthinking it, React has support for forms https://reactjs.org/docs/forms.html

mathpunk23:02:41

Here's me, misunderstanding ClojureScript and Node at the same time. Thoughts anyone? I've got a submodule of JSON files in a resources directory, I'd like to load them as maps, but so far as I know there's no equivalent of function in ClojureScript:

mathpunk23:02:58

ohwait, maybe I should be using http://lumo.io

hlolli23:02:55

(:require ["fs" :as fs]) .... (let [file-contents (fs/readFileSync "file.txt")] .. do stuff

hlolli23:02:22

this looks still right

hlolli23:02:53

I think they are going to deprecate the nonsync fs functions, some already have been I read recently.

mathpunk23:02:40

That method of requiring doesn't appear to work--- I'm using lumo, I'm really fuzzy on how lumo/planck differs from "straight" cljs in this regard

hlolli23:02:54

ah! sorry I see now 🙂

hlolli23:02:02

js/require ! not nodejs/require

hlolli23:02:59

but if you're useing recent clojurescript version you can now call js/require with (:require ["some-random-node-module" :as symbol]) the benefit being you could do (fs/readFile ..) instead of (.readFile fs ..)

hlolli23:02:31

just remember the quotes (only) when you're requireing node_module

mathpunk23:02:00

(:require ["fs" as fs]) gives me Only :as, :refer and :rename options supported in :require / :require-macros; offending spec: ["fs" as fs] at line 1 sherman/corpora.cljs, so, that does not appear to be an option in self-hosted