This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-08
Channels
- # bangalore-clj (4)
- # beginners (88)
- # boot (12)
- # cljs-dev (10)
- # cljsjs (1)
- # clojure (284)
- # clojure-denmark (2)
- # clojure-dev (35)
- # clojure-italy (8)
- # clojure-russia (36)
- # clojure-spec (38)
- # clojure-uk (51)
- # clojurescript (145)
- # cursive (6)
- # data-science (1)
- # datomic (8)
- # duct (43)
- # emacs (9)
- # figwheel (2)
- # fulcro (29)
- # graphql (1)
- # immutant (3)
- # instaparse (1)
- # jobs (1)
- # jobs-discuss (1)
- # lumo (16)
- # off-topic (50)
- # onyx (90)
- # re-frame (6)
- # reagent (20)
- # remote-jobs (3)
- # ring-swagger (18)
- # schema (8)
- # shadow-cljs (141)
- # slack-help (3)
- # spacemacs (36)
- # unrepl (7)
- # vim (1)
- # yada (2)
Hey all, trying to use polyfills, specifically https://github.com/andyearnshaw/Intl.js/, 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
I'd like to dynamically generate some variables from a map in clojurescript.
My use case is something like the joy of clojure debug code but for clojurescript.
Problem I had was that a macro writing a (def ...) doesn't evaluate the symbol for the var.
I ended up with this solution: track symbols at compile time and use list for macro which generates defs
(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
[k]
(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
[k]
`(:locals (first (get @dbg-data ~k))))
(defmacro post-mortem
[k]
(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)
m#))))
(this is basically a super simple version of https://github.com/vvvvalvalval/scope-capture (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
Hi. I'd love to use it too. Just can't seem to do even the basic things.
I'll set up an example repo. Should be quick. Last try was using "lein new figwheel"
I've setup a test repo: https://github.com/olivergeorge/can-i-spy
I'm running with lein figwheel
If I add in (sc.api/spy ...) based on the tutorial example I get the first error.
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
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.
Thanks. I'll give it a try.
You probably know this but you can arrange things to avoid that sometimes. http://blog.fikesfarm.com/posts/2016-03-01-clojurescript-macro-sugar.html
@U055DUUFS Ha, cool, will try that
Working like a charm. Thank you. Really excited to use this for debugging.
@U055DUUFS made the suggested change in the 0.1.4
release
Great. I'll give it a try.
Yesterday I finally used scope-capture in anger and it was perfect. Really nice to be able to work with local vars like that.
Thank you for making CLJS land a nicer place to be
(That link I sent you is the only documentation I know of related to that. Seems like it should be on http://clojurescript.org somewhere)
Hello all, I´ve read this https://clojurescript.org/news/2017-07-12-clojurescript-is-not-an-island-integrating-node-modules for using with this
:npm-deps {"react-md" "1.2.4"} :install-deps true
, but I didn´t understand how to use it in :require
and use it with js/ . Can anyone that used it help me to understand how to use it in clojurescript project?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
then no CORS
I should have said SPA rather than web app
this is probably it
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
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
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
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
@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
I’m looking at Bruce’s example server handler and it seems to have the hooks I need
I can add a proxy middleware
and does that integrate with figwheel?
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
ha … cool!
where are you?
I use bidi and pushy. Router and links work just fine, but external links like
keep getting me 404
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
it seems like I need some server side things to tell the server that it should always return one page
if you don't want a request to hit the server, the simplest thing is to put the changes in the fragment
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
are the links absolute or relative or protocol-relative?
if the actual text of the href is "http://my-domain.com/somepage" - 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
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?
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
(https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/stacktrace.cljc#L605-L640), 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 https://github.com/exupero/vdom ? 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
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
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
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."
I'm in the middle of a project right now that may interest you when I'm happy with it. https://github.com/Olical/bonsai 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.
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 ()
.
@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.
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.
Thanks, will check it out.