This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-01
Channels
- # aleph (4)
- # arachne (24)
- # beginners (231)
- # boot (4)
- # cider (63)
- # clara (36)
- # cljs-dev (57)
- # clojure (195)
- # clojure-dev (12)
- # clojure-gamedev (2)
- # clojure-greece (1)
- # clojure-italy (10)
- # clojure-poland (4)
- # clojure-spec (36)
- # clojure-uk (65)
- # clojurescript (133)
- # core-async (8)
- # core-logic (2)
- # cursive (18)
- # data-science (3)
- # datomic (58)
- # defnpodcast (3)
- # duct (2)
- # emacs (2)
- # fulcro (27)
- # graphql (3)
- # hoplon (18)
- # jobs (2)
- # jobs-discuss (10)
- # jobs-rus (1)
- # lumo (1)
- # mount (6)
- # nyc (2)
- # off-topic (27)
- # pedestal (13)
- # re-frame (71)
- # reagent (105)
- # reitit (4)
- # ring (2)
- # ring-swagger (1)
- # rum (10)
- # shadow-cljs (172)
- # spacemacs (24)
- # sql (26)
- # tools-deps (1)
- # uncomplicate (4)
- # unrepl (51)
- # vim (3)
- # yada (11)
How to use ajax in dev mode? If I just use relative url, then it will actually get data from http://0.0.0.0:3449/some_relative_path. But I am using django as backend, and the port should be 5555 instead of 3449, so how to write url for ajax?
If use absolution url, then I need to put domain to the url, but the domain is based on whether it's prod or qa or dev.
@wqhhust I came to the conclusion that it’s not possible. You either need to rewrite the entire url or you need to proxy your backend. I may be wrong, of course.
maybe you could just replace the port of the request URL to create the ajax and be happy
@aeudes with a jsHREF object you can use set! on the .-port property
and then put that HREF in your anchor
sadly there's no literal for it, but some code can do it
sorry, by HREF I of course mean URL https://developer.mozilla.org/en-US/docs/Web/API/URL
if you use clojure + clojuresript, the backend is clojure, the port is also NOT 3449, then how to call ajax even if using full stack clojure?
oops, I tagged the wrong person above - so to change the port on a URL you need some js or cljs code
or you can have the static absolute URL passed in (eg. if your html file is a template, the host address canbe injected as a var in a script tag)
you can create (js/URL. "//foo") that is your relative pathed url, now set the .-port property
of course put the actual path you want in that string, once you set the port it's good to use
it's cleaner than using regexes or storing the absolute path or whatever IMHO
justinlee: URL has a toString method of course
Hi, what is the best way to do (a-to-fixed-func-but-return-number 1.11512 2) ;; => 1.12
in ClojureScript?
@cmal porting precisionRound
from here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
(defn precision-round [number precision]
(let [factor (Math/pow 10 precision)]
(/ (Math/round (* number factor)) factor)))
might match what you want(defn page [ratom]
(let [a (.-location js/document)
b (string/replace a #":3449" ":5555")
]
(js/alert b)
[:div
"Welcome to test reagent-figwheel."]
)
)
Hiya. I just tried starting a new project via leiningen with lein new re-frame cljs +cider +10x +garden +re-frisk +routes
, and then running with lein figwheel dev
. upon doing this, it installed a bunch of dependencies and the then it suddenly errors out with: https://gist.github.com/3e04ee1a13642437561cde6be5d6569d
It's been a while since i've compiled clojurescript to :nodejs, are you able to use the usual clojurescript dependencies with a nodejs compilation target, or are you limited to using node_modules?
haven't used it but I would guess you should totally be able to use normal clojurescript dependencies, especially with :advanced
optimizations which will embed all of your dependencies within your final js file
that being said, the usefulness of :advanced
is rather limited with server environment
well, I was thinking of developing a barebones template for creating commandline tools with nexe
@benzap: something seems to be up with the normal requirement flow when targeting node: https://github.com/clojure/clojurescript/commit/53070a2c5392e8bdc00bb81c45034268e1cd81f2
@dchristianbell so is the current version of clojurescript broken when pulling in npm builds with the :nodejs target?
far as I can tell there are three (!) paths to pulling js libs in node projects
1. cljsjs/, in your :dependencies
. for node, my impression is that this is broken until next cljs release
2. :npm-deps, which I think works but have not tried
3. using the npm/yarn chain instead; npm install
, etc
As David said above, using node modules is still in sort of a wild west state
so I'm not quite sure enough about this for my comfort
If you look at this guide: https://clojurescript.org/guides/native-executables
Using react-router with JS/TS or some such, I can manually type in a url to a specific place in my SPA like
and have that routing happen "client-side" so that the path bar/baz renders some specific component. How can I achieve the same behavior in clojurescript? I've been playing around with secretary + accountant, and I'm just not able to replicate this behavior. I'm essentially trying to do something like: user presses sign in -> user gets redirected to github for oauth flow -> user gets redirected back to SPA at route /auth_callback?secret=params&go=here
-> SPA performs API call to backend with secret params to auth user and get a cookie I have implemented more or less exactly this flow using react-router in typescript. the crux is that react-router handles the /auth_callback
route, while in clojurescript, the redirect just gives me a figwheel error about the resource not being found.
I figured it out. The issue was with figwheel. I needed to configure it to always serve up index.html
instead of a 404. https://pez.github.io/2016/03/01/Reagent-clientside-routing-with-Bidi-and-Accountant.html
Hello, does anyone know how to add regular nodejs packages in cljs 1.8? I tried to add them to :npm { :dependencies }, but then why I try to rewrite it on my code I always get "namespace not found" :(
Hey derp, are you targeting node? I think__ you may have to do it manually, writing a package.json
and going through npm/yarn
@derpocious I'm curious, did you run lein npm install
. (I've never used lein-npm
, but just guessing.)
@derpocious It is also not clear whether lein-npm
goes beyond just making the deps available. In other words, can you use the deps in a :require
or do you need to treat them as foreign libs, or drop down to JavaScript interop to use them?
@dchristianbell yes I'm targeting node. I have a Node_modules folder, but how do I add it?
Thanks @mfikes, lein npm install doesn't seem to help
@derpocious If you are using :require
then you need to tell ClojureScript about the foreign deps, if that's the way lein-npm
works (just guessing again). In other words ClojureScript isn't going to automatically look in to the NPM deps tree
I don't know if cljs.nodejs
is in 1.8, but the source for its (node version of) require
is dead simple:
(def require (js* "require"))
Maybe lein-npm
does all this for you. I can't really contribute having never used it. Sorry.
something like ((js* "require") "module-name-here")
might work.
(and yes this is a hack, sorry)
@dchristianbell FWIW: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/nodejs.cljs#L16
just wondering, can I use :require with this in the same file to bring in my other cljs libraries as well?
in theory should I be able to call a Clojurescript function from the JS console?
Ok thanks guys. And @dchristianbell when I do module name it should be without the double quotes right?
(or well from Javascript in general)
no, the double quotes are intentional
I did some "interop" by passing some data with the window['config']
trick, but if I could call the functions directly it would be even much better
@andrea.crotti you should be able to, but you'll be typing a bunch
hehe ah yes I tried to auto complete around but could not get anywhere
project.myproject.projectnamespacebeginning.projectnamespace.ohheywefinallygotafunction.call(null, args)
hehe ok thanks
probably better generate the actual output I want and stuff it into window.config
still thene
what's the window.config trick? :)
something like: (let [resulting-data (cljs-fns input-data)] (set! (.config js/window) resulting-data))
(-> promise
(.then #(console.log %))
(.catch #(console.log %)))
@roman01la but it will return promise it self not a value... Let's say then lambda returns a number - and I want that
There’s no way to “unwrap” JS Promise
I usually use Deferred objects for that purpose
@dnolen I think I found a bug in the node module indexing indeed. I think it reports package.json -> "module" -> "index.mjs"
as index.js
(which may not even exist) instead of index.mjs
. Still investigating though with a help of a test in cljs.closure-tests
.
Although, this is what it generates for iterall
, which has an index.mjs
:
{:file
"/Users/jannis/Work/personal/groom-npm-deps/node_modules/iterall/index.mjs",
:module-type :es6,
:provides ["iterall" "iterall/index.mjs" "iterall/index.mjs"]}
That looks ok, even if the last item could maybe be iterall/index
instead (it does that if the main entry is index.js
).
However, the resulting cljs_deps.js
only has:
goog.addDependency("../foo/core.js", ['foo.core'], ['cljs.core', 'iterall']);
and no additional lines for iterall
. That part looks wrong.ah that's better than mine @dchristianbell I just did
client-side-config (json/write-str (assoc config
:language language))
;; and then
[:body
[:script (format "window['config']=%s" client-side-config)]
@roman01la just found your youtube channel 🙂 nice!
but well I think it's not exactly the same thing, with "my trick" I can share stuff from the backend to the JS directly
guys, can someone help me to resolve an error that I’m getting please. I’m new to cljs, when I try to run my tests in repl with (cljs.test/run-tests), I’m getting #object[TypeError TypeError: undefined is not an object (evaluating ‘cljs.test.run_block’)] error
im not allowed to share the code 😞 I can give you the details of my setup, what would you need to know?
"undefined is not an object". You are trying to call a property or method of something that is undefined
Does it give you a line number?
@anelkudebayeva You want to check if you are accessing all the fields of an object that are defined.
@faxa everything compiles with no errors or warnings, these tests also run without any issue in clojure repl, so I’m assuming it has something to do with cljs repl?
@anelkudebayeva in clojurescript as oposite clojure libs will be different
umm well its clojurescript that im trying to test but those functions are essentially equivalent in clojure, so I ran a quick test in clojure and it worked
Is there a way for me to compile with advanced optimization and include node_modules in that output?
Or somehow specify a destination for node_modules? I'm building multiple cljs pieces, and I don't want them all sharing the same node_modules (which I'll have to copy with the output for it to work).
I'd rather not have every one of them required the node dependencies of every other piece.
@ghopper If you're using closure modules I can't help you because I don't know much about that, but if you're defining separate builds you can use :foreign-libs for that.
Well, I'm using :npm-deps with :install-deps. I'm not familiar with :foreign-libs.
I'm using boot, so perhaps I could get it to run the cljs compilation from a different directory to make :install-deps install in a different directory?
That seems plausible. My understanding is that npm-deps is basically shorthand for foreign libs, so using different builds w/ different npm deps might work.
The problem is I'm not sure how to get boot-cljs to compile from a different directory.
Interesting, I thought foreign-libs was completely different.
I've got a problem where a foreign-lib is included twice in the output javascript. Example project here: https://github.com/tomconnors/problems/blob/reagent-preact/project.clj. preact-compat is included twice in the prd build's out. Is this a known issue?
So, are foreign-libs never advanced optimized?
it’s referred to in cljs.core, but I can’t see where it comes from (and it causes an error for me)
@ghopper They're just prepended to the output file. Pretty sure they get :simple optimizations.
@quoll it's a reader, and those errors typically mean something is using an older version of the clojurescript reader
Updated versions of things, cleaned and recompiled, and it worked. Thanks @noisesmith
@quoll: I think it comes from here, if you're still curious https://github.com/clojure/tools.reader/blob/9d1f2634b43daa307d0290a42c3a0e02c590b64f/src/main/clojure/clojure/tools/reader/edn.clj#L322
well - the thing I linked is clojure code, technically, heh
it's just the clojure code that happens to turn cljs into js
I'm sure bootstrapped cljs has the same thing from some other place