This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-11-26
Channels
- # adventofcode (2)
- # announcements (9)
- # bangalore-clj (1)
- # beginners (158)
- # calva (32)
- # cider (2)
- # clara (4)
- # cljdoc (40)
- # cljs-dev (3)
- # cljsrn (6)
- # clojure (45)
- # clojure-brasil (2)
- # clojure-dev (35)
- # clojure-europe (9)
- # clojure-italy (7)
- # clojure-nl (2)
- # clojure-uk (29)
- # clojurescript (144)
- # code-reviews (3)
- # core-logic (9)
- # cursive (11)
- # datascript (8)
- # datomic (9)
- # duct (1)
- # figwheel (6)
- # fulcro (11)
- # hyperfiddle (27)
- # kaocha (23)
- # luminus (1)
- # off-topic (7)
- # onyx (2)
- # pathom (3)
- # re-frame (61)
- # reagent (12)
- # remote-jobs (10)
- # shadow-cljs (40)
- # spacemacs (4)
- # sql (27)
- # tools-deps (6)
- # unrepl (3)
- # vim (47)
Hello all, I'm running cljs tests (using @olical great https://github.com/Olical/cljs-test-runner ) and when I load namespaces that require Expo code which is using ES6 module import
I get “Uncaught SyntaxError: Unexpected String”. I'm not expert of js but how can I tell cljs test runners to not error when some of the modules use ES6? Has anyone run tests successfully against Expo? I see there is https://github.com/expo/expo/tree/master/packages/jest-expo for JS but I have no idea how to integrate it with cljs
By default, cljs-test-runner executes your code within your local nodejs instance, so I guess that doesn't support the ES6 syntax? (I have no idea, I'm not keeping up with JavaScript features 😬) It's not ideal, but maybe you could try running your dependencies through babel or whatever to compile the unsupported syntax out? Might be worth asking the expo people if they've ever dealt with anything similar. I'd hope they'd provide a version that used require syntax but maybe not.
ES6 modules are not supported in Node.js jet. You have to transpile them to require()
form.
Ahhh it makes sense but I have no idea how to transpile them as part of a test pipeline 😞
Thanks for your reply, but I'm still stuck
is it safe to (cljs.reader/read-string x)
when x
is the output of (with-out-str (cljs.pprint/pprint data))
(assuming data
does not contain JS objects and other un-serializable values)?
i think you want clojure.tools.reader (and cljs.tools.reader)
Compare these impls: https://github.com/hyperfiddle/hyperfiddle/blob/master/src/contrib/reader.cljc https://github.com/hyperfiddle/hyperfiddle/blob/master/src/contrib/eval.cljc
is there a sane way to get bootstrap 4's js on the page and bundled into a cljs project? just something to simply skip requiring it from a cdn (but not as complex as using react bootstrap components)
In Clojurescript, it is possible to make a type callable as a function (like keywords and maps) by extending the IFn
protocol simply like this:
(extend-type js/String
IFn
(-invoke
([s coll]
(get coll (str s)))))
Is it also possible in Clojure?@U09K620SG FWIW you also need to implement applyTo
there if you want apply
to work
thanks
Thanks @U09K620SG and @bronsa
clojure.lang.IFn is an interface and not a protocol. So we can extend IFn with deftype
but not with extend-type
.
user=> (extend-type java.lang.String
#_=> clojure.lang.IFn
#_=> (-invoke
#_=> ([s coll]
#_=> (get coll s))))
Evaluation error (IllegalArgumentException) at clojure.core/extend (core_deftype.clj:784).
interface clojure.lang.IFn is not a protocol
what’s the difference between protocols and interfaces?
TIL, i thought protocols were interfaces
@bronsa can you illuminate us regarding interfaces vs. protocols?
when you extend an existing type to a protocol, the implementation is added to a runtime virtual dispatch table
when you invoke a protocol method, clojure first checks the type for direct implementation of the interface, then looks into this dispatch table
Thanks Why IFn is not a protocol?
For perf reasons?
somehow in cljs it works
it's not impossible to make IFn a protocol in clojure, but it would require a significant reimplementation of clojure
Thanks a lot @bronsa.
Any idea why records are not functions in Clojure and ClojureScript?
I suspect because records are still considered lower level than maps, and you might want to define invoke
as a different operation than get
Why do you think records are considered lower level than maps?
that's what they were designed for, to be a lower-level, faster, interoppy alternative to maps
what about “less generic” than maps?
@bronsa in Clojure, we can read a record like this
(read-string "#user.Person{:firstname 1, :lastname avc, :age 3}")
Is there something similar availailable in cljs?
I tried this in cljs (cljs.reader.read-string "#my.playground.Person{:firstname Dave, :lastname Smith, :age 42}")
And I got: “No reader function for tag my.playground.Person.”
I am interested in self-hosted cljs
ok sorry, what I was talking about earlier relates to a different thing than what you're asking
i.e. in clojurescript source code you can't have #my.record[1]
inlined, as the record exists at cljs runtime while the reader is executing in the clojure environment at cljs compile-time
as to why you can't have (read-string "#my.record[1]")
, it looks like I simply forgot to implement that part when porting over from the clj impl
I’m in another call for the moment
Will get back to you in an hour or so
I even think you may be able to make it work, but strongly discouraged as potential to definitely break stuff
I know that it is dangerous but it seems to work with JS strings
the potential issue is that some JS libraries will type dispatch on .call
property to distinguish fns
it is for a toy (I mean a talk)
Any idea why records are not functions in Clojure and ClojureScript?
Is it on purpose?
I mean with a map you can have ({:a 1} :a)
but now with a record
Check this out @viebel @dnolen @bronsa http://tank.hyperfiddle.com/:dustingetz.storm!view/~entity('$',17592186047281)
@viebel huh, I didn't know that, probably Clojure JIRA has some information, it must have come up before
OK. I wrote a blog post (2 years ago) “records are wacky maps” based on a talk by Michał Marczy https://blog.klipse.tech/clojurescript/2016/04/25/records-wacky-maps.html
But it’s only today (2 years later) that I am asking myself the “why” question :thinking_face:
can only speculate - but I would still consider records to be a performance construct, I personally almost never use them
Given spec and Cognitect guidance to prefer maps of namespaced keywords from many namespaces, is defrecord legacy at this point?
If I needed a map that did more than usual map like things, I'd probably start with defrecord, rather than extending the map
multimethod + map seems to beat defrecord + protocol in the happy path
no, flexibility and power
but for simple use cases “defrecord + protocol” are more easy to grasp For instance, you don’t have to explicitly mention that the behavior depends on the type of the first argument
I mean code written with “defrecord + protocol” will be easier to understand
That's not immediately obviously true to me, i will need to think on that, thanks
Clojure kind of bucks the legacy notion - nothing is going away - if it’s useful - use it
Halo I just discovered macchiato and am using cljs to make a node.js server. i would also like to have my clojurescript application compile to a separate .js file from the server.js ...
is there a way to write out such a way in the project.clj to get 2 separate js files from the /src/... dir?
okay, it looks like modules are a thing...
@sova that is not what modules are for. you basically want 2 different builds. one for the lcient and one for the server
Aha. So it is! okay I have one.. :target :nodejs
... what's the defacto? :target :???
and the correct answer was, delete that line when not node.js ^_^
So how do I ask lein to build my build named :client ?
argh, I just spent 30 minutes finding out why str/starts-with?
didn’t work with my regex… solution: it doesn’t accept a regex at all (why not actually?)
you can use the existing re- functions for that
(re-find #"^foo" "foobar")
yeah, it’s easy to forget in cljs:
(str/starts-with? "" #"https?://") ;; false, no error
in ClojureScript we just defer to goog.string
which doesn’t do any validation of any kind
https://github.com/slipset/speculative/commit/b4abb1c77d45f9a31348e143a84aa66a84cb5928
I am trying to use web workers in my project
and I get this error
The key :target at (:cljsbuild :builds 1 :compiler) has a non-conforming value: :webworker. It should satisfy #{:nodejs}
I have [org.clojure/clojurescript "1.10.238"]
and [figwheel "0.5.17"] [figwheel-sidecar "0.5.17"]
cljs builds work fine,
I get this error when I try to start repl programatically by figwheel-sidecar.repl-api/start-figwheel!
the error seems pretty specific. you have a :target :webworker
in your compiler config, but that's not valid
what are all the options for clojurescript on the server via node?
I noticed that you're in macchiato channel. That's only framework I know of. You can also use reitit routing library that allows you to generate swagger doc and have input validation using spec: https://github.com/macchiato-framework/macchiato-core/issues/7 It is not perfect, but people working on macchiato and reitit react pretty quickly on issues and pull requests 🙂
@sova I've only used it for quick scripts thus far rather than a full project, but I've had good luck with lumo (installable via npm undre lumo-cljs
, which can both run cljs directly via its embedded node and be used to run a compile script if you want to run in an existing node project (or different version than that embedded in lumo)
Cool. I'm very happy using cljs on the clientside but now that I want to have some sort of minimal cross talk and persistence i'm trying to keep it all looking like cljs ^_^
and yeah you can just use clojure itself + the regular compiler these days with pretty good results
joking aside, cljs ecosystem is not as mature as clojure for server side stuff, at least that's my view for experience both, which has been very little time
yeah the server machine i'm using it'd be much nicer to do an npm deploy because it doesn't need many resources to get started
i'm frustrated by this new term "serverless" that is just a lie
yeah I am very skeptical. people like it because it seems like less complexity but it adds more complexity the same way microservices do once you have to deal with every single thing happening over a network boundary