Fork me on GitHub

Hey all, trying to use polyfills, specifically, from npm with CLJS in a cljc file. I am requiring with the form

(ns time-align.utilities
  (:require [clojure.string :as string]
            #?(:cljs [cljsjs.moment-timezone])
            #?(:clj [java-time :as t])
            [clojure.pprint :refer [pprint]]
            #?(:cljs [intl :refer [Intl]])
and am wondering why when I load the page I get the error Error: Undefined nameToPath for intl


I googled around a bit and wasn't able to find anything alluding to a fix so any ideas would be greatly appreciated

Oliver George04:11:32

I'd like to dynamically generate some variables from a map in clojurescript.

Oliver George04:11:12

My use case is something like the joy of clojure debug code but for clojurescript.

Oliver George04:11:38

Problem I had was that a macro writing a (def ...) doesn't evaluate the symbol for the var.

Oliver George04:11:06

I ended up with this solution: track symbols at compile time and use list for macro which generates defs

Oliver George04:11:08

(ns can-i-spy.dbg
  (:require [clojure.spec.alpha :as s]))

(declare dbg-meta)

#?(:clj (defonce dbg-meta (atom {})))

#?(:cljs (defonce dbg-data (atom {})))

(defmacro spy
  (let [symbols (keys (:locals &env))
        locals (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)
        location (-> &form meta)]
    (swap! dbg-meta update k conj {:location location :symbols symbols})
    `(do (swap! dbg-data update ~k conj {:location ~location :locals ~locals}) nil)))

(defmacro locals
  `(:locals (first (get @dbg-data ~k))))

(defmacro post-mortem
  (let [{:keys [symbols location] :as data} (first (get @dbg-meta k))
        def-sym (fn [sym]
                  `(let [m# (first (get @dbg-data ~k))
                         val# (get (:locals m#) '~sym)]
                     (def ~sym val#)))]
    (s/assert (s/coll-of symbol?) symbols)
    (s/assert map? location)
    `(let [m# (first (get @dbg-data ~k))]
       (do (println "Set up post-mortem of line" (:line (:location m#)) "of" (:file (:location m#)))
           (println "Symbols: " ~(pr-str symbols))
           ~@(map def-sym symbols)

Oliver George04:11:54

(this is basically a super simple version of (can't get that to work in my cljs environment)


@U055DUUFS Can you tell me more about your CLJS environment? I'd like to help you get it to work 🙂


I've been planning to add more documentation to ease CLJS setup, this kind of real-world feedback would be super useful

Oliver George09:11:35

Hi. I'd love to use it too. Just can't seem to do even the basic things.

Oliver George09:11:56

I'll set up an example repo. Should be quick. Last try was using "lein new figwheel"

Oliver George09:11:48

I'm running with lein figwheel

Oliver George09:11:05

If I add in (sc.api/spy ...) based on the tutorial example I get the first error.

Oliver George09:11:34

api.cljc?rel=1510132767767:10 Uncaught Error: Invalid arity: -1
    at sc$api$spy (api.cljc?rel=1510132767767:10)
    at core.cljs?rel=1510133529150:27
    at core.cljs?rel=1510133529150:40

Oliver George09:11:46

I've pushed a third commit which generates that error.


@U055DUUFS thanks, will have a look and come back to you.


@U055DUUFS I made a pull request that fixes the issue in your project. The problem was that, since spy is a macro, you need to require it with special CLJS syntax for macro, e.g (:require [sc.api :include-macros true])


I realize it may not be obvious from scope-capture's README; I plan to include some example projects (including Figwheel) to show how to add scope-capture to a project (using a Github diff). Hopefully that with smooth off the rough edges.

Oliver George20:11:23

Thanks. I'll give it a try.

Oliver George21:11:38

You probably know this but you can arrange things to avoid that sometimes.


@U055DUUFS Ha, cool, will try that

Oliver George23:11:02

Working like a charm. Thank you. Really excited to use this for debugging.


@U055DUUFS made the suggested change in the 0.1.4 release

Oliver George23:11:20

Great. I'll give it a try.

Oliver George23:11:47

Yesterday I finally used scope-capture in anger and it was perfect. Really nice to be able to work with local vars like that.

Oliver George23:11:58

Thank you for making CLJS land a nicer place to be

Oliver George23:11:38

(That link I sent you is the only documentation I know of related to that. Seems like it should be on somewhere)


Hello all, I´ve read this for using with this

:npm-deps {"react-md" "1.2.4"} :install-deps true
, but I didn´t understand how to use it in
and use it with js/ . Can anyone that used it help me to understand how to use it in clojurescript project?


(:require ["react-md" :as md]) … then in your code md/thing, eg. md/Card


Anyone using libs from nervous-systems? Eg fink-nottle, cljs-lambda, etc


Hey there, in case someone knows how to debug this: A clojure macro occasionally causes a cljs compilation error. This macro requires cljs-react-test.simulate (a clojure namesmapce). That normally works, but I get a compilation error once in a while. When it fails, (require '[cljs-react-test.simulate :as sim-clojure]) in JVM clojure repl will fail: CompilerException java.lang.Exception: namespace 'cljs-react-test.simulate' not found, compiling:(*cider-repl horizon*:8:41) Even in those cases when it fails, cljs-react-test/cljs-react-test/0.1.4-SNAPSHOT is in the classpath (checked via ps aux). That's the most puzzling part - how come you cannot require a plain Clojure ns that is in the classpath?


looking for some advice (lazy me) on what folks do to avoid CORS issues when running on localhost


is there a simple proxy for serving web apps / routing to the localhost server?


[ this is a well-known / supported nodejs pattern ]


I want to avoid CORS entirely … the deployed app will be on the same domain as the server


(served from S3, routed to app via CF if you want the messy details :)


so the goal is for the browser SPA to communicate back to a proxy that then forwards the requests to the localhost server


I should have said SPA rather than web app


this is probably it


does anyone know how the :output-to and :output-dir paths work?


i'm trying to set up figwheel with nodejs, but the temp files end up pointing to the wrong thing, like if it's :output-dir "backend/out", it'll complain that it can't find some goog file in /../backend/out/backend/out/...


i don't know what i'm doing wrong.. i looked at the docs but i don't know how clojure (or figwheel) is resolving paths



:output-to "backend/backend.js",
:output-dir "backend"


also seems like figwheel has the option to install a :ring-handler so that should be perfect …. anyone else using figwheel like that?


@fbielejec that's what I have right now, but it doesn't work


@risto try adding

:target :nodejs
:optimizations :none
:source-map true


yeah I have those too


I copied it from a smaller example I have that's working, so I have no idea why it doesn't work in this case


the names are just different


do you have :source-paths ["src"] defined?


this is what I have:

{:id "backend-dev"
                :source-paths ["backend"]
                :figwheel true
                :compiler {:main avcado.server.core
                           :output-to "backend_out/foo.js"
                           :output-dir "backend_out"
                           ;:foreign-libs [{:file "backend/src"
                           ;                :module-type :commonjs}]
                           :target :nodejs
                           :optimizations :none
                           :source-map true }}


@raymcdermott sorry, commomly we like to handle not to avoid 😞


with backend/avcado/server/core.cljs being a hello world thing w/ ns avcado.server.core


you sources paths points to a wrong dir


@lovuikeng np … in my case I control the client and the server so I don’t need / want to fuss with CORS


@risto move it outside of :cljsbuild and point to "src", I'm assuming you're using a default name


@raymcdermott I used a compojure handler in a figwheel for a while, what do you need to know?


we ditched it though and just have an nginx server build by docker-compose to have a production-like environment


i have a simple hello world app that looks almost the same and works fine, i'm wondering why it's different in this case


why does it need to point to "src"? the example im copying from points to "server_src" and works ok


we have that too … problem is that if you serve via figwheel and make AJAX requests to localhost:5000 you get CORS errors


how do you avoid that on a local box?


or do you serve from the NGINX?


we (in prod) will serve from S3


right now we serve /resources/public from nginx


I’m looking at Bruce’s example server handler and it seems to have the hooks I need


I can add a proxy middleware


you can mount /resources/public, define nginx server and pretend it's S3


works quite well


and does that integrate with figwheel?


it's actually parallel to figwheel


figwheelwill still react to changes and update the compiled sources


ok I see … I think I’m going to futz around with the figwheel only solution first but might hit you up if I run out of road … thanks for the support


I'll be on 15 at functional Leuven meetup 😉


where are you?


hi everyone!


could anyone please help me with routing?


I use bidi and pushy. Router and links work just fine, but external links like keep getting me 404


it seems like I can get to pages inside my app only


how do I get external links to work? It's also popular topic in react


how would you route a url that doesn't point at your app? are you trying to redirect or link out to other pages and failing?


like, a url that isn't in your app should never hit your app's router


figured out the issue, i wasn't running it from the project root, so the path wasn't resolving properly


assume that is my app, but any other links is 404 even if they work. It seems like that's popular client-side routing issue


@risto yep, that's that


it seems like I need some server side things to tell the server that it should always return one page


and not to look up for any other


but then any external link will lead to the home page


if you don't want a request to hit the server, the simplest thing is to put the changes in the fragment


i need to pass the whole path to my client-side router some way?


otherwise you need javascript hacks to override what changing the url does


the http spec says changes after a # in the url don't invoke requests to the server, so many of us address this by putting all routing changes that are meant to stay in-app in that fragment


yes, but my links work just fine inside my app


but only inside my app. Any external link is getting me 404


are the links absolute or relative or protocol-relative?


if the actual text of the href is "" - that looks like a broken relative link to me


i don't know. If I have the link to somepage in my app, it works just fine and there's actual text in address bar


but is I type it, it doesn't work, and figwheel is getting me 404


sounds like goog.history or some other browser bar related lib is being used incorrectly - maybe someone else has experienced the issue and can help more?


i thought that goog.history was incapsulated by pushy or bidi


OK - sure - but it sounds to me like it's being misused (or you need some backend help to make this case work) - I avoided all these issues by not doing any url bar magic, using # for all in-app routing. if in-app routing is overriding the usual usage of the url bar, then to support typing into the url bar or even someone hitting refresh or bookmarking, you need to support that on the back end surely


yeah to have the app use normal urls you need a route on the server like GET * -> index.html


when we designed our app, I made our first priority that hitting refresh, or the back button, or using a bookmark, would always work


because it's easier to maintain that from the start, than it is to take a system where those things are broken and make it work


Hello everybody, I'm looking for possible solutions to handle document meta/head/title tags, dynamically. Either from reagent components and maybe on specific events. Basically researching the topic


@melvoloskov Yeah, when using pushy you still need the server to route all requests to where your app lives. Netlify (no affiliation) is a static site hosting where you can do this nicely and easily, if you have a static site SPA that just talks to different apis and no traditional server. For local dev you can use compojure with (GET "*" [] ,,,).


I'm trying to track down where *target* might be getting redefined. I'm compiling with :target :nodejs, yet in finding *target* to be "default" when testing. :optimizations is :none


grepping the code for *target* (both the clojurescript source and the project code) doesn't reveal any assignments/rebindings from what I can see.


looking at cljs.stacktrace/mapped-stacktrace (, it's arguments are stacktrace (AIUI, a stacktrace parsed via parse-stacktrace), and sms, which appears to mean "source-maps". I'm looking for clarity on this second sms argument: how do I (dynamically, at runtime) determine the appropriate value of sms?


is anyone here aware of ? It only seems to do one thing (rendering) rather than more than one (rendering, state management); seems like a less complected alternative to reagent or om.


@bcbradley I think you're right in thinking it might be less complected. Is there a reason you don't find the state management aspects of om/reagent compelling?


@grzm i did like reagent's ratoms at first glance but If I have to be honest with myself i tend to think that clojure already has terrific ways in the core language to manage state and keep it from making things complex on you


I think one of the other value propositions for om/reagent is that they're building on React, which has a very active community. If you don't find that attractive, I see no reason why you shouldn't try to build on vdom instead.


I like React for its active community too, but some of the things React has done were inspired by clojure


at first they tried making all React components just basic objects that inherit from a base class


and with local state-- a very object oriented approach to things


Clojurescript demonstrated through Om that they could be faster with React that javascript could be, because all state could be pulled up into an immutable data structure at the top level


so the React community mimicked that, and added "functional components"


Reagent actually does something React doesn't do-- it doesn't encourage you to collect your state in one place at the top level in an immutable data structure-- it offers you ways to spread state throughout your program in Ratoms, and then have the views update automatically based on when and how those ratoms change


I feel like everyone is missing the forest for the trees


the only reason we had to create React in the first place is because the stateful nature of the browser Dom makes it error prone to work with. The only reason the Dom exists the way it does is because when it was created people thought the answer to the question "Can't we just create a new Dom every time something changes?" was "No, that is too inefficient."


We should revisit that question, and I think that is what v-dom actually does.


I'm in the middle of a project right now that may interest you when I'm happy with it. It's not a virtual DOM, it's a declarative data -> DOM renderer with some basic hooks into some state management, but with room for you to ignore it or apply your own opinions. It'll be a while before I'm done yet, but it's the tool I want to use within ClojureScript.


It looks pretty interesting!


Hi Everyone, is there something obvious I am overlooking when comparing the result of (apply interleave [[1 2 3]]) across Clojure and ClojureScript? Clojure returns (1 2 3) as I would expect but ClojureScript returns ().


cljs also return (1 2 3)


i get (1 2 3) as well


@bcbradley As I understand it, both reagent and om pretty much only utilize React's rendering and add state management on top of that. So to me it looks like the question you want to answer is what state management you'd like, and whether you prefer React's rendering over vdom's.


Thanks @thheller @dpsutton, what version of ClojureScript?


I'm on 1.9.908 and it's working for me as well


what version are you on?


Not sure why but I was using 1.9.93, bumping to 1.9.908 fixes the issue.


I did try bumping to 1.9.946 but got some issues with ##NaN reader literals.


probably an old conflicting tools.reader dep, core.async is a common cause


Thanks, will check it out.


easy fix is just adding [org.clojure/tools.reader "1.1.1"] to your deps