This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-09
Channels
- # beginners (376)
- # cider (7)
- # cljs-dev (4)
- # clojure (96)
- # clojure-dev (7)
- # clojure-finland (2)
- # clojure-spec (1)
- # clojure-uk (15)
- # clojurescript (54)
- # cryogen (1)
- # defnpodcast (2)
- # docs (4)
- # emacs (1)
- # fulcro (2)
- # hoplon (15)
- # lumo (19)
- # off-topic (28)
- # om (3)
- # pedestal (2)
- # portkey (6)
- # proton (2)
- # re-frame (34)
- # reagent (4)
- # ring (3)
- # spacemacs (5)
- # unrepl (3)
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?
looks like i should have read https://clojurescript.org/reference/javascript-library-preprocessing more carefully 😉
and if you want this to generate code for non-ES6 JS environments - you need to set :language-out
I want to fix a minor problem on https://clojurescript.org does the site have its own git repo? is a JIRA ticket needed?
thank you
@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.
@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
@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 🙂
if you do it that way, can't it just return the fragment part of the route?
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.
I'll just dig deeper, I can not imagine that no #-based routing is available in bidi, it's quite powerful
oh, if it didn't generate the href=
part, you could just fix it with a string concat
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"]
(A reagent-based app)
you said:
> it generates href="/about"
,
I assumed you meant the bidi function generated that text
if it just returns "/about" it's trivial to put a #
in front
the thing to remember is that http doesn't treat anything after # as a route - it's literally free-for-all
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
(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)
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.
I tried variants of ["#/" ["about" :about]]
, ["/#" ["/about" :about]]
, ["/#/" ["about" :about]]
, for example
@johanmynhardt aren't you in a position where you could wrap both the generated URLs and the route lookup?
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
but maybe bidi supports fragment based single page routing, I have no idea
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.
Anyway, thank you for your input @noisesmith, I appreciate
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
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
if you have control over the server, rather than rewriting everything to /, you could rewrite only /some-context
right?
anything after /# never gets seen by the server, it's only visible internally to things running in the browser
that's why there's no rules for the contents
Is there a simple way to have autocomplete and history in figwheel’s repl?
I tried to integrate with cider and nrepl but failed miserably
@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
But I could live with basic auto complete or at the very least last-item entered.
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.
but in figwheel’s repl alt or arrow keys but result in control characters printed to the terminal
I fixed the arrows -> control characters issue with rlwrap
I installed it via hombrew brew install rlwrap
then rlwrap lein figwheel