This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-22
Channels
- # aws (1)
- # bangalore-clj (3)
- # beginners (103)
- # boot (15)
- # cider (29)
- # cljs-dev (17)
- # cljsrn (43)
- # clojure (156)
- # clojure-gamedev (2)
- # clojure-italy (11)
- # clojure-spec (55)
- # clojure-uk (4)
- # clojurescript (76)
- # data-science (2)
- # datomic (7)
- # defnpodcast (2)
- # emacs (4)
- # leiningen (2)
- # luminus (3)
- # off-topic (11)
- # parinfer (3)
- # pedestal (1)
- # quil (1)
- # re-frame (3)
- # reagent (2)
- # ring-swagger (1)
- # timbre (3)
- # unrepl (10)
- # untangled (1)
- # vim (3)
- # yada (1)
Guys, I really don’t understand some basics of clojurescript. I added an npm package to my project, I require that from an js file and then I can use it. But, how can I require this library from clojurescript ?
Not like that.
There is a function call in my template
(def ReactNative (js/require "react-native"))
Ah, I wanted to link this actually: https://anmonteiro.com/2017/03/requiring-node-js-modules-from-clojurescript-namespaces/
Also this: https://clojurescript.org/reference/compiler-options#foreign-libs (which is linked in the blog entry as well)
is there no workaround for the lack of
map-entry?
in CLJS ?+cljs.user=> (type (first {:a 0}))
cljs.core/PersistentVector
that's trickyit's a vector and has exactly two items?
yeah, without a separate type to look for you are kind of stuck
this surprises me...
+cljs.user=> (def v [:a 0])
#'cljs.user/v
+cljs.user=> (identical? v (first (conj {} v)))
false
(identical? v [:a 0])
hey @noisesmith take a look at the type of (first (conj {} v))
I am not sure in cljs but in clojure it would probably a map entry, not a vector
yeh that's the point
@octo221 my surpise is that it doesn't just use the vector, since conj will be putting a vector into the hash-map
@jeremys the point of this convo is that elements in hash maps in cljs are vectors
does the same for (into {})
+cljs.user=> (type (first (conj {} v)))
cljs.core/PersistentVector
@octo221 into uses conj (or conj!) yeah
oh right
right, now you've caught up
my surprise is because if it puts a vector in anyway, it could just use the vector
probably its in order to keep the code diffs from clj as small as possible
it's nice to know the provenance of data
when you ‘add’ the vector to the map, the internals take the values in your map and store them
right but it doesn't have to - and clojure's usually smart about reusing persistent data when it can
when you retrieve them the map has to constuct a new vector to give you a key-value pair
yes like how subvec reuses the parent vec
retrieval does not create a new entry
a hash map contains the entries
you can go into your js debugger and find them if you inspect it
no the hash map contains a tree like datastructure use for efficient retreiving of value from keys
oh wait - it doesn't have the map entries in the structure
so that explains why the vector you get back isn't identical
it's a an array below a certain size, then a tree of 32 element arrays, OK
I was just confused about the inner structure
https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L6307
then why don't we see it?
that's not a type it's an interface - which is extended to collections
(later in the file)
so there's no concrete map entry type
oh wait, there is a mapentry record https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L6307
n/m that's the line you linked to, now I'm catching up
oh! MapEntry type was added in 1.9.542
so I bet in that version or newer you can actually test for entries - this repl is a month or two old, that's what's going on
lein deps...
I lost the line but I saw an implementation of ISeq returning a set of vectors somewhere, which might be why we get vectors instead of map entries
my cljs is older, it doesn't have that type yet
I need to update my repl
I trying the latest atm to try the new code splitting and I will try requiring from node_modules
just used code splitting to compile my devcards in the same build that compiles my app main, I should be able to hot reaload them at the same time. pretty cool
Hi all, I have a reframe project in which I include an npm module. It compiles OK with :optimizations :simple
but not with :advanced
. Should I file a bug? is there a list of such known problems? More details here: https://stackoverflow.com/questions/45201315/a-is-undefined-when-compiling-a-cljs-prj-with-an-npm-module-under-prod-profil