This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-01
Channels
- # aleph (2)
- # beginners (137)
- # boot (4)
- # cider (10)
- # clara (29)
- # cljs-dev (71)
- # cljsrn (7)
- # clojure (105)
- # clojure-bangladesh (1)
- # clojure-france (2)
- # clojure-italy (4)
- # clojure-nl (3)
- # clojure-russia (1)
- # clojure-spec (30)
- # clojure-sweden (5)
- # clojure-uk (71)
- # clojurescript (217)
- # cursive (36)
- # data-science (1)
- # datomic (11)
- # duct (53)
- # fulcro (2)
- # garden (3)
- # jobs (1)
- # lein-figwheel (23)
- # luminus (3)
- # lumo (7)
- # mount (13)
- # off-topic (88)
- # pedestal (3)
- # re-frame (63)
- # reagent (85)
- # remote-jobs (1)
- # ring-swagger (3)
- # shadow-cljs (81)
- # spacemacs (5)
- # tools-deps (16)
- # yada (2)
hello folks, anyone knows how to print a function name in clojurescript for browser? name
and var
won’t work.
interestingly, (.toString function-x)
prints the whole function code whereas i’m only interested in its name (for logging)
@michael.heuberger if you just want to log it then why not just quote the function. (.toString (quote func-name))
thanks guys, will check out both suggestions after the weekend (new zealand here)
Hello, just wondering if there was some article I could read about best practises around where to put files in your clojure/clojurescript project. Like where do I put cljs, cljc, clj. I just want to read an article because I'm bad at making up my mind 🙂
@djwelch666 I just keep everything in src/main
which already "group" everything by namespace. no need to group by extension.
@djwelch666 I do have src/cljs
, src/clj
and src/cljc
, because the frontend and backend don't have much code overlap. mixing them is not impossible but not very positive either (in my case)
I have seen src/cljs, as well as src-cljs. I guess there is no real difference
yeah, cheers
Does anybody else develop a shared react / react-native app here? How do you handle differences? reader - features seem to be out for this use case ...
I haven’t developed anything, but I’m pretty sure that https://github.com/necolas/react-native-web is the best shot at that
@bendlas you may not be able to share that much actual UI code
Sharing actual functions between react-dom and react-native is not a primary goal of RN AFAIK
But of course you can share all the helper libraries
Chances are your native UI will be different from the Web UI
OK, please get me right, I'm not looking for basic answers, I've been developing with Cljs for several years, and I think I had one of the first commercial applications out with it ...
Yeah as I see it the question poses itself for React (JS) as well as for CLJS
our primary use case is sharing sharing functionality. sharing ui code is a secondary / non - goal
The answer will be pretty similar — separate code into platform-specific and shared business logic
I've been working on shared react-native and react-dom code bases for a few years, so if you have more specific questions lmk
but i want a solution for almost-equal namespaces, that have different :require
clauses. everything else is pretty much taken care of
possibility 1: two source directories with different classpaths
@dnolen has declined my ticket due to missing previous discussussion: https://dev.clojure.org/jira/browse/CLJS-2396
possibility 2: write code in such a way that it doesn't blow up at NS init time
e.g.: (def react (if (on-react-native?) (js/require "react-native") (js/require "react-native-web")))
and the list conv doesn't seem to be going anywhere https://groups.google.com/d/topic/clojure-dev/8YJJM8lJuQs/discussion
avoid things like (def platform-specific-comp (r/adapt-react-class js/PlatformSpecificComp))
@pesterhazy I'm doing 2) as much as possible, but it's not for require
clauses
if the "require"s in the ns declaration blow up because of missing npm deps, avoid those in favor of using js/require
directly
you can build shared RN / react-doc namespaces that way
@pesterhazy yeah, that's what I'm doing anyway, since too much read-cond gets confusing as well
but at least the entry point still needs to be overlayed from separate source directories then ...
@dnolen how do you feel about making the reader in cljs swappable? that's not something we would need to wait on clojure for ...
so you're telling me, that I would, in fact, need to do significant development work, in order to feed data structures to a lisp compiler (and cover all the tooling cases)?
but I also know other people have likely encountered this problem and worked around it without futzing with reader capability
multiple source-dirs for multiple entry points has worked well for me in the past
re the reader, the concern from Rich from the beginning was to avoid creating Clojure(Script) code that is unreadable by other users. Being able to swap out the whole reader would open that scenario so I don’t think Rich would be on board with that.
same reason we don’t have reader macros
I still think it could be easier to use just the compiler (with a custom reader) without making that problem worse
I understand the pain people are encountering here - but it’s same pain in any programming language
> so why such a big hammer for such a well defined problem to be fair, what other problem did read-cond solve for clojure?
cross-platform portability
.. which is exactly what I'd like to use it for. only with extensible definition of platform
well it’s the extensibility that caused a lot of complexity in the implementation which is why we backed down to just platform level.
The design page lists something very complex indeed under the label extensibility
. Also boolean combinators. I'm not interested in the former one and only slightly in the latter.
The thing I'm interested in, configurable compiler :features
, doesn't seem that complex besides those ...
I will certainly look it over such a proposal, provide feeback and see if I have further comments/ideas
but even if I did, I don’t have issues w/ managing the classpath, writing some redundant files or whatever
@dnolen I'll try to come up with something, but there are only so many eyelet to hook into
fwiw I already had this discussion with Rich and our conclusion was that managing the classpath was fine in many cases
all the cases i've been finding could be solved with distinct namespaces. the best solution for this one seems to be overlaying namespaces ...
well, I guess I'll be looking into shadow-cljs, until more users become vocal on this, and / or someone on the core team has a personal need 😉
yes, shadow-cljs does lots of cool things we’re not necessarily interested in (yet) - so this seems like a perfectly fine solution to me!
@dnolen @alexmiller I'm just looking at the latest State of Clojure
, because I want to know, how many people are doing what I'm doing (shared web/native). Didn't find anything about that ... do you have any idea about that?
I do suspect shadow-cljs usage to get a huge boost in the next survey given the large influx of JS users
hah, that's a whole separate chapter ... am I right with my perception, that the main problem seems to be gclosure lacking the ability to apply :simple
to npm deps, while compiling the rest with :advanced
?
there was one question about targeting React Native I think ?
yeah, 19.5% said they were targeting React Native
but just not feeling rushed - there’s already tons of users and legacy code bases doing things the previous way
I can see this being dirty the solution bendlas is suggesting with the reader. Offering no solution, but I could see how seperating native platforms would be nice. I'm now working with Samsung Tizen and Amazon FireTv, they both offer custom chromium browsers that can do some custom stuff. Never did rn, so not sure if it's comparable 🙂
well, most platform differences can easily be handled by :closure-defines
+ if
. I'm concerned about the remaining cases, where you want to :require
different namespaces based on platform ...
requireing platform specific plugin, geolocation in cordova-toast will only work on Tizen platform.
but this isn't a problem for me, just thinking out loud about potential cleaner code in the future.
all in all this was bit badly thought comment, don't do React Native, just React, so don't know how this applies. Support for reader macros on various native platforms sounds good. But I have no slightest idea what implications that has from the bigger picture, so I stay out of it.
I'm trying to compile a minimal program with the cljs.main and target node. It does not work. Am I doing something wrong? https://github.com/lgrapenthin/cljs-main-node-problem
@leongrapenthin you need to specify "-re node"
This is what I use
{:deps {org.clojure/clojurescript {:mvn/version "1.10.238"}}
:aliases
{:prod
{:main-opts ["-m" "cljs.main"
"--optimizations" "simple"
"-o" "compiled-prod.js"
"--compile" "foo.prod"]}
:watch
{:main-opts ["-m" "cljs.main"
"--target" "node"
"-o" "compiled-dev.js"
"--watch" "src"
"--compile" "foo.devserver"]}
:repl
{:main-opts ["-m" "cljs.main"
"--repl-env" "node"
"--repl"]}}}
@bhauman But I don't want a repl environment
I'm not using clojurescript to pull in NPM deps. Instead I just add them to package.json (and yarn install
). To make that work from the repl I use NODE_PATH="$PWD/node_modules" clj -M:repl
since i'm using exactly the command line from the quickstart i'm wondering if I'm doing sth. else wrong
@leongrapenthin not sure if that will work without master
@dnolen thanks, I'll try master
@dnolen can confirm its working on master
@pesterhazy if you are watching you may want to try figwheel.main
https://github.com/bhauman/lein-figwheel/tree/master/figwheel-main
I get Exception in thread "main" clojure.lang.ExceptionInfo: Couldn't read the file:figwheel-main.edn {:figwheel.main/error true}
clj -Sdeps "{:deps {com.bhauman/figwheel-main {:mvn/version \"0.1.0-SNAPSHOT\"}}}}" -m figwheel.main
being able to compose dev stuff in ~/.clojure
with project local stuff is so much better
@bhauman looks cool, I'll check it out
for node I'm just using doall clj -M:watch -- nodemon dev-compiled.js
, where doall
is https://gist.github.com/pesterhazy/9020617ade9c93c3cccd9748f76dbe01
it just restarts the node process whenever the cljs compilation produces a new output file
it's useful to bundle everything into a single script that you can ask people to run
right for the browser where you have a lot of state hotloading is obviously superior. I'm excited to give it a try next week
can anyone recommend a library for dealing with in-memory graph-like data in clojurescript?
basically i have a list of nodes and and edge descriptions, and need to run some simple queries on it, such as “how many steps from node A to node E”
@mattly: I use ubergraph (datastructure for various types of graphs + some algorithms). https://github.com/Engelberg/ubergraph Not sure it runs on clojurescript
I was super impressed with blessed at first but ran into a few bugs that were kinda dealbreaks 😕 specifically made it hard/impossible to use lists in react-blessed
https://github.com/chjj/blessed/issues/325 the project seems mostly unsupported
@lilactown cool, I’ve only been playing around with simple examples so far
@lilactown this project seems pretty active though: https://github.com/yaronn/blessed-contrib it lists blessed as a dev-dependency, wonder why it isn’t a normal one
@johanatan it doesn’t seem so, but you can include the macro in a .clj file and then use it from clojurescript?
@borkdude do you have an example of that? I generally avoid macros in cljs due to not having successfully pulled that off before
@johanatan in which context do you use cljs?
@johanatan ok, here’s an example: https://github.com/borkdude/balcony/blob/master/lumo/src/balcony/env.clj
this is using self-hosted cljs. I don’t know in detail how it works with macros, but this one worked…
@johanatan you could maybe use https://nodejs.org/api/stream.html
@selfsame i'm looking particularly for the resource cleanup/finalization. with-open
just calls .close()
on its target (which could be impl as a protocol method)
@johanatan transducers are maybe even better for closing stuff when you’re done reading. with-open doesn’t play nice with laziness
oh maybe just grab the macro from https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L3797
@borkdude in my case, the cleanup would be: (fs.unlinkSync temp-file)
(the resource acquisition is the equivalent of mktemp
from bash).
@johanatan example for processing text files using a transducer: https://blog.michielborkent.nl/blog/2018/01/17/transducing-text/
ah, good to know but doesn't really apply in my case. the file is created in one fell swoop via output redirection to a temp file and it's read in its entirety on the very next line via readFileSync
(with-open [f (mktemp!)]
(sh (str "some-process >" f))
(do-stuff-with (fs.readFileSync f "utf-8")))
i.e., with-open
according to docs doesn't call .open
and only just calls .close()
when finalized
(defmacro with-tmp-dir
"Evaluates body while binding `tmp-dir-bind` to a fresh temporary
directory and returns evaluated value. Cleans up directory
afterwards, if no exception happens. Else, leaves it there for
inspection."
[tmp-dir-bind & body]
`(let [~tmp-dir-bind (new-tmp-dir)
res# (do ~@body)]
(org.apache.commons.io.FileUtils/deleteQuietly
~tmp-dir-bind)
res#))
Convert to nodejs and you’re done 😉like so:
(defn with-temp [callback]
(let [tmp (mktemp)]
(try
(callback tmp)
(finally
(fs.unlinkSync tmp)))))
@johanatan I wouldn’t try to retrofit things into with-open
if you can do it more simple