Fork me on GitHub
#clojurescript
<
2017-09-09
>
ajpierce13:09:53

Hey gang, I'm trying to import an ES6 class (React component) directly into clojurescript, and i'm getting a Uncaught SyntaxError: Unexpected token import error in the console after import. Here's what I've done: 1. drop the library and its dependencies inside the src/ folder of my cljs project 2. Add :foreign-libs to my cljsbuilds in project.clj 3. :require the foreign ES6 library in my core.cljs file Haven't tried rendering it or anything, just doesn't seem to like the ES6 style import JS syntax. Am I missing something? Or is importing ES6 classes not supported yet?

dnolen13:09:19

@ajpierce you need to set :module-type pretty sure

ajpierce13:09:35

Tried :preprocess :jsx with no luck

dnolen13:09:46

:preprocess :jsx isn’t a thing

dnolen13:09:51

unless you’ve set that up yourself

dnolen14:09:42

we don’t have a way to infer JS modules types really - you must be explicit

ajpierce14:09:43

so :module-type :es6 ?

dnolen14:09:23

and if you want this to generate code for non-ES6 JS environments - you need to set :language-out

dnolen14:09:48

(only applies to compilation levels higher than :none though)

ajpierce14:09:00

awesome, thanks David!

ajpierce14:09:26

Getting JSC parse errors now so i am on the right track :thumbsup:

Kevin Casey15:09:51

I want to fix a minor problem on https://clojurescript.org does the site have its own git repo? is a JIRA ticket needed?

johanmynhardt15:09:28

@lxsameer cljs. I know, but none of the examples I found even mention configuration for using the fragment. I did try to configure it with hashes and even tried regex.

noisesmith15:09:11

@johanmynhardt I don't use bidi, but what I do is extract the part of the route I care about before handing it to the router function, using the native js methods to get the fragment out of the location of the url

johanmynhardt16:09:51

@noisesmith interesting. But that then won't allow me to use the capability of bidi to generate links from the defined app-routes. I forgot to mention that I'm still learning a lot, so I might need to fill in some gaps 🙂

noisesmith16:09:29

if you do it that way, can't it just return the fragment part of the route?

johanmynhardt16:09:02

It does that, if I understand your question correctly. For example, for say, 'about', at route /about, it generates href="/about", not the absolute URL.

johanmynhardt16:09:33

I'll just dig deeper, I can not imagine that no #-based routing is available in bidi, it's quite powerful

noisesmith16:09:35

oh, if it didn't generate the href= part, you could just fix it with a string concat

johanmynhardt16:09:07

Hmm, think we are not on the same page. I have the function: (defn route-for [page] (bidi/path-for routing-sandbox.core/app-routes page)) which I can use to populate a link like so: [:a {:href (route-for :about)} "About"]

johanmynhardt16:09:39

(A reagent-based app)

noisesmith16:09:38

you said: > it generates href="/about", I assumed you meant the bidi function generated that text

noisesmith16:09:11

if it just returns "/about" it's trivial to put a # in front

noisesmith16:09:01

the thing to remember is that http doesn't treat anything after # as a route - it's literally free-for-all

noisesmith16:09:00

I actually have a mode in my app that generates urls that look like app/#/network {:id "akasdfjoi" :focus "insiders" :graph "open"} - no need to escape any of it, you can simply put edn in there and it works

noisesmith16:09:31

(the normal mode turns that into an obfuscated "normal" looking url from which the same data can be extracted, but that's handy for dev mode)

johanmynhardt16:09:47

I get that, but just out of the box I couldn't get bidi to recognise the path when a hash is present. Even in the config. So it would generate a link with /#/about, but clicking on it won't resolve, basically not making it proper bidirectional if I would then have to hack around to make it work.

johanmynhardt16:09:11

I tried variants of ["#/" ["about" :about]], ["/#" ["/about" :about]], ["/#/" ["about" :about]], for example

stvnmllr216:09:20

Anyone still use clojure for webdriver tests?

noisesmith16:09:01

@johanmynhardt aren't you in a position where you could wrap both the generated URLs and the route lookup?

noisesmith16:09:41

at least how I've always done it is passing some function to goog.history, you could pass a wrapped function instead of the bidi function directly

noisesmith16:09:04

but maybe bidi supports fragment based single page routing, I have no idea

johanmynhardt16:09:29

Yeah, I'll have to dig around. I can work with it like it is now, but it is going to be a problem if I have to deploy at a sub context (`/some-context/my-app-here`). Hmm, I guess setting the base path in HTML would solve it.

johanmynhardt16:09:41

Anyway, thank you for your input @noisesmith, I appreciate

noisesmith16:09:35

if I was doing both http routing and treating the fragment as SPA routing, I'd be tempted to have separate mechanisms for the two instead of mixing them in one router

noisesmith16:09:26

I'm experienced with this stuff (have had a cljs app in production for a couple years) but not an expert though, perhaps there's a smarter solution

sundarj16:09:35

if you have control over the server, rather than rewriting everything to /, you could rewrite only /some-context right?

noisesmith17:09:58

anything after /# never gets seen by the server, it's only visible internally to things running in the browser

noisesmith17:09:43

that's why there's no rules for the contents

sundarj17:09:26

ah, i thought he was talking about using HTML5 routing

juanjo.lenero21:09:29

Is there a simple way to have autocomplete and history in figwheel’s repl?

juanjo.lenero21:09:55

I tried to integrate with cider and nrepl but failed miserably

jumar13:09:40

@U6KUNRBB6 I'd recommend to try to make it work with Cider. Recently, I came back to clojurescript and my current workflow is to do just cider-jack-in and then from repl:

(use 'figwheel-sidecar.repl-api)

(start-figwheel!)

(cljs-repl)
If you want to use both clj and cljs REPLs than you can do the final step (cljs-repl) in the separate "repl" opened via cider-connect

juanjo.lenero21:09:17

But I could live with basic auto complete or at the very least last-item entered.

juanjo.lenero21:09:38

In cider/nrepl I can hit alt-up/up to bring up previous input and the left/right arrow keys to move arround entered text.

juanjo.lenero21:09:11

but in figwheel’s repl alt or arrow keys but result in control characters printed to the terminal

juanjo.lenero21:09:03

I fixed the arrows -> control characters issue with rlwrap

juanjo.lenero21:09:20

I installed it via hombrew brew install rlwrap

juanjo.lenero21:09:36

then rlwrap lein figwheel